Get Event closest to Event or Player

I'd like to request a script for my project that would loop through the relevant events on the map (Preferably ones with the string "enemy" in the name. And report back the one that is closest to the player. 
It should later be able to be called from a script call, something like: closest(ToThisID)

Thanks in advance!
Cheers ^-^
A sensor radar script can be laggy if you have the sensor range set to a large area and using a large map.

Especially having it check through every single event in the map constantly will surely lag if you have too many events on the map.

The game original built in sensor is to check the distance of the player from the event (on event side).

Because off screen events will automatically stop running, this prevents the lag in a way.

If you don't mind a small change to the design, i might be able to put up a sensor script for you that only run once when the script is called.

A slight lag can still happen during scan depending on the events you have on map, but at least it won't be always lagging down the system compared to constant running radar.

Enemy's name tag:

<enemy>Put that in the events' name to declare the event as enemy for the scanner.

Script call:

To get the nearest enemy event's id.

nearest_enemyPair this with a game variable's script box to check result in message box

eg

Control Variables:[0001] = nearest_enemy

To get a list of all enemies, use this:

$game_map.scan_targetthis script call will return a list of enemies(event's id and their distance from player)

Script:

http://forums.rpgmakerweb.com/index.php?/topic/46115-enemy-distant-scanner-radar/
This works wonderfully! This is exactly what I need <3 Thank you. I'll be sure to add your name to the credits, and keep in mind how nice it was of you to take on this request. You are awesome for letting people use this for free and commercial purpose. 

If I ever make any money from my project I'll be sure to forward a little something to you amigo. 

<3 <3
You're welcome! And congratulations on your progress! 😉

Original thread: https://forums.rpgmakerweb.com/threads/get-event-closest-to-event-or-player.46104/