Monster repellent Help

Ok so I made a monster reppellent for my game kinda like in pokemon where you use the item and monsters don't attack you for a while.
Here is the repellent:
Screenshot_2.png

And here are the common event setups:
Screenshot_3.png

Screenshot_4.png

The problem I am having is when I use it it works, but even after I go 100 steps it doesn't wear off. How do I fix this?
Thanks in advance for the help.
First two lines of your parallel process: It sets the variable as the number of steps, then removes the value of steps, thus rendering the final value always as zero.
First two lines of your parallel process: It sets the variable as the number of steps, then removes the value of steps, thus rendering the final value always as zero.
Ok, how would I go at fixing that so when the player takes 100 steps after they use the repellent it wears off?
You can approach this problem using addition instead of subtraction.
Simply change the "Steps Taken" variable to "Steps until wear off" and set its value as Steps+100 at the very moment you activate the repellent.
In your parallel process, instead of checking if your variable reached zero, you check if "Step" is Equal or Greater than "Steps until wear off".

Tell me if it works.
In the Item common event, set the variable to Steps then do += 100 to it.

In the parallel process common event, set a different variable to Steps, then compare it to see if it's greater than the original variable. Don't change the original variable.
In the Item common event, set the variable to Steps then do += 100 to it.

In the parallel process common event, set a different variable to Steps, then compare it to see if it's greater than the original variable. Don't change the original variable.
My apologies I am a bit confused on what you mean. Could you explain it a bit differently?
I am renaming your variables to make more sense with this method
In your Repel common event, do this:

Code:
Control Variables [0010: Required Steps] = Steps
Control Variables [0010: Required Steps] += 100
Control Switches [0042: Repel in Use] = ON

In your parallel process common event, do this (using whatever new variable you have available, if 11 is already taken):

Code:
Wait 5 Frames
Control Variables [0011: Steps Taken] = Steps
If Variable [0011: Steps Taken] >= Variable [0010: Required Steps]
  ... do some stuff
  When [Yes]
  Control Variables [0010: Required Steps] = Steps
  Control Variables [0010: Required Steps] += 100

So when you use the repellent, you're setting the variable to be the current steps + 100, which is when the repellent will wear off. Then every 5 frames you're checking to see how many steps the player has taken, and when they reach that number, it wears off.

The wait is because you don't need to do this 60 times per second. A wait of 5 frames allows the player to move 12 steps per second, which is unlikely. It also prevents your common event from causing lag (a parallel process with no wait is one of the most common causes of lag in games).

Doing the + 100 at the beginning also prevents the additional calculation every frame, which just reduces the work needed to be done by the parallel process event by a tiny bit.
I am renaming your variables to make more sense with this method
In your Repel common event, do this:

Code:
Control Variables [0010: Required Steps] = Steps
Control Variables [0010: Required Steps] += 100
Control Switches [0042: Repel in Use] = ON

In your parallel process common event, do this (using whatever new variable you have available, if 11 is already taken):

Code:
Wait 5 Frames
Control Variables [0011: Steps Taken] = Steps
If Variable [0011: Steps Taken] >= Variable [0010: Required Steps]
  ... do some stuff
  When [Yes]
  Control Variables [0010: Required Steps] = Steps
  Control Variables [0010: Required Steps] += 100

So when you use the repellent, you're setting the variable to be the current steps + 100, which is when the repellent will wear off. Then every 5 frames you're checking to see how many steps the player has taken, and when they reach that number, it wears off.

The wait is because you don't need to do this 60 times per second. A wait of 5 frames allows the player to move 12 steps per second, which is unlikely. It also prevents your common event from causing lag (a parallel process with no wait is one of the most common causes of lag in games).

Doing the + 100 at the beginning also prevents the additional calculation every frame, which just reduces the work needed to be done by the parallel process event by a tiny bit.
Here is the new setup: Want to know if I got this right
1597983424274.png

1597983441555.png

If I got something wrong please let me know.
No, first glance that looks fine. Did you give it a whirl? How did it go?
No, first glance that looks fine. Did you give it a whirl? How did it go?
Well it worked.

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/monster-repellent-help.125431/