Assistance with making a state reduce your on-map movement speed.

Hello.

I am attempting to create a state that once inflicted will reduce your movement speed.

What happens is. (My game has no battles so I want the player to just make sure to avoid the enemies)

What I have done so far:
A event runs toward you after you alert it. If you get hit, you have 25% of being inflicted this movement reducing state
which is reducing your movement speed from 4 to 3.

The event then has a small wait time (as to not stun-lock you) and if you have the previous state inflicted, I want the movement speed to be further reduced down to 2, and then to 1. Making it impossible to run from the enemy.

I have made everything so far and attempted to do a parallel event check for the state but that just lags the game down most of the time and for some reason it does not always work (?)

[I am using yepfly chase player] for the alart - run thing.
Is there a reason you're doing something with a Parallel event rather than just changing the player's speed when they get hit? 😅

I'd consider using a variable, maybe something like this in the chasing event (Event Touch trigger):
Spoiler: Event example
Code:
◆Comment:Uh oh!
◆Show Balloon Icon:This Event, Anger
◆Comment:25% chance to hit
◆Control Variables:#0008 Temporary = Random 1..100
◆If:Temporary ≤ 25
  ◆Comment:Show animation
  ◆Show Animation:Player, Hit Physical
  ◆Show Balloon Icon:Player, Exclamation
  ◆Comment:+1 hit!
  ◆Control Variables:#0007 Count += 1
  ◆Comment:Change player speed
  ◆If:Count = 1
    ◆Set Movement Route:Player (Wait)
    :                  :◇Speed:3
    ◆
  :Else
    ◆If:Count = 2
      ◆Set Movement Route:Player (Wait)
      :                  :◇Speed:2
      ◆
    :Else
      ◆Comment:Too many hits, game over
      ◆Game Over
      ◆
    :End
    ◆
  :End
  ◆
:End
◆Comment:I'll wait here a moment to let you run away
◆Set Movement Route:This Event
:                  :◇Wait:30 frames
You could use states instead (or as well), this is just an example~ 🙏
Is there a reason you're doing something with a Parallel event rather than just changing the player's speed when they get hit? 😅

I'd consider using a variable, maybe something like this in the chasing event (Event Touch trigger):
Spoiler: Event example
Code:
◆Comment:Uh oh![/INDENT]
[INDENT]◆Show Balloon Icon:This Event, Anger[/INDENT]
[INDENT]◆Comment:25% chance to hit[/INDENT]
[INDENT]◆Control Variables:#0008 Temporary = Random 1..100[/INDENT]
[INDENT]◆If:Temporary ≤ 25[/INDENT]
[INDENT]  ◆Comment:Show animation[/INDENT]
[INDENT]  ◆Show Animation:Player, Hit Physical[/INDENT]
[INDENT]  ◆Show Balloon Icon:Player, Exclamation[/INDENT]
[INDENT]  ◆Comment:+1 hit![/INDENT]
[INDENT]  ◆Control Variables:#0007 Count += 1[/INDENT]
[INDENT]  ◆Comment:Change player speed[/INDENT]
[INDENT]  ◆If:Count = 1[/INDENT]
[INDENT]    ◆Set Movement Route:Player (Wait)[/INDENT]
[INDENT]    :                  :◇Speed:3[/INDENT]
[INDENT]    ◆[/INDENT]
[INDENT]  :Else[/INDENT]
[INDENT]    ◆If:Count = 2[/INDENT]
[INDENT]      ◆Set Movement Route:Player (Wait)[/INDENT]
[INDENT]      :                  :◇Speed:2[/INDENT]
[INDENT]      ◆[/INDENT]
[INDENT]    :Else[/INDENT]
[INDENT]      ◆Comment:Too many hits, game over[/INDENT]
[INDENT]      ◆Game Over[/INDENT]
[INDENT]      ◆[/INDENT]
[INDENT]    :End[/INDENT]
[INDENT]    ◆[/INDENT]
[INDENT]  :End[/INDENT]
[INDENT]  ◆[/INDENT]
[INDENT]:End[/INDENT]
[INDENT]◆Comment:I'll wait here a moment to let you run away[/INDENT]
[INDENT]◆Set Movement Route:This Event[/INDENT]
[INDENT]:                  :◇Wait:30 frames
You could use states instead (or as well), this is just an example~ 🙏


