Extension or modification of YEP_EventProxActivate to detect if player is in front of event

Hello,

I'd like to use Yanfly's Event Proximity Activate plugin, but have it so that it will only run if I'm in front of the event. So, for example, if the event is facing down, and my y position is greater than the event's y position, then activation occures, otherwise nothing happens.

I tried using my own conditions to check for if the player is in front of event, like (for example):

Control Variables : event direction
Control Variables : event x position
Control Variables : event y position
Control Variables : player x position
Control Variables : player y position
if event direction = 2
if player y postion > event y postion
<Comment : Activation Radius: 9>
end
end

The problem is that just having the <Comment : Activation Radius: 9> anywhere on the page activates the plugin. Putting it inside a condition is no different from having it anywhere else. So if you had something like:

if 2 = 3
<Comment : Activation Radius: 9>
end

it would still activate whatever else you have on the event page. My reasons for wanting this are kind of complicated, but it would also be useful for anyone who wanted to allow the player to approach an event from behind without activating it, which is generally more realistic.

Thanks for reading!
@JDevain just replace this part of code:
Code:
Game_Player.prototype.meetPlayerProximityConditions = function(ev) {
  if (ev._activationType === 'radius') {
    var x1 = this.x;
    var y1 = this.y;
    var x2 = ev.x;
    var y2 = ev.y;
    var radius = $gameMap.distance(x1, y1, x2, y2);
    return ev._activationDist >= radius
  } else if (ev._activationType === 'square') {
    return ev._activationDist >= Math.abs(ev.deltaXFrom(this.x)) &&
           ev._activationDist >= Math.abs(ev.deltaYFrom(this.y));
  } else if (ev._activationType === 'row') {
    return ev._activationDist >= Math.abs(ev.deltaYFrom(this.y));
  } else if (ev._activationType === 'column') {
    return ev._activationDist >= Math.abs(ev.deltaXFrom(this.x));
  } else {
    return false;
  }
};

with this:
Code:
Game_Player.prototype.meetPlayerProximityConditions = function(ev) {
  if (ev._activationType === 'radius') {
    var x1 = this.x;
    var y1 = this.y;
    var x2 = ev.x;
    var y2 = ev.y;
    var radius = $gameMap.distance(x1, y1, x2, y2);
    return ev._activationDist >= radius && (this._direction + ev._direction) == 10
  } else if (ev._activationType === 'square') {
    return ev._activationDist >= Math.abs(ev.deltaXFrom(this.x)) &&
           ev._activationDist >= Math.abs(ev.deltaYFrom(this.y));
  } else if (ev._activationType === 'row') {
    return ev._activationDist >= Math.abs(ev.deltaYFrom(this.y));
  } else if (ev._activationType === 'column') {
    return ev._activationDist >= Math.abs(ev.deltaXFrom(this.x));
  } else {
    return false;
  }
};
Now the event won't active unless the Event is facing directly with your Player (it will work with 'Radius' type only)
Well well, Bella_Ghost, look at you. First day on the job, and you're already knocking out problems like a champ. I have to say, I'm impressed. What are you, some kind of javascript ninja?

In any case, thank you!
@JDevain just replace this part of code:
Code:
Game_Player.prototype.meetPlayerProximityConditions = function(ev) {
  if (ev._activationType === 'radius') {
    var x1 = this.x;
    var y1 = this.y;
    var x2 = ev.x;
    var y2 = ev.y;
    var radius = $gameMap.distance(x1, y1, x2, y2);
    return ev._activationDist >= radius
  } else if (ev._activationType === 'square') {
    return ev._activationDist >= Math.abs(ev.deltaXFrom(this.x)) &&
           ev._activationDist >= Math.abs(ev.deltaYFrom(this.y));
  } else if (ev._activationType === 'row') {
    return ev._activationDist >= Math.abs(ev.deltaYFrom(this.y));
  } else if (ev._activationType === 'column') {
    return ev._activationDist >= Math.abs(ev.deltaXFrom(this.x));
  } else {
    return false;
  }
};

with this:
Code:
Game_Player.prototype.meetPlayerProximityConditions = function(ev) {
  if (ev._activationType === 'radius') {
    var x1 = this.x;
    var y1 = this.y;
    var x2 = ev.x;
    var y2 = ev.y;
    var radius = $gameMap.distance(x1, y1, x2, y2);
    return ev._activationDist >= radius && (this._direction + ev._direction) == 10
  } else if (ev._activationType === 'square') {
    return ev._activationDist >= Math.abs(ev.deltaXFrom(this.x)) &&
           ev._activationDist >= Math.abs(ev.deltaYFrom(this.y));
  } else if (ev._activationType === 'row') {
    return ev._activationDist >= Math.abs(ev.deltaYFrom(this.y));
  } else if (ev._activationType === 'column') {
    return ev._activationDist >= Math.abs(ev.deltaXFrom(this.x));
  } else {
    return false;
  }
};
Now the event won't active unless the Event is facing directly with your Player (it will work with 'Radius' type only)

I also have that problem and you solved me thank you very much
(this._direction + ev._direction) == 10

Doesn't this mean the event and the player have to be facing each other? What if the event is facing down, and my y position is greater than the event's, but I am also facing down? this._direction + ev._direction will only be 4 so the condition will not be met?
Doesn't this mean the event and the player have to be facing each other?

Yeah, that turned out to be the case. I ended up going in a different direction, so it doesn't really matter to me, but it doesn't work if event and player aren't facing one another.

Original thread: https://forums.rpgmakerweb.com/threads/extension-or-modification-of-yep_eventproxactivate-to-detect-if-player-is-in-front-of-event.104014/