redmedved2

Veteran
Veteran
Joined
Nov 2, 2020
Messages
137
Reaction score
65
First Language
Belarusian
Primarily Uses
RMMV
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
Veteran
Joined
Mar 5, 2013
Messages
37,304
Reaction score
10,173
First Language
German
Primarily Uses
RMMV
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

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
1,609
Reaction score
1,128
First Language
Polish
Primarily Uses
RMMV
Correct, but you need a direct solution for checking the distance between events (player pos too)
is method within MV:

$gameMap.distance()

example usage:
wwEuXdG.png
 

deus69xxx

Ultima Ratio Regum
Veteran
Joined
Oct 13, 2013
Messages
108
Reaction score
53
First Language
English
Primarily Uses
RMMV
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
Veteran
Joined
Nov 2, 2020
Messages
137
Reaction score
65
First Language
Belarusian
Primarily Uses
RMMV
Correct, but you need a direct solution for checking the distance between events (player pos too)
is method within MV:

$gameMap.distance()

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

1650666263323.png
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
    1650666312553.png
    115.4 KB · Views: 7

RCXGaming

Champion of Brightmoon Tor
Veteran
Joined
Jan 4, 2019
Messages
690
Reaction score
1,533
First Language
English
Primarily Uses
RMVXA
So @redmedved2 you want a system that tracks the distance between the player and an NPC event? Then this might work for you:

FhK7jE1.png


(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

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
1,609
Reaction score
1,128
First Language
Polish
Primarily Uses
RMMV
@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
Member
Joined
Mar 21, 2019
Messages
4
Reaction score
1
First Language
English
Primarily Uses
RMMV
@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?
1664221127203.png
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
1,283
Reaction score
824
First Language
Javascript
Primarily Uses
RMMZ
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.

CTB_NearestEventMV Plugin: Click Here to Download

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

pmerrifield

Warper
Member
Joined
Mar 21, 2019
Messages
4
Reaction score
1
First Language
English
Primarily Uses
RMMV
I really appreciate all the helpful tips!!

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

1664341227681.png
 

Latest Threads

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 :kaosigh:
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! :guffaw:

That's got to be a good sign considering it only has place holder animations, enemy skills, troop comps, etc. right now. Feels good!
Bex
Finally upgraded to RMMZ.
ScreenShot_11_28_2022_7_52_34.png
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!

Forum statistics

Threads
126,925
Messages
1,182,403
Members
166,759
Latest member
Ninja777
Top