Turn switch on for 150 steps

Hi all. I need to find a way to turn on a switch for 150 steps, when an item is used, then turn it off again.

The reason for this is because, in my game, the enemies are events that wander around the map (rather than random encounters). For most enemies, if their level is lower than the player's, they wander randomly. If it is higher, they approach the player. On event touch, battle starts.

The item I am trying to make is a repellent that the player can use to stop higher-level enemies attacking them for 150 steps.

The problem is that for each emeny event, I have an event page for when the player's level is lower than the enemy's (enemy approaches), and another for when it is higher (enemy moves randomly). I need a third page where when the 'repellent' switch is on, the event moves randomly.

I tried a conditional branch on the approach page so that if the repellent state is on then it skips the battle (Jump to label: end), but that doesn't stop higher-level enemies approaching (and the player ends up surrounded and unable to move).

Because you cannot turn on a switch in the 'Effects' part of an item, instead I triggered a common event where the switch is turned on. This works, but I need the switch to turn off again once the effect wears off. I tried a loop, but it freezes the player movement once the item is used.

Any ideas?

I've attached a screenshot of my pathetic attempt at a common event with the loop that doesn't work, the item page and the state page.

Thanks in advance. 😀
So in the common event attached to the item, do this:
Code:
Control Variables: Target Steps = Game Data > Other > Player Steps
Control Variables: Target Steps += 150
Control Switches: Repellent On = ON

Then create another common event, set to parallel process, conditioned by the Repellent On switch
Code:
Wait 5 Frames
Control Variables: Current Steps = Game Data > Other > Player Steps
Conditional Branch: If Variable [Current Steps] >= Player Steps
  Control Switches: Repellent On = OFF
End

So when the item is used, it gets the current number of steps and adds 150 to give the total number of steps that will trigger the repellent wearing off. Then it turns on the switch that controls the parallel process, which checks every 5 frames to see if the player has reached the target number of steps and it's time for the repellent to wear off. The Wait is there to stop it causing any kind of lag. With a 5 frame wait, it's going to check 12 times per second, and it's very unlikely the player is going to move more than 12 times a second. If they take one or two steps extra, which is also unlikely, it's not going to matter very much.

No loops. No states.
Thank you. It works perfectly now. 🙂

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.

Original thread: https://forums.rpgmakerweb.com/threads/turn-switch-on-for-150-steps.95218/