# How to check player proximity to event

#### redmedved2

##### Veteran
Objective: to create a parallel event that makes a sound until the player comes to it, so then another action will be triggered.

For now I made it with two events: One parallel event creates sound and checking if my utility variable value = 146. Another event right next to it is an autorun event, but it has YEP proximity activate condition, so it activates only when player is in range of 5 tiles. All it does is sets utility variable value to 146 and deletes itself, so another event will react to it and launch the main event instead of looping sound.

But I don't think it's the best approach, and because it's the second time I have to make such event, I want to improve it. Is there a way to make everything in one event, using the conditional branches? I haven't found player proximity in branches' options, but there is option for scripts. Will it be hard to write such a script?

#### Andar

##### Veteran
the key to this are mathematics and control variable.

you can use control variable to get the player coordinates into two variables, and then either coordinates or another event position into two more coordinates.

after that it is only https://en.wikipedia.org/wiki/Pythagorean_theorem to calculate the distance between the positions

#### Soulrender

Correct, but you need a direct solution for checking the distance between events (player pos too)
is method within MV:

\$gameMap.distance()

example usage:

#### deus69xxx

##### Ultima Ratio Regum
Might check YEP_EventChasePlayer. it has a distance option, and some activation options, i don't think it actually HAS to chase anyone.

#### redmedved2

##### Veteran
Correct, but you need a direct solution for checking the distance between events (player pos too)
is method within MV:

\$gameMap.distance()

example usage:
I honestly don't understand, is this script self-sufficient, or do I need to assign values to variables myself?

It doesn't really work just like that. Did I made a mistake?

Might check YEP_EventChasePlayer. it has a distance option, and some activation options, i don't think it actually HAS to chase anyone.
I checked it, it has the common event activation option. I can use common event to assign some variable value to specific number to activate the main event. If I won't be able to make it with scripts, I will use this method, thank you.

#### Attachments

• 1650666312553.png
115.4 KB · Views: 7

#### RCXGaming

##### Champion of Brightmoon Tor
So @redmedved2 you want a system that tracks the distance between the player and an NPC event? Then this might work for you:

(Ignore the "R Button is pressed" part. Also the first two variables track the NPC's X and Y coordinates)

This is a system I cooked up in VX Ace that tracks how far away you are from an event in tiles, and it's extremely powerful since it even tracks diagonal distance. Just set it up as exactly as pictured and it should track how far away the player is from an event if that's what you need.

Just be careful: you have to count negatives as well. It would look like this in a conditional branch's script part -
\$game_variables[902] == 1 || \$game_variables[902] == -1
(This particular version tracks if you're directly adjacent to an event.)

Likewise, this version tracks if you're in distance of 5 tiles:
\$game_variables[902] <= 5 || \$game_variables[902] >= -5

This version tracks if you're over 5 tiles away:
\$game_variables[902] >= 6 || \$game_variables[902] <= -6

... Only trade in the script format for what MV uses (\$gameVariables.value(variableId) / value);) and you should be good.

Last edited:

#### Soulrender

@redmedved2 It's self sufficient, just replace the eventId with actuall ID of event you want to check, I'm using exactly the same code as parallel event in escort quest in my game and it works. But I see I've made a mistake in value comparison, I used lower or equal <= but it should be greater or equal >=

#### pmerrifield

##### Warper
@redmedved2 It's self sufficient, just replace the eventId with actuall ID of event you want to check, I'm using exactly the same code as parallel event in escort quest in my game and it works. But I see I've made a mistake in value comparison, I used lower or equal <= but it should be greater or equal >=
Hi there, I just tried this and am getting a SyntaxError: Missing ) after argument list. I went ahead and removed the conditional "if" section to figure out where it thinks it wants an end-parenthesis and it wants it somewhere in the initial script.

I get the error like this and with the full copy of what you did. Any ideas?

#### ct_bolt

##### Creator
Hi there, I just tried this and am getting a SyntaxError: Missing ) after argument list. I went ahead and removed the conditional "if" section to figure out where it thinks it wants an end-parenthesis and it wants it somewhere in the initial script.

I get the error like this and with the full copy of what you did. Any ideas?
View attachment 241329

"\$gameMap.event" is a function that looks for an event number as it's parameter.
So your code above should be something like...
JavaScript:
``\$gameVariables.setValue(10, \$gameMap.event(91).x)``
That would store event #91's x into variable 10

or...
JavaScript:
``\$gameVariables.setValue(10, \$gameMap.event(this._eventId).x)``
That would store the current event's x into variable 10

Alternatively if you really want to use the name to get the event... could be done like this:
JavaScript:
``````var id = \$dataMap.events.filter(function(event){if (event) {return event.name === "Harpy 1"};})[0].id;
\$gameVariables.setValue(10, \$gameMap.event(id).x)``````
That would store the x location of the event named "Harpy 1" into variable 10

...
That said if you want I do have a plugin to do such things & more.
Originally created for another user just to check for the nearest event.. but has expanded into more now.

Sooo anyways with that plugin then to do what you have above could then be done like this:
or alternatively.. same thing..
...and to use my plugin to do this by the name of the event would be like this:

Last edited:

#### pmerrifield

##### Warper
I really appreciate all the helpful tips!!

This is what I found that was simplest and accomplished exactly what I was looking to do:

### Latest Profile Posts

working on an A/V sync system for my game! was NOT expecting the first roadblock to be accessing a variable from a public class!! Computers are so finicky sometimes
For the first real time since my game's inception I found myself actually having fun playing around with my party's skills while testing out some battles! So much so, that I actually forgot what I was doing for a minute and had to force myself to move on to the next thing!

That's got to be a good sign considering it only has place holder animations, enemy skills, troop comps, etc. right now. Feels good!

FINALLY, I figured out how to get the "tail" to appear IN the window and not directly below it lol. now it looks like it's part of the window and not hanging from the bottom of it.
Twitch! Stream is about to go live with some Dark Souls 2! Feel free to drop by!