Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Proximity-based detection?

Actaeonis

Villager
Xy$
0.00
I'm looking to implement events that randomly activate when you load the map, but you can also tell which events activated based on your proximity to them. The random activation is easy enough, but I'm having trouble implementing proximity-based detection on several events at once without using an obscene amount of variables. Using a common event just causes each event to overwrite the others, leaving some activated events with no detection. I hope this makes sense, it sounds more complicated now that I've typed it out.
 

trapless

Villager
Xy$
0.00
Please rewrite your question it is very dificult to understand.
I'm not sure about your first sentence "I'm looking to implement events that randomly activate when you load the map, but you can also tell which events activated based on your proximity to them.".
Do you mean, you want random activation, proximity activation and the ability to reference how each event was activated?

If you list your goals seperately, explain what you have done to achieve them and share your results this will be easier to figure out.
 

Actaeonis

Villager
Xy$
0.00
I have created several events that activate self-switches based on the result of a random number generator. What I want is for a common event to trigger when the character is within 3 spaces of one of these "activated" events, but not when near an event that didn't "activate".

I hope this clears things up. I don't know how else to explain this.
 

trapless

Villager
Xy$
0.00
I think I understand now. It has been a while since I've opened the event editor so I'll have a look at what we can use in there. I'll take a good stab at this today and keep an eye on the thread until we figure this much out.

and good morning :)
 

trapless

Villager
Xy$
0.00
I'm guessing you flipped the activated event to a new page with the self switch and from that new page are wanting to monitor player proximity. If so, on that page, create a conditional branch and select "script" on tab four. Paste the following code in the script box:
JavaScript:
(() => {let ex = $gameMap.event(this._eventId)._x;let ey = $gameMap.event(this._eventId)._y;let px = $gamePlayer._x;let py = $gamePlayer._y;let x = ex - px;let y = ey - py;let d = Math.sqrt( x*x + y*y );if (d <= 3) {return true;}return false;})();
I had to make the code one line before i could paste it in or else MV would crash on paste. Maybe because I'm running only 2 GB of memory on this machine, I don't know...
That code is written in ES6 syntax which MV now supports, tested on MV 1.6.0
It calculates the distance between the event tile and the player tile. Thats not exactly counting tiles... it uses a radius around the event and returns true when you are within it.
Let me know if that works out for ya.

oh... the page with this script needs to be set to parallel so it is constantly chacking the condition.
Running a lot of parallel events can slow your game mind you.
I would flip the page to one that isnt parallel once the player is detected to stop the process if possible.
 
Last edited:
Top