How to script event for player next to event?

Currently, I'm trying to script a conditional branch for a player next to an event. However, I'm new to RPGM and am having a hard time figuring out how to work the script. I tried this (and several variations of this):

◆If:Script:$gameMap.event(010).pos+(1,0)=gamePlayer.pos

But no cigar. Any ideas?
So you just want them on a tile touching the event? Could be above/below or on either side?

Code:
If: Script: Math.abs($gameMap.event(10).x - $gamePlayer.x) + Math.abs($gameMap.event(10).y - $gamePlayer.y) == 1

This will return true if there is one tile difference horizontally OR vertically.

This will also do the same thing and also caters for maps that loop horizontally or vertically:
Code:
If: Script: $gameMap.distance($gamePlayer.x, $gamePlayer.y, $gameMap.event(10).x, $gameMap.event(10).y) == 1
So you just want them on a tile touching the event? Could be above/below or on either side?

Code:
If: Script: Math.abs($gameMap.event(10).x - $gamePlayer.x) + Math.abs($gameMap.event(10).y - $gamePlayer.y) == 1

This will return true if there is one tile difference horizontally OR vertically.

This will also do the same thing and also caters for maps that loop horizontally or vertically:
Code:
If: Script: $gameMap.distance($gamePlayer.x, $gamePlayer.y, $gameMap.event(10).x, $gameMap.event(10).y) == 1
Thank you! This seems to be working perfectly- better than I expected actually. If it's not too much to ask, could you give me a play-by-play of how this script works?
Thanks again.
Actually, second question. Is there a way to get individual coordinates relative to the event? Like an individual coordinate for a player to the left of the event, an individual coordinate for a player to the right of the event, etc.?
$gameMap.event(10).x - $gamePlayer.x will give:
  • -1 if the player is standing to the right of the event
  • 0 if the player is standing above or below the event
  • 1 if the player is standing to the left of the event
$gameMap.event(10).y - $gamePlayer.y will give:
  • -1 if the player is standing below the event
  • 0 if the player is standing to the left or right of the event
  • 1 if the player is standing above the event

Math.abs gets rid of the negative figure, so the first Math.abs will give 1 if the player is directly beside the event, and the second will give 1 if the player is directly above or below the event.

Adding them together will give 1 if the player is either directly above/below or beside the event. Any other position will give a higher number. 0 means they are on the same tile.

Not sure what you mean by "individual coordinates relative to the event". What do you expect to get if the player is to the left, and what do you expect to get if the player is to the right?
@Holefiller
From your questioning I think you've missed one of the basic limitations of a computer and tried to circumvent that by script. But unfortunately scripts are not miracle workers...

The computer is at basic nothing but a calculator - it can only handle single numbers and single operations, anything else requires mathematical workarounds and variables. A position is at least two numbers, not a single one - which is why your original idea failed.

I suggest you play around a bit with the advanced uses of the control variable command - that can do everything described above without a single script if you know how, and checking it should give you a good idea on what can be done easily and what would require a lot of complex scripting.

More precisely, open an event for testig, add a control variable command, select the "game data" option (the one that defaults to Map ID) and then click on the dots behind "Map ID".
That will open a window where you can select a lot of different game data options, and looking through what is available there and what not should help you sort things out.
$gameMap.event(10).x - $gamePlayer.x will give:
  • -1 if the player is standing to the right of the event
  • 0 if the player is standing above or below the event
  • 1 if the player is standing to the left of the event
$gameMap.event(10).y - $gamePlayer.y will give:
  • -1 if the player is standing below the event
  • 0 if the player is standing to the left or right of the event
  • 1 if the player is standing above the event

Math.abs gets rid of the negative figure, so the first Math.abs will give 1 if the player is directly beside the event, and the second will give 1 if the player is directly above or below the event.

Adding them together will give 1 if the player is either directly above/below or beside the event. Any other position will give a higher number. 0 means they are on the same tile.

Not sure what you mean by "individual coordinates relative to the event". What do you expect to get if the player is to the left, and what do you expect to get if the player is to the right?
This is what I needed, thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-script-event-for-player-next-to-event.143688/