Hey Caethyril! Thanks for your response.

I was experimenting with states as I had never used them before and I wanted to get a chance to experiment.

My problem with your approach, how will the player's movement speed return to normal afterwards? Only way I could think would be to exit the area.

When you mean with states I assume you mean in the conditional branches or do you have a better idea on that?

I was thinking it would be nice to get rid of the state to reset after x steps (Which I saw was possible) but it was difficult for me to check all those conditions without messing it up ^^ "
Oh, I see! It is possible to make effects that are timed or based on a number of steps etc. I don't blame you for getting confused in the eventing, though. It might look a bit complicated, but it splits neatly into smaller concepts:
Spoiler: Event structure
  1. Parallel event
    Code:
    ◆Comment:Do stuff here!
    ◆Comment:--------------------------------------------------
    ◆Comment:Wait 6 frames (i.e. do the stuff 10 times per second)
    ◆Wait:6 frames
    • Have a Parallel event that does stuff once every X frames, using a Wait command.
    • If it applies to all maps, make it a Common Event (defined in the database).
      If it only applies to one map, make it a map event.
    • Note that you can check multiple things in the same event~

  2. Long timers
    Code:
    ◆Comment:Initialise time variable!
    ◆Control Variables:#0020 Time = 30
    Code:
    ◆Comment:Is there time left on this timer?
    ◆If:Time > 0
      ◆Comment:-1 from timer value
      ◆Control Variables:#0020 Time -= 1
      ◆Comment:Has time expired?
      ◆If:Time ≤ 0
        ◆Comment:OK, do the timeout thing here!
        ◆
      :End
      ◆
    :End
    • You could do "Wait 180 frames" or something. That's generally a bad idea, though: Parallel events reset when the player changes maps, plus you'd need separate events for each timer.
    • Instead, I recommend using a variable, and ticking down that variable every X frames in a Parallel event. If X is small compared to the total wait time, the potential "reset error" time will be insignificant.
    • Note: if X = 6 frames, a value of 1 in the timer variable represents 6 frames of wait time.

  3. Other checks, e.g. step count
    Code:
    ◆Comment:Initialise step count!
    ◆Control Variables:#0014 Hit Recovery Steps = 30
    Code:
    ◆Comment:Get difference between stored step count and current value
    :       :(Variables start with value 0 by default.)
    ◆Control Variables:#0015 Step Count -= Steps
    ◆Comment:Check difference...
    ◆If:Step Count ≠ 0
      ◆Comment:Step count has changed!
      :       :Do the things!
      ◆
    :End
    ◆Comment:Reset value to current step count, ready for the next check!
    ◆Control Variables:#0015 Step Count = Steps
    • You can check other things in a similar way, e.g. step count.
      You can get the step count via Control Variables > Game Data > Other > Steps.
    • If a value has changed: the stored value and the current value will be different. I.e. if you subtract the current value from the stored value, the result will not be 0.
    • You can then use a similar approach to what I mentioned for "long timers", above: -1 to the step counter each step and do something when the counter hits zero. 😤
