How Can I Detect If Player Is Running?

Rodak

Dang Hippy
Veteran
Joined
Dec 28, 2015
Messages
136
Reaction score
82
First Language
Math
Primarily Uses
RMMZ
It's another crazy hippy problem. I have an event I want to activate when the player runs ("dashes") into it. Not walks into it or be standing adjacent to it and turning into it, but actually running.

This could be used for breaking down doors or other things for which they'd need momentum, but I can't find any way to check for this.

Here's hoping I'm just missing something obvious, but I think I may need a script or something for this (I will be up to learning scripting for this game one day, but it is not this day!).

Thanks for any advice anyone may have.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,544
Reaction score
14,854
First Language
English
Primarily Uses
RMMV
Well, the script call to see if the player is running is $gamePlayer.isDashing() but I think at the time the event activates, the player will have stopped moving/dashing so that will likely return false.

Give it a go, and if it doesn't work, you might have to try something like this -

Common event, set to parallel process:
Code:
If Shift Button is pressed (not sure Shift IS available, or if pressed is what you're after - you want "held down")
  Control Switches: Player is Running = ON
Else
  Control Switches: Player is Running = OFF
End

then have the event check the switch. I'm not even sure if that will work.
 

Rodak

Dang Hippy
Veteran
Joined
Dec 28, 2015
Messages
136
Reaction score
82
First Language
Math
Primarily Uses
RMMZ
I thought it may be dependent on a button check, but being old and impatient I set my personal game preferences to "always dash" in the options at game start. If anyone else is as crazy as me, that would slip by the check.

The isDashing() will probably work if it's placed on the tile before the event (since, as you pointed out, they will no longer be dashing when they hit the event). Probably need a direction check too if there are adjacent passable tiles.

I'll pound my head against it a bit a see if I can crack something...
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,544
Reaction score
14,854
First Language
English
Primarily Uses
RMMV
Well, if you don't mind a small delay, then you could try this:

Code:
If Script: $gamePlayer.isDashing()
  Control Switches: Player Dashing = ON
Else
  Wait 60 frames
  Control Switches: Player Dashing = OFF
End

So if the player is dashing (which should be via a button press or 'always dash'), the switch will be turned on immediately. But when the player stops dashing, it will wait a second before turning the switch off. That also means if the player is dashing, then releases the button but presses it again a fraction of a second later, it won't check again until the 1 second wait is up (but then it should still be immediately - 1 frame - after it's turned off, so I doubt anything will slip through).

Did you actually try to do the $gamePlayer.isDashing() test on the event? Turn off your 'always dashing' option and test it, because it's the button press we're interested in. It might just work.
 

Artille

Veteran
Veteran
Joined
Jul 23, 2012
Messages
49
Reaction score
34
First Language
French
Primarily Uses
RMMZ
Code:
If Shift Button is pressed (not sure Shift IS available, or if pressed is what you're after - you want "held down")
  Control Switches: Player is Running = ON
Else
  Control Switches: Player is Running = OFF
End
Shift is default for dashing, it is availble in the conditionnal branch. :)

Solution works, but the flaw would be if the player knows about that, he can simply hold shift while activating said event.

I did some eventing tests and this would work best I think :

Code:
◆Loop
  ◆Control variables:#0018 Player Pos X = Map X Player
  ◆Control variables:#0019 Player Pos Y = Map Y Player
  ◆If:Button [Shift] is pressed
    ◆If:Player Pos X ≠ Previous Pos X
      ◆Control switches:#0009 PlayerRunning = ON
      ◆
    :Else
      ◆If:Player Pos Y ≠ Previous Pos Y
        ◆Control switches:#0009 PlayerRunning = ON
        ◆
      :Else
        ◆Control switches:#0009 PlayerRunning = OFF
        ◆Break Loop
        ◆
      :End
      ◆
    :End
    ◆
  :Else
    ◆Control switches:#0009 PlayerRunning = OFF
    ◆Break Loop
    ◆
  :End
  ◆Wait:1 trame
  ◆
:Repeat Loop
◆Control variables:#0009 Previous Pos X = Map X Player
◆Control variables:#0010 Previous Pos Y = Map Y Player

Then you only need to make a conditionnal branch "If PlayerRunning = ON" => whatever you want to happen.

This will prevent a player to stand next to your event and simply hold shift, he will need to move also.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,501
Reaction score
727
First Language
indonesian
I thought it may be dependent on a button check, but being old and impatient I set my personal game preferences to "always dash" in the options at game start. If anyone else is as crazy as me, that would slip by the check.

The isDashing() will probably work if it's placed on the tile before the event (since, as you pointed out, they will no longer be dashing when they hit the event). Probably need a direction check too if there are adjacent passable tiles.

I'll pound my head against it a bit a see if I can crack something...
hmmm how about storing $gamePlayer.realMoveSpeed() to a variable in tile before the 'door'...

then check that variable in the 'door' event... by default walking speed is (4) and running is (4+1)... unless you use plugin or event command to change that speed...

when you dash... and enter the 'tile' next to the 'door'... it will save the dashing speed (5) to the variable... then when you trigger the event... you can check the variable... if it's 5 then break the door... else do something else...

