How do I...remove a slowness effect after a certain amount of time?

Joined
Jul 12, 2020
Messages
164
Reaction score
29
First Language
English
Primarily Uses
RMMV
I want to make a state that can slow the player down (I have SRD_MapSlipDamage plugin) for 7 seconds on the overworld map.

I have it setup this way:


Screen Shot 2021-05-14 at 9.48.16 PM.png
Screen Shot 2021-05-14 at 9.48.21 PM.png


The problem is...I can't seem to find a way to make the slowness get "auto-removed" after 7 seconds. I've tried experimenting with "Wait" and Variables, but...I can't seem to figure it out.

Perhaps there is another way to do this? Am I approaching a dead end?
 

DRG

Orange juice lover, Sunny D Hater.
Veteran
Joined
Apr 23, 2018
Messages
110
Reaction score
45
First Language
english
Primarily Uses
RMMV
the best thing I can think of is this.

1. In the "Helm's slowness" common event after setting the player movement speed, create a new switch, and use a control switch command to set it to "ON"

2. create another common event. This common event would have trigger set to "Parallel" and Switches set to the switch you created in the previous common event.

3. add a "wait" event command to this new common event that lasts 420 frames (7 seconds). After the wait command, use a "change states" command under the actor section, to remove the slowness state, and after that, use the set movement command to set the player's movement speed back to normal. Then finally, use another control switches command to set the previous switch to "Off".
 

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
588
Reaction score
160
First Language
Engilsh
Primarily Uses
RMMV
There are probably "easier" ways to do it with eventing, but I like to use code when I can to improve my own logic flows,

First I create the slow event called by the state, In the event I use a javascript "timer" that calls my second common event after 7 seconds,

1621050395279.png

in the second event that is being called after 7 seconds, I clear the timer and set the movement speed back to normal,

1621050493884.png

That's pretty much how I would do it, I'm not 100% sure this works as I don't feel like testing this in my own project but hey, I just wanted to give options
 
Joined
Jul 12, 2020
Messages
164
Reaction score
29
First Language
English
Primarily Uses
RMMV
There are probably "easier" ways to do it with eventing, but I like to use code when I can to improve my own logic flows,

First I create the slow event called by the state, In the event I use a javascript "timer" that calls my second common event after 7 seconds,

View attachment 189344

in the second event that is being called after 7 seconds, I clear the timer and set the movement speed back to normal,

View attachment 189346

That's pretty much how I would do it, I'm not 100% sure this works as I don't feel like testing this in my own project but hey, I just wanted to give options

Ahh, yeah...I tried your script suggestion first since it sounded a bit easier. It isn't doing anything :/
I made sure to "remove" the state in the 2nd event call too.

I will try the other suggestion
 
Joined
Jul 12, 2020
Messages
164
Reaction score
29
First Language
English
Primarily Uses
RMMV
the best thing I can think of is this.

1. In the "Helm's slowness" common event after setting the player movement speed, create a new switch, and use a control switch command to set it to "ON"

2. create another common event. This common event would have trigger set to "Parallel" and Switches set to the switch you created in the previous common event.

3. add a "wait" event command to this new common event that lasts 420 frames (7 seconds). After the wait command, use a "change states" command under the actor section, to remove the slowness state, and after that, use the set movement command to set the player's movement speed back to normal. Then finally, use another control switches command to set the previous switch to "Off".
Hey, this worked like a charm dude! Thank you : )
 

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
588
Reaction score
160
First Language
Engilsh
Primarily Uses
RMMV
Ahh, yeah...I tried your script suggestion first since it sounded a bit easier. It isn't doing anything :/
I made sure to "remove" the state in the 2nd event call too.

I will try the other suggestion
That's strange, I just tried it and it worked for me, ah well, glad you found a method that worked for you
 

frogs_r_cool

Villager
Member
Joined
May 11, 2021
Messages
16
Reaction score
8
First Language
English
Primarily Uses
RMMZ
@Capitán - you want setTimeout() here, not setInterval().

