Variable as Nearest Event ID

Is it possible to set a variable as an event id?

Event IDs that are used as variables are events that have the closest distance to the player.

Please help me solve this
If there are more than one event that has the closest range to the player. Which one do you want to use?
If there are more than one event that has the closest range to the player. Which one do you want to use?
event with a special note in the name.
For example 2 events are 2 tiles from the player.
just call it event001 and event002
event001 has the name <get_id> while event002 does not.
then the variable will change to the ID of event001.
I haven't tested this but you could use something like the following to find that event.

Code:
event.note[/<get_id>/]

Probably you'd need to use it like this:
Code:
closest_event = nil
events = $game_map.events
events = events.select{|e| event.note[/<get_id>/i] != nil }
events.each do |e|
  # Checks for X and Y coordinates and assign them to closest_event
end

Original thread: https://forums.rpgmakerweb.com/threads/variable-as-nearest-event-id.124914/