Getting an event to recognize several others

● ARCHIVED · READ-ONLY
Started by Symbol_ 6 posts View original ↗
  1. So I currently have this script I'm working with

    (($gameVariables.value(crook x)+1) === $gameVariables.value(guard x) && ($gameVariables.value(crook y)-1) === $gameVariables.value(guard y)) || (($gameVariables.value(crook x)) === $gameVariables.value(guard x) && ($gameVariables.value(crook y)-1) === $gameVariables.value(guard y)) || (($gameVariables.value(crook x)-1) === $gameVariables.value(guard x) && ($gameVariables.value(crook y)-1) === $gameVariables.value(guard y)) || (($gameVariables.value(crook x)-1) === $gameVariables.value(guard x) && ($gameVariables.value(crook y)) === $gameVariables.value(guard y)) || (($gameVariables.value(crook x)+1) === $gameVariables.value(guard x) && ($gameVariables.value(crook y)) === $gameVariables.value(guard y)) || (($gameVariables.value(crook x)+1) === $gameVariables.value(guard x) && ($gameVariables.value(crook y)+1) === $gameVariables.value(guard y)) || (($gameVariables.value(crook x)) === $gameVariables.value(guard x) && ($gameVariables.value(crook y)+1) === $gameVariables.value(guard y)) || (($gameVariables.value(crook x)-1) === $gameVariables.value(guard x) && ($gameVariables.value(crook y)+1) === $gameVariables.value(guard y));

    To put it simply, what this does, is, (When put into a conditional branch for the guard) activates an event whenever the crook comes within one square of the guard.

    But what if I want to have multiple crooks? Do I need a conditional event for each crook? Or is it possible, that I could have the guard check for all crooks on the map. So in other terms:

    Could I get the guard event to recognize any crook event that it came into contact with, not just one particular specific event?
  2. That's too complicated. If your guard is standing still, just draw a square around him using a region tile, give all of your crook events the name Crook, and use the conditional branch below, replacing 1 with whatever region id you're after.

    Code:
    $gameMap.events().some(function(event) { return event.event().name === "Crook" && event.regionId() === 1; })

    If your guard is moving around, it's going to be more complicated, and the condition would need to be a little different.
  3. My
    Shaz said:
    That's too complicated. If your guard is standing still, just draw a square around him using a region tile, give all of your crook events the name Crook, and use the conditional branch below, replacing 1 with whatever region id you're after.

    Code:
    $gameMap.events().some(function(event) { return event.event().name === "Crook" && event.regionId() === 1; })

    If your guard is moving around, it's going to be more complicated, and the condition would need to be a little different.

    My guard is moving around.
  4. Oh goodness! Yeah, it'll get the job done, but it's so clumsy. Just subtract the guard's X from the crook's X, and check whether the absolute value Math.abs() of that result is 1 or less, and do the same for their Y values.

    With multiple crooks, you will want to use a For loop. You can either loop through easily using Event IDs (I believe MV's syntax is $gameMap.events()[event_id] but I could be wrong), or you can put all the crook events into an array and then loop through that array.

    Or, if you only need to check that any crooks are within range (and doing general processing if so), rather than checking whether each crook is in range (and doing processing with that crook if so), then you could use Shaz's "some" approach. Just use the absolute value approach rather than Region IDs.
  5. Wavelength said:
    Oh goodness! Yeah, it'll get the job done, but it's so clumsy. Just subtract the guard's X from the crook's X, and check whether the absolute value Math.abs() of that result is 1 or less, and do the same for their Y values.

    With multiple crooks, you will want to use a For loop. You can either loop through easily using Event IDs (I believe MV's syntax is $gameMap.events()[event_id] but I could be wrong), or you can put all the crook events into an array and then loop through that array.

    Or, if you only need to check that any crooks are within range (and doing general processing if so), rather than checking whether each crook is in range (and doing processing with that crook if so), then you could use Shaz's "some" approach. Just use the absolute value approach rather than Region IDs.

    Will this still work if both the crook and guard are moving? I'm not very savvy with script so what most of what you said flew over my head about the math.abs()
  6. Symbol_ said:
    Will this still work if both the crook and guard are moving? I'm not very savvy with script so what most of what you said flew over my head about the math.abs()

    Yes. Their X and Y values are wherever they currently are when the code/event is checking it. Obviously you'll probably want it to run every few frames so you can keep checking - but the fact that they're moving around won't present a problem.