Realize you've moved on having found a good solution, but for anyone else that may need this:

This should be accomplished in a single script.
----
$gamePlayer.setMoveSpeed(2);
setTimeout(() => { $gamePlayer.setMoveSpeed(4)}, 7000);
---

For a more robust approach, start by getting the current speed in case your player's speed is modified by items or something.

----
const normalSpeed = $gamePlayer._moveSpeed;
$gamePlayer.setMoveSpeed(2);
setTimeout(() => { $gamePlayer.setMoveSpeed(normalSpeed)}, 7000);
---
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,473
Reaction score
1,865
First Language
EN
Primarily Uses
RMMZ
Notes (assuming no plugins):
  1. I strongly recommend sticking with the existing engine structure where possible!

    setTimeout will fire regardless of scene, which may cause your event to be reserved in the menu or something. Neither the timeout period nor the reserved event are included in save data; also, reserved common events do not run except on the map and battle scenes. The timeout will not be reset on the usual triggers, either (e.g. new game). Lots of opportunities for unintended behaviour! :kaoswt2:

  2. Using Set Movement Route to reset the player speed may interfere with any cutscenes etc where you give the player a move route (only one route can be active at a time). To avoid that, you can use a Script command to reset the player's speed instead, e.g.
    JavaScript:
    $gamePlayer.setMoveSpeed(4);
    It's probably safe to use a move route to apply the slow speed, unless that is also done via a Parallel event.

  3. Parallel events reset when the player changes map (that includes common events). E.g. if you have a common Parallel event like this:
    Code:
    ◆Comment:Wait 60 seconds (900 frames = 15 seconds)
    ◆Wait:900 frames
    ◆Wait:900 frames
    ◆Wait:900 frames
    ◆Wait:900 frames
    ◆Comment:Say hello!
    ◆Text:None, Window, Bottom
    :    :Hi!
    ...then it will only ever show the message if the player spends 60 seconds on the same map. It is generally better to use a variable or something that counts down in shorter intervals, e.g.
    Apply the slow effect
    Code:
    ◆Comment:Set player to slow speed
    ◆Set Movement Route:Player (Wait)
    :                  :◇Speed:3
    ◆Comment:10 seconds of slowness
    ◆Control Variables:#0020 Slow Counter = 100
    ◆Comment:Start parallel event to remove effect
    ◆Control Switches:#0001 Slowed = ON

    Delayed effect removal (Trigger: Parallel, Condition: Switch 1 is ON)
    Code:
    ◆Comment:Has counter reached 0 yet?
    ◆If:Slow Counter ≤ 0
      ◆Comment:Reset player speed
      :       :(Script call so it won't interfere with active move routes.)
      ◆Script:$gamePlayer.setMoveSpeed(4);
      ◆Comment:Turn off this event's switch (ends event)
      ◆Control Switches:#0001 Slowed = OFF
      ◆
    :Else
      ◆Comment:Reduce counter by 1
      ◆Control Variables:#0020 Slow Counter -= 1
      ◆Comment:Check again in 6 frames
      :       :(-1 to variable every 0.1 seconds)
      ◆Wait:6 frames
      ◆
    :End
    :kaohi:
 
Joined
Jul 12, 2020
Messages
164
Reaction score
29
First Language
English
Primarily Uses
RMMV
Notes (assuming no plugins):
  1. I strongly recommend sticking with the existing engine structure where possible!

    setTimeout will fire regardless of scene, which may cause your event to be reserved in the menu or something. Neither the timeout period nor the reserved event are included in save data; also, reserved common events do not run except on the map and battle scenes. The timeout will not be reset on the usual triggers, either (e.g. new game). Lots of opportunities for unintended behaviour! :kaoswt2:

  2. Using Set Movement Route to reset the player speed may interfere with any cutscenes etc where you give the player a move route (only one route can be active at a time). To avoid that, you can use a Script command to reset the player's speed instead, e.g.
    JavaScript:
    $gamePlayer.setMoveSpeed(4);
    It's probably safe to use a move route to apply the slow speed, unless that is also done via a Parallel event.

  3. Parallel events reset when the player changes map (that includes common events). E.g. if you have a common Parallel event like this:
    Code:
    ◆Comment:Wait 60 seconds (900 frames = 15 seconds)
    ◆Wait:900 frames
    ◆Wait:900 frames
    ◆Wait:900 frames
    ◆Wait:900 frames
    ◆Comment:Say hello!
    ◆Text:None, Window, Bottom
    :    :Hi!
    ...then it will only ever show the message if the player spends 60 seconds on the same map. It is generally better to use a variable or something that counts down in shorter intervals, e.g.
    Apply the slow effect
    Code:
    ◆Comment:Set player to slow speed
    ◆Set Movement Route:Player (Wait)
    :                  :◇Speed:3
    ◆Comment:10 seconds of slowness
    ◆Control Variables:#0020 Slow Counter = 100
    ◆Comment:Start parallel event to remove effect
    ◆Control Switches:#0001 Slowed = ON

    Delayed effect removal (Trigger: Parallel, Condition: Switch 1 is ON)
    Code:
    ◆Comment:Has counter reached 0 yet?
    ◆If:Slow Counter ≤ 0
      ◆Comment:Reset player speed
      :       :(Script call so it won't interfere with active move routes.)
      ◆Script:$gamePlayer.setMoveSpeed(4);
      ◆Comment:Turn off this event's switch (ends event)
      ◆Control Switches:#0001 Slowed = OFF
      ◆
    :Else
      ◆Comment:Reduce counter by 1
      ◆Control Variables:#0020 Slow Counter -= 1
      ◆Comment:Check again in 6 frames
      :       :(-1 to variable every 0.1 seconds)
      ◆Wait:6 frames
      ◆
    :End
    :kaohi:

Now that's a lot of stuff to take in!
So what I ended up doing was the Switch with the Common evens in the very first suggestion. It works just fine!

As an explanation, the Set Movement Route option is best (or, at least I think) because the Slowness effect is only going to be on certain traps/dungeon maps. I don't think it's going to interfere with cutscenes or anything. And even if it does happen to be close, I could easily just remove the states and set a movement route speed upon triggering the cutscene. It's not too bad I think.
 

frogs_r_cool

Villager
Member
Joined
May 11, 2021
Messages
16
Reaction score
8
First Language
English
Primarily Uses
RMMZ
Good thoughts from @caethyril, you generally should stick to prescribed solutions. Regarding my setTimeout script, I didn't include any sort of usage of events--you simply change the values directly. If you didn't want your speed to return to normal in a particular scene (I think usually you would), you could simply check you're in an appropriate scene within the callback. Though, your speed will need to normalize at some point, so you would need to save the remaining duration and apply another timer for that period. All of this functionality should probably be implemented as a plugin (I'm assuming there already is one that does something like this)
 
Last edited:

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
588
Reaction score
160
First Language
Engilsh
Primarily Uses
RMMV
you want setTimeout() here, not setInterval().
Yes setTimeout() would be better for one off, in this case, but I wanted to use setInterval() just in case, as it offered a bit more flexibility with the state by making it simpler to extend the duration/refresh the state by just not clearing the interval. But yes for this usage case setTimeout() would be the best way to go.
 

Latest Threads

Latest Posts

Latest Profile Posts

Man, this quick One Map game is causing unprecedented amounts of trouble.
I always end up having issues with things i'd never expect.

Capture.PNG

Those friggin mountains man xD
Time for my daily walk/jog ''Literally starts raining while I open the door''
I just discovered there's a giant jellyfish in the Ace RTP. My day is made.

Forum statistics

Threads
112,401
Messages
1,068,057
Members
146,053
Latest member
komradiv
Top