Jump to content

Reset function ModPCMovementSpeed if applied for no reason


Recommended Posts

Hello,

I am trying to make a sprint key by using the ModPCMovementSpeed function, and would like to figure out a way to reset that modifier in case it is applied for a reason or another when the key is not pressed. This is the reset block I made using GetPCMovementSpeedModifier function :

; Reset the Speed Modifier if applied for no reason
   
if KeyPress == 0 && Check == 0 && GetPCMovementSpeedModifier == 60 ; if sprint key is not pressed, but sprint bonus of 60 is somehow applied
   ModPCMovementSpeed -60
   Message "Speed Modifier Reset"
endif

Is this going to work ?

Link to comment
Share on other sites

Try changing "&& GetPCMovementSpeedModifier == 60" to "&& GetPCMovementSpeedModifier != 0"

Maybe, for some reason the modifier (being a float) is not exactly 60.

Edit#1:

Next I would try this:

float SpeedMod

; Reset the Speed Modifier if applied for no reason
   
set SpeedMod to GetPCMovementSpeedModifier 
PrintC "SpeedMod = %f  Keypress = %g  Check = %g", SpeedMod, KeyPress, Check  ; NOTE this may flood the console depending on how often it's hit
if KeyPress == 0 && Check == 0 && SpeedMod != 0 ; if sprint key is not pressed, but sprint bonus of 60 is somehow applied
   set SpeedMod to SpeedMod * -1.0
   ModPCMovementSpeed SpeedMod
   Message "Speed Modifier Reset"
endif
Edited by GamerRick
because
Link to comment
Share on other sites

Instead of assigning extra key it would be better to apply speed when we want player to move and he is already in run mode?

short speedMod

...
if IsControlDisabled 0 == 0 ;0 - forward control available
	if IsControlPressed 0 != 0 && player.IsRunning != 0
  		if speedMod == 0
			ModPCMovementSpeed 60
			set speedMod to 1
  		endif
	elseif speedMod != 0
		ModPCMovementSpeed -60
		set speedMod to 0
	endif
else ;if not
	if speedMod != 0 ;return speed if mod applied
		ModPCMovementSpeed -60
		set speedMod to 0
	endif
endif
...	

 Also don't forget that function variables get reseted after every run, so the ones you need to remember must be saved elsewhere, like in quest or global variables.

Edited by RomanR
typos and bugfix
Link to comment
Share on other sites

I'm sorry, but I noticed a bug in my script post. I forgot to add a check if speedMod variable is at zero when adding speed, without it speed would add always when holding a forward control key. See this post again please.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...