Triggering something when two events touch each other.

I'm trying to create a small escort misison. Everyone's favourite 🙂

A character will walk through an area, while enemies will walk in his path. Your job is to kill those enemies before they reach the character you need to protect.
That means there should be a 'mission failed' when an enemy touches the guy we need to protect.
How do I go about doing that?

How do I trigger something to happen, when two events touch each other, where neither is the player?
There's this plugin by CT_Bolt but it's for MV. You can try it with MZ with and without FOSSIL
If the protected one is stationary, you could maybe use variables for the enemies' positions x,y.
Thug1x =
Thug1y =
and then using Conditional branches, Thug 1x=
Thug 1y= If both are true, then, you could control a switch to make anything happen you want.

You would need this on every tile that touches the protected one if the enemy moves randomly. Also, you should change which way they are facing if you want them to face each other when they meet. Also, if there are more than 1 enemy moving randomly, you need to do the same thing with all enemies. Don't personally know any other way. There are some great helpers on this site though who can help too. Good luck.
If the protected one is stationary, you could maybe use variables for the enemies' positions x,y.
Thug1x =
Thug1y =
and then using Conditional branches, Thug 1x=
Thug 1y= If both are true, then, you could control a switch to make anything happen you want.

You would need this on every tile that touches the protected one if the enemy moves randomly. Also, you should change which way they are facing if you want them to face each other when they meet. Also, if there are more than 1 enemy moving randomly, you need to do the same thing with all enemies. Don't personally know any other way. There are some great helpers on this site though who can help too. Good luck.
The protected event is not stationary.
but using x and y coordinates might be something I can play around with.
Thanks for the suggestion.
You can probably put this in a parallel process on the protected event (2). Change 2 to the protected event's number

for (a = 1; a < $gameMap.events().length; a++) {

if (!!$gameMap.event(a)) { // check that event exists
hitDist = Math.abs($gameMap.event(a).screenX() - $gameMap.event(2).screenX()) +
Math.abs($gameMap.event(a).screenY() - $gameMap.event(2).screenY());
if (hitDist <= 10 && $dataMap.events[a].meta['enemy'] ) { // in range?
$gameSwitches.value(x) == 'true';
}}}

Wait 10 frames

Basically check once every 10 frames if the protected event is within 10 pixels of an event with the notetag <enemy>. If it is, set game switch x to ON
The protected event is not stationary.
but using x and y coordinates might be something I can play around with.
Thanks for the suggestion.
You're welcome. I'm not a coder at all 🙁

Original thread: https://forums.rpgmakerweb.com/threads/triggering-something-when-two-events-touch-each-other.159044/