So...putting that all together, you can add something like this when the player gets hit:
Code:
◆Control Variables:#0014 Hit Recovery Steps = 30
Then have a Parallel event to decrease the hit count variable every 30 steps, e.g.
Spoiler: Example Parallel event
Code:
◆Comment:Check difference between current step count and stored value (it's 0 on new game)
◆Control Variables:#0015 Step Count -= Steps
◆If:Step Count ≠ 0
  ◆Comment:Step count has changed since last check!
  ◆Comment:--------------------------------------------
  ◆Comment:Is recovering from a hit?
  ◆If:Hit Recovery Steps > 0
    ◆Comment:-1 to this step counter!
    ◆Control Variables:#0014 Hit Recovery Steps -= 1
    ◆Comment:Reached 0 (recovered)?
    ◆If:Hit Recovery Steps = 0
      ◆Comment:-1 to hit count! (+ balloon for visible feedback)
      ◆Control Variables:#0007 Count -= 1
      ◆Show Balloon Icon:Player, Music Note
      ◆Comment:Change speed to match new hit count~
      ◆If:Count = 0
        ◆Set Movement Route:Player (Wait)
        :                  :◇Speed:4
        ◆
      :Else
        ◆If:Count = 1
          ◆Set Movement Route:Player (Wait)
          :                  :◇Speed:3
          ◆
        :Else
          ◆Set Movement Route:Player (Wait)
          :                  :◇Speed:2
          ◆
        :End
        ◆
      :End
      ◆Comment:Count is still more than 0?
      ◆If:Count > 0
        ◆Comment:Reset hit recovery step counter!
        ◆Control Variables:#0014 Hit Recovery Steps = 30
        ◆
      :End
      ◆
    :End
    ◆
  :End
  ◆Comment:--------------------------------------------
  ◆Comment:Can check other "on step" stuff here, too~
  ◆
:End
◆Comment:Store current step count for next check!
◆Control Variables:#0015 Step Count = Steps
◆Comment:Check again in 6 frames (10 times per second)
◆Wait:6 frames
Obviously you can replace the values as you like. Hope that made some sense! 🙏

If this seems like a lot of trouble to go to for "do stuff on step", there are plugins that let you cut corners here. E.g. I have a plugin called Cae_StepSwitch that lets you automatically turn on a switch every step. You can bind this switch to a Parallel event, then make the event switch itself off at the end.

Lastly: states are typically for "per person" stuff, but this sounds like a "per party" idea, right? You could use states, but things might get awkward if, for example, the player can change the party leader or swap members in/out. That's why I suggested variables~ 👋
Oh, I see! It is possible to make effects that are timed or based on a number of steps etc. I don't blame you for getting confused in the eventing, though. It might look a bit complicated, but it splits neatly into smaller concepts:
​
Spoiler: Event structure
  1. Parallel event
    Code:
    ◆Comment:Do stuff here!
    ◆Comment:--------------------------------------------------
    ◆Comment:Wait 6 frames (i.e. do the stuff 10 times per second)
    ◆Wait:6 frames
    • Have a Parallel event that does stuff once every X frames, using a Wait command.
    • If it applies to all maps, make it a Common Event (defined in the database).
      If it only applies to one map, make it a map event.
    • Note that you can check multiple things in the same event~

  2. Long timers
    Code:
    ◆Comment:Initialise time variable!
    ◆Control Variables:#0020 Time = 30
    Code:
    ◆Comment:Is there time left on this timer?
    ◆If:Time > 0
    ◆Comment:-1 from timer value
    ◆Control Variables:#0020 Time -= 1
    ◆Comment:Has time expired?
    ◆If:Time ≤ 0
    ◆Comment:OK, do the timeout thing here!
    ◆
    :End
    ◆
    :End
    • You could do "Wait 180 frames" or something. That's generally a bad idea, though: Parallel events reset when the player changes maps, plus you'd need separate events for each timer.
    • Instead, I recommend using a variable, and ticking down that variable every X frames in a Parallel event. If X is small compared to the total wait time, the potential "reset error" time will be insignificant.
    • Note: if X = 6 frames, a value of 1 in the timer variable represents 6 frames of wait time.

  3. Other checks, e.g. step count
    Code:
    ◆Comment:Initialise step count!
    ◆Control Variables:#0014 Hit Recovery Steps = 30
    Code:
    ◆Comment:Get difference between stored step count and current value
    : :(Variables start with value 0 by default.)
    ◆Control Variables:#0015 Step Count -= Steps
    ◆Comment:Check difference...
    ◆If:Step Count ≠ 0
    ◆Comment:Step count has changed!
    : :Do the things!
    ◆
    :End
    ◆Comment:Reset value to current step count, ready for the next check!
    ◆Control Variables:#0015 Step Count = Steps
    • You can check other things in a similar way, e.g. step count.
      You can get the step count via Control Variables > Game Data > Other > Steps.
    • If a value has changed: the stored value and the current value will be different. I.e. if you subtract the current value from the stored value, the result will not be 0.
    • You can then use a similar approach to what I mentioned for "long timers", above: -1 to the step counter each step and do something when the counter hits zero. 😤

​
​
So...putting that all together, you can add something like this when the player gets hit:
Code:
◆Control Variables:#0014 Hit Recovery Steps = 30
Then have a Parallel event to decrease the hit count variable every 30 steps, e.g.
Spoiler: Example Parallel event
Code:
◆Comment:Check difference between current step count and stored value (it's 0 on new game)[/INDENT]
[INDENT]◆Control Variables:#0015 Step Count -= Steps[/INDENT]
[INDENT]◆If:Step Count ≠ 0[/INDENT]
[INDENT]  ◆Comment:Step count has changed since last check![/INDENT]
[INDENT]  ◆Comment:--------------------------------------------[/INDENT]
[INDENT]  ◆Comment:Is recovering from a hit?[/INDENT]
[INDENT]  ◆If:Hit Recovery Steps > 0[/INDENT]
[INDENT]    ◆Comment:-1 to this step counter![/INDENT]
[INDENT]    ◆Control Variables:#0014 Hit Recovery Steps -= 1[/INDENT]
[INDENT]    ◆Comment:Reached 0 (recovered)?[/INDENT]
[INDENT]    ◆If:Hit Recovery Steps = 0[/INDENT]
[INDENT]      ◆Comment:-1 to hit count! (+ balloon for visible feedback)[/INDENT]
[INDENT]      ◆Control Variables:#0007 Count -= 1[/INDENT]
[INDENT]      ◆Show Balloon Icon:Player, Music Note[/INDENT]
[INDENT]      ◆Comment:Change speed to match new hit count~[/INDENT]
[INDENT]      ◆If:Count = 0[/INDENT]
[INDENT]        ◆Set Movement Route:Player (Wait)[/INDENT]
[INDENT]        :                  :◇Speed:4[/INDENT]
[INDENT]        ◆[/INDENT]
[INDENT]      :Else[/INDENT]
[INDENT]        ◆If:Count = 1[/INDENT]
[INDENT]          ◆Set Movement Route:Player (Wait)[/INDENT]
[INDENT]          :                  :◇Speed:3[/INDENT]
[INDENT]          ◆[/INDENT]
[INDENT]        :Else[/INDENT]
[INDENT]          ◆Set Movement Route:Player (Wait)[/INDENT]
[INDENT]          :                  :◇Speed:2[/INDENT]
[INDENT]          ◆[/INDENT]
[INDENT]        :End[/INDENT]
[INDENT]        ◆[/INDENT]
[INDENT]      :End[/INDENT]
[INDENT]      ◆Comment:Count is still more than 0?[/INDENT]
[INDENT]      ◆If:Count > 0[/INDENT]
[INDENT]        ◆Comment:Reset hit recovery step counter![/INDENT]
[INDENT]        ◆Control Variables:#0014 Hit Recovery Steps = 30[/INDENT]
[INDENT]        ◆[/INDENT]
[INDENT]      :End[/INDENT]
[INDENT]      ◆[/INDENT]
[INDENT]    :End[/INDENT]
[INDENT]    ◆[/INDENT]
[INDENT]  :End[/INDENT]
[INDENT]  ◆Comment:--------------------------------------------[/INDENT]
[INDENT]  ◆Comment:Can check other "on step" stuff here, too~[/INDENT]
[INDENT]  ◆[/INDENT]
[INDENT]:End[/INDENT]
[INDENT]◆Comment:Store current step count for next check![/INDENT]
[INDENT]◆Control Variables:#0015 Step Count = Steps[/INDENT]
[INDENT]◆Comment:Check again in 6 frames (10 times per second)[/INDENT]
[INDENT]◆Wait:6 frames
Obviously you can replace the values as you like. Hope that made some sense! 🙏

If this seems like a lot of trouble to go to for "do stuff on step", there are plugins that let you cut corners here. E.g. I have a plugin called Cae_StepSwitch that lets you automatically turn on a switch every step. You can bind this switch to a Parallel event, then make the event switch itself off at the end.

Lastly: states are typically for "per person" stuff, but this sounds like a "per party" idea, right? You could use states, but things might get awkward if, for example, the player can change the party leader or swap members in/out. That's why I suggested variables~ 👋


Many thanks for your reply,

I will test and see what the best solution is for this matter.

Happy new year
Happy new year! 😂

Original thread: https://forums.rpgmakerweb.com/threads/assistance-with-making-a-state-reduce-your-on-map-movement-speed.131566/