Is it possible to run an event every time the player moves / takes a step? How?
Thank you in advance!
you could set an event on each tile that would activate when the player steps on it thus allowing events every step.
Yes. It is possible.
First, create a map event or common event (for use on multiple maps). Set the trigger to 'Parallel Process'. If it is a common event, you need to activate it with a switch.
Then, add the following commands in the contents:
- Control Variables: [0001: Xcoordinates] = Player's Map X
- Control Variables: [0002: Ycoordinates] = Player's Map Y
- Wait: 15 frame(s)
- Conditional Branch: Script Call : $game_variables[1] != $game_player.x || $game_variables[2] != $game_player.y
Moved to: VX Ace Support[move]
I would just use Control Variables to obtain # steps (it's in Game Data > Other), compare that to a second variable with the # steps stored (this will be 0 by default at the start, so you don't need to worry about initializing it). Then a Conditional Branch to see if they're different - if they are, do what you want to do, then change the second variable to be equal to the first.
All in a parallel process common event (which will be conditioned by a switch, which you WILL have to initialize at the start of the game). Make sure there's a Wait 10 Frames or something - you don't need to check 60 times a second to see whether the player has taken a step.[/move]
Thanks, I think I have several ideas about how to do it.
I know a bunch of people are suggesting to include a "wait 10 frames" part - thing is, I was thinking of using this for enemies...every time the player takes a step, the enemies move 1 step toward you. Not sure if there's an easier way to do this or if this information sheds light on the best approach to this.
The wait is to prevent lag caused by having parallel process events that don't come up for air and let other events get a look-in.
If you are going to put this on individual enemies and have them set to parallel process, you DEFINITELY want to have a wait here.
How are you planning to make the enemies move - are you going to put this logic on every enemy event? If so, you will need to use different variables for each one. Not very nice.
You might be better off having the event set to parallel process as a map event, rather than a common event, then in the "player has taken a step" logic, user a number of Set Move Route commands to make each enemy move one step closer to the player. Then you only need one variable, one event to monitor everything, and all enemies will be updated accordingly.
Yeah, I was going to make each map event have their move route command "1 step toward player" every time the player takes a step. So I can just use the above variable logic, throw on a few wait frames, and this'll work?
Make Paralel comon Event and do:
Control Variable[2] = Other--Steps.
If Variable[2] more than Variable[1]
than Variable[1] += 1 and Control Switch[1] = On
Switch[1] activates another Common Event. (The CE should also deactivate Switch[1] after the code had run.
Should get you startet.