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

JDevain

Veteran
Veteran
Joined
Oct 21, 2018
Messages
121
Reaction score
46
First Language
English
Primarily Uses
RMMV
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!
 

Bella_Ghost

Warper
Member
Joined
Jan 7, 2019
Messages
4
Reaction score
3
First Language
English
Primarily Uses
Other
@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)
 

JDevain

Veteran
Veteran
Joined
Oct 21, 2018
Messages
121
Reaction score
46
First Language
English
Primarily Uses
RMMV
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!
 
Last edited:

Nacura

Veteran
Veteran
Joined
Feb 4, 2018
Messages
125
Reaction score
14
First Language
Español
Primarily Uses
RMMV
@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
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
(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?
 

JDevain

Veteran
Veteran
Joined
Oct 21, 2018
Messages
121
Reaction score
46
First Language
English
Primarily Uses
RMMV
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,990
Members
137,562
Latest member
tamedeathman
Top