Check distance between player and event?

I have been looking awhile now, and i can't seem to find a means to do this.
But is there a way to check the distance between the player and an event, and tell the event to do something specific based on distance?
For instance, what i am trying to do is a work around for the FPLE plugin, events don't properly get darker at a distance like they should, so i figured if i could check the distance in squares from the player, and tell the event depending on how many squares away you are, to tint themselves darker and darker or lighter and lighter depending on how close i am, and that should fix the issue.
I was sure there was a plugin, but i could not find it.
$gameMap.distance(x1, y1, x2, y2)

However, you would need to have a parallel process running this, and if you set one up for each event, that would likely cause lag.

Maybe a single parallel process event that waits for 10 frames right at the start, then compares the number of steps to a number saved in a variable, and if they're different, update the variable and then proceed to check each of the events all within the same parallel process. That means you'd have just one instead of many, it wouldn't be running constantly - only every few frames, and it'd only do the heavy processing if the player has actually moved.
Maybe if i tell it to only check when i hit a direction button...
Like if i am pressing left or right or up or down, it checks the players X and Y and then compares it to the event.... and if it's more or less compared to the player by so many numbers.. it tells the event to change effects..
I found a plugin made by moghunter that changes things like effects for an event.. that SHOULD work for telling the even to change depending on the distance..
You would think there would be an easy plugin for this somewhere to prevent lag.. like with a call thing.. or.. something.
Oh my head..
Hi friend
Code:
var get_distance = Math.abs($gamePlayer._x - $gameMap._events[?]._x); // distance between player and a specific event ID ? If negative, Valur will alway positive beacause we use Math.abs() to transforme the resulte in +
var target_distance = 3;
if (get_distance<=target_distance){
    // Do some stuff
}
this call work in game.
You can manipulate it as you see fit, but it is important to understand the method Math.abs
https://www.w3schools.com/jsref/jsref_abs.asp
for what you need

so in this context
if player X are in 4 target_distance valur or === to the event 999 _x .. do stuff
Left rigth can give negative valur, but math.abs transform negative to alway positive valure
Code:
var get_distance = Math.abs($gamePlayer._x - $gameMap._events[999]._x);
var target_distance = 4;
if (get_distance<=target_distance){
     console.log('I am near the event 999 according to the target_distance');
}
for Y and X distance
Code:
var get_distance = [Math.abs($gamePlayer._x - $gameMap._events[999]._x), Math.abs($gamePlayer._y - $gameMap._events[999]._y)];
var target_distance = 4;
if (get_distance[0]<=target_distance && get_distance[1]<=target_distance){
     console.log('I am near the event 999 according to the target_distance');
}
this code are ugly but is for show you how is work.
Ummm..
I'm doing this with events and condition branches.
I have a variable set for the X position of the player the Y position of the player.. and then 2 more for the position of the event.
I just need to figure out how to do a branch that checks for a specific number difference between the player and event...
But i don't see how to in the condition branch options.

This is what i got so far.

Code:
◆Control Variables:#0001 Event Map X = Map X of This Event
◆Control Variables:#0002 Event Map Y = Map Y of This Event
◆Control Variables:#0003 Player Map X = Map X of Player
◆Control Variables:#0004 Player Map Y = Map Y of Player
◆Get Location Info:Player Distance, Terrain Tag, ({Player Map X},{Player Map Y})
◆Get Location Info:Event Distance, Terrain Tag, ({Event Map X},{Event Map Y})
◆If:Player Distance ≠ Event Distance
  ◆
:End
and what does the terrain tag has to do with distance?
The get location info command can never give you the distance between events, you're only testing if the player and the event are standing on tiles that have the same terrain tag, but those two tiles could either be next to each other or on other sides of the map.
Nothing sorry... that was me being stupid..
I was just trying to group the X and Y into a single Variable.. it did not work...

Currently i have this.. but it is only working properly when the player is more than the event..
If i move above the event, it seems to work in the opposite direction... oddly..
And if i am right or left of the object.. it just kinda goes all over the place with the different graphics..

Code:
◆Comment:Calculating distance
◆Control Variables:#0001 Event Map X = Map X of This Event
◆Control Variables:#0002 Event Map Y = Map Y of This Event
◆Control Variables:#0003 Player Map X = Map X of Player
◆Control Variables:#0004 Player Map Y = Map Y of Player
◆Comment:Calculate X distance
◆If:Player Map X < Event Map X
  ◆Control Variables:#0005 X Distance = Event Map X
  ◆Control Variables:#0005 X Distance -= Player Map X
  ◆
:Else
  ◆Control Variables:#0005 X Distance = Player Map X
  ◆Control Variables:#0005 X Distance -= Event Map X
  ◆
:End
◆Comment:Calculate Y distance
◆If:Player Map Y < Event Map Y
  ◆Control Variables:#0006 Y Distance = Event Map Y
  ◆Control Variables:#0006 Y Distance -= Player Map Y
  ◆
:Else
  ◆Control Variables:#0006 Y Distance = Player Map Y
  ◆Control Variables:#0006 Y Distance -= Event Map Y
  ◆
:End
◆Comment:Calculating squares distances
◆Control Variables:#0007 Total Distance = X Distance
◆Control Variables:#0007 Total Distance += Y Distance
◆Comment:Setting Var numbers for event graphics
◆Control Variables:#0009 Dark = 3
◆Control Variables:#0010 Less Dark = 2
◆Control Variables:#0011 Light = 1
◆Comment:Telling event to change based on each number.
◆If:Total Distance = Dark
  ◆Set Movement Route:This Event (Wait)
  :                  :◇Direction Fix OFF
  :                  :◇Turn Down
  :                  :◇Direction Fix ON
  ◆
:End
◆If:Total Distance = Less Dark
  ◆Set Movement Route:This Event (Wait)
  :                  :◇Direction Fix OFF
  :                  :◇Turn Left
  :                  :◇Direction Fix ON
  ◆
:End
◆If:Total Distance = Light
  ◆Set Movement Route:This Event (Wait)
  :                  :◇Direction Fix OFF
  :                  :◇Turn Right
  :                  :◇Direction Fix ON
  ◆
:End
I THINK i might have to actually do separate parts that also check if the player X is more than the events X or less than... same with the Y of the 2..because i think it's only really checking properly when the player is more IE below the event.
But.. there might be an easier way to go about it.
I actually looked at an old post i finally found when trying to figure this out... so i almost got it.. it almost works.


Okay forget that last part.
It works!
Gonna leave that there though, as it might help someone else later!

Original thread: https://forums.rpgmakerweb.com/threads/check-distance-between-player-and-event.78247/