1. Dismiss Notice
  2. Within our Resources section we have over 150 Audio files, with room to grow. You may find exactly what you have been looking for. Just CLICK HERE to start your listening adventure.
    Dismiss Notice
  3. Why would you want to upload your resources directly to RMMV.co? It makes it easier for other members to download them. Click HERE for more information.
    Dismiss Notice
  4. Click HERE to see our four new featured resources by TheUnproPro, Starbird, iblamevictoria, and VGM MarkH.
    Dismiss Notice
  5. Here are the The Resource Rules.
    Dismiss Notice
  6. Please read these RULES before posting.
    Dismiss Notice

Proximity-based detection?

Discussion in 'Javascript & Event Design' started by Actaeonis, Jan 12, 2018.

  1. 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.
     
  2. 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.
     
  3. 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.
     
  4. 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 :)
     
  5. Good morning, and thank you for the help.
     
  6. #6 trapless, Feb 24, 2018
    Last edited: Feb 24, 2018
    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:
    Code (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.
     

Share This Page

Loading...