If enemy is within 1 tile within player direction script?

wondering if their is a script that can do this. So if event is 1 tile away from players direction than do script.
Depends where you're calling it from ... if your commands are on the event itself, it would be something like this, in the script portion of a conditional branch:

Code:
$gameMap.event(this._eventId).x == $gameMap.roundXWithDirection($gamePlayer.x, $gamePlayer.direction) && $gameMap.event(this._eventId).y == $gameMap.roundYWithDirection($gamePlayer.y, $gamePlayer.direction) && Math.abs($gameMap.event(this._eventId).x - $gamePlayer.x) + Math.abs($gameMap.event(this._eventId).y - $gamePlayer.y) == 1
Depends where you're calling it from ... if your commands are on the event itself, it would be something like this, in the script portion of a conditional branch:

Code:
$gameMap.event(this._eventId).x == $gameMap.roundXWithDirection($gamePlayer.x, $gamePlayer.direction) && $gameMap.event(this._eventId).y == $gameMap.roundYWithDirection($gamePlayer.y, $gamePlayer.direction) && Math.abs($gameMap.event(this._eventId).x - $gamePlayer.x) + Math.abs($gameMap.event(this._eventId).y - $gamePlayer.y) == 1

oh okay sweet, I think thatll be helpful for me to use it from the event or player. Thank you

Original thread: https://forums.rpgmakerweb.com/threads/if-enemy-is-within-1-tile-within-player-direction-script.77878/