Detect Proximity from player

Hey there game makers.

I have on map encounters. I want to be able to attack the enemy on map so that you can get a preemptive strike kinda like in Dragon quest 11 or Radiant Historia.

My problem is telling the rpg maker if the event is one tile away from the player and a button is pressed do this.

Does anyone know how to do that?
there are basically two ways:
1)
with eventing you'll use control variable to get the coordinates of both the player and the event and compare them to determine the distance.
then you can use either action trigger or conditional branch button pressed or a combination or something similar depending on how the event is structured to determine what else you need.

2)
there are plugins that automate proximity effects, but they might not be fitting to your game mechanic as they usually are used slightly different. But you can test them.
Hi,

by fluke, I have been thinking about something similar, inspired by the Paper Mario Games.
You want to put the enemy at a disadvantage before the battle really started by damaging him due to a "first strike" attack, right?
Heres my way how i did it by using an item on map on front of enemies:

Since i have become kind of friends with the GALV_Tools-Plugin (link below), i use it to obtain some kind of "backstab dagger", that allows me to "stab" right to the next event the player is facing to, everytime i press a button. ) I suppose, the script calls the plugin features are meant to harvest some berries or plant some seeds on bushes/field tiles in front of you but, this line of code

Galv.TOOLS.frontEvent('beast')

goes for everything, as long as its an event with a fitting comment (like <beast> in this case), hence map enemies work too. It checks, whats "one tile away from the player" like you wrote.

After the item is used, it connects to a common event, where you are free to create all effects of your "first strike". For example, you can use a switch to alter the upcoming battle scene and already damage the enemies you wish before the first turn starts. Preemptive.

Its more or less like a compromise and im sure there are better ways, but i wanted to share my thought on this.

link to the script (you need 30 min or so to get into it, but its free, love GALV):
I made an event at some point to activate when players got close, but if you add "if [button] is being pressed" you should be able to do what you need with roughly the same. On the other hand, there's probably also a plugin that's even easier, I just don't know it offhand...a quick google search would probably bring one up. In the meantime, here's what I did:


Spoiler: proximity activation
Screenshot (195).png

I didn't think to include it in the screenshot, but it'll have to be parallel for this to work.

Original thread: https://forums.rpgmakerweb.com/threads/detect-proximity-from-player.146521/