MZ How to make a conditional branch that checks if the player is close to any event?

Hey y'all! As the title states, I'm looking for a script for a conditional branch that checks if the player is within 1 tile of an event (I'm fine with using notetags on all events if necessary). This is so I can make an "interact?" popup whenever the player is close to an event they can interact with. Here is an example of what I mean below: (It's in the bottom left corner, just a placeholder for now.

Before being in range with an interactable:

Screenshot 2025-08-17 162604.png


After being in range with an interactable: (Again, the top square is all that matters here)
Screenshot 2025-08-17 162614.png

Thanks in advance!
you can't really do it in a single script line, at least not without that line becoming extra long and complex.
basically you'll have to check every single space where the player may interact for an event, either in a loop or in a sequence of checks.

I assume that evented checks are out? Those would be the easiest way, but based on how the results should affect the HUD that might be too much to handle with evented processes.

In that case the key to the question is the script equivalent to the event command "get location info".
You can give that command a single position on the map (relative to the player if necccessary) and ask it to return the ID of an event there. And if the retuirn is zero you'll know that there is no event there.

Depending on your range definition it would have to be used on four or eight positions around the player.

Unfortunately I can't give you the entire sequence because I haven't worked with MZ yet and don't want to write something wrong, but I hope the above is enough for you to be able to put it together yourself with the pinned topic about script equivalents.
Line of Sight Auras

You tweak the numbers and you can make the events range of "Sight" be whatever you want.
Put the script into an IF Conditional and make it do Whatever you Want while the player is in RANGE.
In your case some kind of Interaction like Turn on Switch, Else, Switch Off. The switch would control the appearance of the button and the button would only be available with a Common Event controlled by the switch.
Idk, just throwing out ideas.
You also might find it useful to search for proximity checks or proximity triggers. That might give you some options that fit your particular use case.
If you only need to check 1 tile in front of the player, that's the simplest case. Get Location Info could work, but would require you to keep track of which event IDs on each map are "interactable", which is clunky. Instead, something like this in Conditional Branch -> Script might work (untested):

const d = $gamePlayer.direction(); $gameMap.events().some(e => e.isTriggerIn([0]) && e.isNormalPriority() && e.posNt($gameMap.roundXWithDirection($gamePlayer.x, d), $gameMap.roundYWithDirection($gamePlayer.y, d)))
I.e. "is there some event on the map that has Trigger = 0 (Action Button), Priority = normal (Same as characters), is in front of the player, and is not marked Through?".

You would still have to figure out when to check it. You could do that with a Parallel event, maybe one that ends with Wait 6 frames or so, to limit the check frequency. A plugin that turns on a switch (or calls a common event) with every step may help to streamline things.


Alternatively, just to mention it...have you seen Galv's Action Indicators plugin?
The visuals (icon over the event, rather than in the corner of the screen) aren't what you ask for, but it would probably be a lot more straightforward than trying to manually event these checks.
const d = $gamePlayer.direction(); $gameMap.events().some(e => e.isTriggerIn([0]) && e.isNormalPriority() && e.posNt($gameMap.roundXWithDirection($gamePlayer.x, d), $gameMap.roundYWithDirection($gamePlayer.y, d)))
This worked wonders! Kinda surprised it worked first try. Thanks to everyone else that helped as well, I'm lucky RPGMaker has such a great community! (Also I forgot about Galv's plugin, but this works better as I can use any size image and not just a 32 * 32 icon)

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-conditional-branch-that-checks-if-the-player-is-close-to-any-event.179619/