this.event's position vs other events radius (Solved!)

● ARCHIVED · READ-ONLY
Started by userlame 4 posts View original ↗
  1. I want something to happen to a monster event on the map when it's next to events named trap. Event ID's are out of the question as these will be spawned in randomly. So like, if an event with a parallel process running the script is within radius 1 of trap then flick a self switch or set a variable or something. This is what the code looks like right now.
    Code:
    var trapEvents = $gameMap.events().filter(function(event) { return event.event().name === 'trap'; });
    var monster = $gameMap.event(this.eventId());
    trapEvents.forEach(function(trap) {
      if (monster.x < trap.x + 1 && monster.x > trap.x - 1 && monster.y < trap.y + 1 && monster.y > trap.y - 1) {
        $gameVariables.setValue(13, 1);
      }
    });

    I put variable 13 so it's easy to check. But when the monster event is next to events named trap, nothing changes.
  2. monster.x < trap.x + 1 && monster.x > trap.x -1
    is equivalent to monster.x == trap.x
    monster.y < trap.y + 1 && monster.y > trap.y - 1 is equivalent to monster.y == trap.y

    so you're saying
    if (monster.x == trap.x && monster.y == trap.y) set the variable.
    Replace > with >= and < with <=
  3. Code:
    var trapEvents = $gameMap.events().filter(function(event) { return event.event().name === 'trap'; });
    var monster = $gameMap.event(this.eventId());
    trapEvents.forEach(function(trap) {
      if (monster.x <= (trap.x + 1) && monster.x >= (trap.x - 1) && monster.y <= (trap.y + 1) && monster.y >= (trap.y - 1) {
        $gameVariables.setValue(13, 1);
      }
    });
    I see. Now it works like a charm, thank you for your help!
  4. This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.