Get event's map x/y position with a script command?

I'm writing a hunting scene where the player shoots projectiles on the map to strike monsters, and I need a way to check a monster's x/y without using two variable slots for each monster (I can do that if I have to, but it would be harder to keep track of). Is there a way to use a script command in the corresponding spot of an if-statement to check the map x or y value of the event that calls it?

Grazie!
I think something like this should work?

JavaScript:
(who => who.x == 4 && who.y == 5)(this.character(0))

Explanation, if you're interested:
  • The expression (who => ...) declares a function taking parameter who.
  • We then immediately call the function, assigning this.character(0) (which returns the current event) to the variable who.
  • The && means "and", so you're checking both coordinates. If you only need to check either x or y but not both, you can omit it.
  • If you need to check a range, you can use <= or >= instead of ==
Hi there!
To check an event position on the map, without variables, you can use the script call:
$gameMap.event(Id).x
or
$gameMap.event(Id).y
(I don't remember if it is 'event' or 'events', not in my pc right now)
So, in the script call of the if statement you can use
$gameMap.event(id).x === 10 && $gameMap.event(id).y === 12
This will check if both conditions are true.
If you want one or another, you can replace && for ||
Hi there!
To check an event position on the map, without variables, you can use the script call:
$gameMap.event(Id).x
or
$gameMap.event(Id).y
(I don't remember if it is 'event' or 'events', not in my pc right now)
So, in the script call of the if statement you can use
$gameMap.event(id).x === 10 && $gameMap.event(id).y === 12
This will check if both conditions are true.
If you want one or another, you can replace && for ||

You're correct, the function is event.

Original thread: https://forums.rpgmakerweb.com/threads/get-events-map-x-y-position-with-a-script-command.123443/