Is there a simple in-engine way to trigger an event with the 'event touch' setting when the player is adjacent to the event? I know that the VisuStella plugins can do this but I don't want to use those.
Event Touch Adjacent Trigger
RPG Maker MZ SupportWithout a plugin you would have to make a parallel event checking if the player is in one of the tiles around the event every x frames (10 would probably more than suffice).
Or, if the event doesn't move, you could make all the tiles around the event touch trigger and have them remotely toggle the self switch of the event. This seems like a worse solution though because of event bloat.
Or, if the event doesn't move, you could make all the tiles around the event touch trigger and have them remotely toggle the self switch of the event. This seems like a worse solution though because of event bloat.
Does the event have a fixed position? If so, you can just make an event on the tike next to the event, make it "below player" and make the trigger "Player touch"
Now, this event is triggered when the player stands in top of it, and since you put it next to the other event, it will trigger right where you want it.
---
If it us required Face the event, you can simply give the event itself "same as character" and trigger "player touch" in this case there is no extra event next to it needed.
---
Either way, make sure you use "player touch" and not "event touch".
Event tough is used when the event moves and touches the player, not the other way around.
Now, this event is triggered when the player stands in top of it, and since you put it next to the other event, it will trigger right where you want it.
---
If it us required Face the event, you can simply give the event itself "same as character" and trigger "player touch" in this case there is no extra event next to it needed.
---
Either way, make sure you use "player touch" and not "event touch".
Event tough is used when the event moves and touches the player, not the other way around.
truth be told I didn't debug this, so It may have errors sorry D;
But this is the basic concept of what it is you're wanting. It determines if the event with the id of ID( replace ID with the actual ID of the event you wanna check ), is within a 1 tile range( you can change the 1 to any size you want, it's calculated in tiles. ).
or alternatively instead of running this lengthy code in a script call you can put this in a js file and add it as a plugin.
and then call this in a script call.
either way the result is just the same, but the second approach is much easier if it needs to be called multiple times :x
again there may be issues and or errors I didn't test it sorry D; If it don't work lemme know and I'll give it a test later when I have free time 🙂
JavaScript:
const deltaX = Math.abs( $gameMap.deltaX( $gamePlayer.x, $gameMap.event( ID ).x ) );
const deltaY = Math.abs( $gameMap.deltaY( $gamePlayer.y, $gameMap.event( ID ).y ) );
const distance = deltaX - deltaY;
if ( distance <= 1 ) $gameMap.event( ID ).start();
But this is the basic concept of what it is you're wanting. It determines if the event with the id of ID( replace ID with the actual ID of the event you wanna check ), is within a 1 tile range( you can change the 1 to any size you want, it's calculated in tiles. ).
or alternatively instead of running this lengthy code in a script call you can put this in a js file and add it as a plugin.
JavaScript:
Game_Map.prototype.characterDistance = function ( character1, character2 ) {
const deltaX = Math.abs( $gameMap.deltaX( character1.x, character2.x ) );
const deltaY = Math.abs( $gameMap.deltaY( character1.y, character2.y ) );
return deltaX - deltaY;
}
and then call this in a script call.
JavaScript:
if ( $gameMap.characterDistance( $gamePlayer, $gameMap.event( ID ) ) <= 1 ) $gameMap.event( ID ).start();
either way the result is just the same, but the second approach is much easier if it needs to be called multiple times :x
again there may be issues and or errors I didn't test it sorry D; If it don't work lemme know and I'll give it a test later when I have free time 🙂
Thanks! I'll give it a try.
Hmm, seems to be triggering the event listed in ( ID ) if I'm beside any event, but that is probably user error on my part. I can message you privately to look into that.
Original thread: https://forums.rpgmakerweb.com/threads/event-touch-adjacent-trigger.159963/