and in another scenario where player dashing till that tile (variable save 5 as value at that time) and then suddenly return back one tile (not ramming the door)... and then back again without dashing... the variable will save 4 as value and when you trigger the door it won't break...

edit: in the 'door' event you can use conditional branch -> script:
Code:
$gameVariables.value(7) > $gamePlayer.moveSpeed()
change 7 to your variable id...
so even if you use plugin to change your default move speed it should work...
don't forgot to 'erase' that variable value at the end of 'door' event.

something like this:
door event:

'dashing check' event (place next to the door event)


there's a little downside though... if the door is at the top... and you dashing from the left / right... then at the 'check tile' turn up... then you break the door... maybe need to modify it to also check direction before storing the variable...

hope this help...[/code]
 
Last edited:

Rodak

Dang Hippy
Veteran
Joined
Dec 28, 2015
Messages
136
Reaction score
82
First Language
Math
Primarily Uses
RMMZ
Well, if you don't mind a small delay, then you could try this:

Code:
If Script: $gamePlayer.isDashing()
  Control Switches: Player Dashing = ON
Else
  Wait 60 frames
  Control Switches: Player Dashing = OFF
End

So if the player is dashing (which should be via a button press or 'always dash'), the switch will be turned on immediately. But when the player stops dashing, it will wait a second before turning the switch off. That also means if the player is dashing, then releases the button but presses it again a fraction of a second later, it won't check again until the 1 second wait is up (but then it should still be immediately - 1 frame - after it's turned off, so I doubt anything will slip through).

Did you actually try to do the $gamePlayer.isDashing() test on the event? Turn off your 'always dashing' option and test it, because it's the button press we're interested in. It might just work.

Thanks again!

I was trying the $gamePlayer.isDashing() bit and working on the proper syntax (I learned programming a long time ago and then took decades off - I have the logic skills, but the code structure is alien to me).

And, being dyslexic, I was actually testing it upside down by leaving my always dash on and pressing shift so I walked into it.

Shift is default for dashing, it is availble in the conditionnal branch. :)

Solution works, but the flaw would be if the player knows about that, he can simply hold shift while activating said event.

I did some eventing tests and this would work best I think :

Code:
◆Loop
  ◆Control variables:#0018 Player Pos X = Map X Player
  ◆Control variables:#0019 Player Pos Y = Map Y Player
  ◆If:Button [Shift] is pressed
    ◆If:Player Pos X ≠ Previous Pos X
      ◆Control switches:#0009 PlayerRunning = ON
      ◆
    :Else
      ◆If:Player Pos Y ≠ Previous Pos Y
        ◆Control switches:#0009 PlayerRunning = ON
        ◆
      :Else
        ◆Control switches:#0009 PlayerRunning = OFF
        ◆Break Loop
        ◆
      :End
      ◆
    :End
    ◆
  :Else
    ◆Control switches:#0009 PlayerRunning = OFF
    ◆Break Loop
    ◆
  :End
  ◆Wait:1 trame
  ◆
:Repeat Loop
◆Control variables:#0009 Previous Pos X = Map X Player
◆Control variables:#0010 Previous Pos Y = Map Y Player

Then you only need to make a conditionnal branch "If PlayerRunning = ON" => whatever you want to happen.

This will prevent a player to stand next to your event and simply hold shift, he will need to move also.

Great thinking! But the shift button doesn't always work here since silly people like me set their "options" on the title screen to "always dash" - that means I have to hold shift if I don't want to dash!

This gets trickier and trickier...


EDIT:


hmmm how about storing $gamePlayer.realMoveSpeed() to a variable in tile before the 'door'...

then check that variable in the 'door' event... by default walking speed is (4) and running is (4+1)... unless you use plugin or event command to change that speed...

when you dash... and enter the 'tile' next to the 'door'... it will save the dashing speed (5) to the variable... then when you trigger the event... you can check the variable... if it's 5 then break the door... else do something else...

and in another scenario where player dashing till that tile (variable save 5 as value at that time) and then suddenly return back one tile (not ramming the door)... and then back again without dashing... the variable will save 4 as value and when you trigger the door it won't break...

hope this help...


Sorry, @estriole ! You posted while I was typing and missed any alert it may have sent.

That's only missing the direction check (dash past the door running along the wall would foul it) but otherwise is a good alternative! Will try all of these suggestions and test them, trying to trick them, and report back what, if any, works best!

Thanks all for the help.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,481
Reaction score
1,870
First Language
EN
Primarily Uses
RMMZ
Use Conditional Branch > Script:
JavaScript:
$gamePlayer.isDashing()
This is OK because, by default, the dashing flag only updates between moves.
 

Artille

Veteran
Veteran
Joined
Jul 23, 2012
Messages
49
Reaction score
34
First Language
French
Primarily Uses
RMMZ
Great thinking! But the shift button doesn't always work here since silly people like me set their "options" on the title screen to "always dash" - that means I have to hold shift if I don't want to dash!

This gets trickier and trickier...


Well, that means if you don't hold Shift you are dashing.
Which is the same as my example, but simply the opposite. :D

