Check if player's co-ordinates match those of any event.

Hi everybody, happy weekend!

I'm trying to find a conditional script that would let me check if the player's co-ordinates match with any of the events on the map.
This is because Yanfly's Event Spawner plugin won't spawn events where there are already events present on the map.
I'm trying to spawn events right under the player, which works fine unless the player is already over an existing event.
This isn't a problem in itself, but I'd like a conditional check which can show the player a message, telling them to find a clear space.
At the moment, the plugin executes as normal but without spawning a new event.

I need to find whether the player is standing over any of the events on the map at the time they choose to spawn a new event.
I'd really like to avoid having to check the player's position versus every single event ID on the map!

Any help, or suggestions about where to look, would be appreciated.
I already checked the big script calls document and nothing occured to me, but I am a bit nooby so...
$gameMap.events().some(event => $gameMap.eventsXy($gamePlayer.x, $gamePlayer.y).includes(event))

Will return true if the player is on a map event, and false otherwise.
If you wanted a general function that checks if there are any events at a specified position (assuming you're using default RPG Maker position system), it would be convenient to have a function that you can call from your events.

You can create a new plugin (open notepad, copy code, save in plugins folder) that contains

Code:
function anyEventsAt(x, y) {
  var events = $gameMap.events();
  for (var i = 0; i < events.length; i++) {
    var ev = events[i];
    if (ev.x === x && ev.y === y) {
      return true;
    }
  }
  return false;
}

Then add the plugin to your project. The code can probably be optimized but it's the basic logic.

Then you can use a script condition to pass in the player's current position

Code:
anyEventsAt($gamePlayer.x, $gamePlayer.y)

This can also be used to check if there are any events at any particular position by passing in any position that you want

Code:
anyEventsAt(2, 3)
If you wanted a general function that checks if there are any events at a specified position (assuming you're using default RPG Maker position system), it would be convenient to have a function that you can call from your events.

You can create a new plugin (open notepad, copy code, save in plugins folder) that contains

Code:
function anyEventsAt(x, y) {
  var events = $gameMap.events();
  for (var i = 0; i < events.length; i++) {
    var ev = events[i];
    if (ev.x === x && ev.y === y) {
      return true;
    }
  }
  return false;
}

Then add the plugin to your project. The code can probably be optimized but it's the basic logic.

Then you can use a script condition to pass in the player's current position

Code:
anyEventsAt($gamePlayer.x, $gamePlayer.y)

This can also be used to check if there are any events at any particular position by passing in any position that you want

Code:
anyEventsAt(2, 3)

This works perfectly, thankyou so much.

Original thread: https://forums.rpgmakerweb.com/threads/check-if-players-co-ordinates-match-those-of-any-event.124492/