Sure. Here's the formula:

Code:

`Math.abs($gamePlayer.x - this.character(0).x) + Math.abs($gamePlayer.y - this.character(0).y) === 1`

When you're running a script call in an event,

*this* is the interpreter attached to the event, so you can say

*this.* followed by any function in the Game_Interpreter class to run that function.

Now, Game_Interpreter has a neat function called

*character(x)* and if you pass -1 to that function, it returns the player object. If you pass a number > 0, it returns the event object of the event with that id. And if you pass 0, it returns the event object that this command was run from. So

*this.character(0)* is the same as saying

*$gameMap.event(this._eventId).*
So what we're doing here is taking the difference between the x position of the player and of the event, and the difference between the y position of the player and the event.

*Math.abs()* converts a number to the absolute value - it removes the negative sign. So if player.x is 5 and event.x is 4, then player.x - event.x will be 5 - 4, or 1. But if player.x is 4 and event.x is 5, then player.x - event.x will be -1.

*Math.abs()* just ditches the negative sign, so in both cases, the difference would be just 1. Same for the y comparison.

Finally, we add the two numbers (difference in x and difference in y) together to see how many tiles apart they are. If the player is immediately above, below or beside the event, the difference will be 1 (1 + 0 or 0 + 1, because either the x values or the y values will be the same). If the player is touching diagonally, the difference will be 2 (1 away horizontally plus 1 away vertically - 1 + 1 = 2).

The

*=== 1* is the javascript comparison. The

*Math.abs(...) + Math.abs(...) *returns a number. The

*=== 1* just compares that returned number with 1 (the distance you want the player to be from the event), and returns true if they match (the result is 1) and false if they don't (the result is not 1).

The only positions the player could be in, to return true from that calculation, would be directly above, below, or beside the event, which are the positions you've highlighted in red and green on your screenshot. Touching diagonally will return false, as will any position further away.

Do you follow that? If, not, I'll draw some pictures

If you just copy that and paste it into your Script box in the conditional branch, it will work. However, it will only tell you that the player is one tile away from the event. It will NOT tell you which tile the player is on - above, below, to the right or left. So if north/south/east/west is important, the above will not tell you that. If you need to know exactly where the player is in relation to the event, then your method above is the one you will have to use. I made the assumption that you were only interested in knowing if they were one tile apart, and didn't care about the direction, which is probably not a good assumption to make ...