Simply reverse the conditions. :D

Code:
◆Loop
  ◆Control variables:#0018 Player Pos X = Map X Player
  ◆Control variables:#0019 Player Pos Y = Map Y Player
  ◆If:Button [Shift] is pressed
    ◆Control switches:#0009 PlayerRunning = OFF
    ◆Break Loop
    ◆
  :Else
    ◆If:Player Pos X ≠ Previous Pos X
      ◆Control switches:#0009 PlayerRunning = ON
      ◆
    :Else
      ◆If:Player Pos Y ≠ Previous Pos Y
        ◆Control switches:#0009 PlayerRunning = ON
        ◆
      :Else
        ◆Control switches:#0009 PlayerRunning = OFF
        ◆Break Loop
        ◆
      :End
      ◆
    :End
    ◆
  :End
  ◆Wait:1 trame
  ◆
:Repeat Loop
◆Control variables:#0009 Previous Pos X = Map X Player
◆Control variables:#0010 Previous Pos Y = Map Y Player

Same result, only this time if you hold shift, you are not dashing anymore. :D

Edit : Oops, you meant you "as player".
My bad :kaoswt2:

Double edit, with the script instead of the shift button, it covers all options. :)
So you get something like this :

Code:
◆Loop
  ◆Control variables:#0018 Player Pos X = Map X Player
  ◆Control variables:#0019 Player Pos Y = Map Y Player
  ◆If:Script : $gamePlayer.isDashing()
    ◆If:Player Pos X ≠ Previous Pos X
      ◆Control switches:#0009 PlayerRunning = ON
      ◆
    :Else
      ◆If:Player Pos Y ≠ Previous Pos Y
        ◆Control switches:#0009 PlayerRunning = ON
        ◆
      :Else
        ◆Control switches:#0009 PlayerRunning = OFF
        ◆Break Loop
        ◆
      :End
      ◆
    :End
    ◆
  :Else
    ◆Control switches:#0009 PlayerRunning = OFF
    ◆Break Loop
    ◆
  :End
  ◆Wait:1 trame
  ◆
:Repeat Loop
◆Control variables:#0009 Previous Pos X = Map X Player
◆Control variables:#0010 Previous Pos Y = Map Y Player

This way, however you're option is set (auto or not) the event will work the same.
If you don't autorun, you need to hold shift to activate the switch,
If you autorun, you need to have nothing pressed to activate the switch.
 
Last edited:

Rodak

Dang Hippy
Veteran
Joined
Dec 28, 2015
Messages
136
Reaction score
82
First Language
Math
Primarily Uses
RMMZ
Use Conditional Branch > Script:
JavaScript:
$gamePlayer.isDashing()
This is OK because, by default, the dashing flag only updates between moves.

Yup.

That was all it needed.

In my inexperience with scripting I kept trying to add a "true" in the parenthesis o_O

May as well attach a screen shot of a working event and call this one solved.

Thanks everyone that replied!


EDIT:

@caethyril - again, I missed a post while replying!

Thanks so much for the effort. I appreciate it.

I posted a simple event that does the job with a single script thingy that doesn't care about button presses or how the game options are set with regard to dashing.

I need to study this scripting stuff more!

Thanks again everyone that helped.
 

Attachments

  • mzzzzzz.png
    mzzzzzz.png
    30.8 KB · Views: 4

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,501
Reaction score
727
First Language
indonesian
Yup.

That was all it needed.

In my inexperience with scripting I kept trying to add a "true" in the parenthesis o_O

May as well attach a screen shot of a working event and call this one solved.

Thanks everyone that replied!
there's a little catch though... if you 'dash' from left / right... and then do sudden turn up on the door... it will trigger and break the door :D...
 

Rodak

Dang Hippy
Veteran
Joined
Dec 28, 2015
Messages
136
Reaction score
82
First Language
Math
Primarily Uses
RMMZ
there's a little catch though... if you 'dash' from left / right... and then do sudden turn up on the door... it will trigger :D...

Dang you, @estriole !

Dang you to heck!!

I guess we can just allow the 90 degree turn given that the main player character is a cow, the added weight over a human is enough to break the door with the momentum loss.

Either that or just put plants or something on either side of the door...
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,501
Reaction score
727
First Language
indonesian
Dang you, @estriole !

Dang you to heck!!

I guess we can just allow the 90 degree turn given that the main player character is a cow, the added weight over a human is enough to break the door with the momentum loss.

Either that or just put plants or something on either side of the door...
:D :D :D
yes i advice you to block left and right path :D :D :D
 

Latest Threads

Latest Posts

Latest Profile Posts

Theydies and gentlethems, presenting Touch the Stars character #1: Anna Smith and her transformed form, Sagittaria!1624568259771.png
Anyone seen Dsiver around?
I wish character bust packs had options for both side-facing and front-facing for the same characters.
Looks like I'm going to have to cancel another game.
For now it is in testing phase: Changing the game icon from Rm2k/2k3 without needing to edit the executable.
Rm2k-DinChangeIcon.png

Forum statistics

Threads
112,529
Messages
1,068,985
Members
146,216
Latest member
WTCraft2003
Top