Jump to content

Prevent the player from running


lofgren

Recommended Posts

I've been trying to search Google for this, but the results are too cluttered with other definitions of "run" and with players trying to solve bugs.

 

Has anybody found a nice clean method for preventing the player from running? Specifically I want them to be unable to run when under the effects of a particular spell. So far the only method I have found is encumbering them, which also slows their walking speed. Any help would be appreciated.

 

Thanks.

Link to comment
Share on other sites

You could do what my Controller Walk Run Toggle mod does. Change the player's speed multiplier value. When done as a magic effect, it might show up in the magic window under status effects (not sure - would need to be tested).

 

25 to 35 is a good range for walking when adjusting the speedmult value. But given that other mods could change the value, it might be best to get the starting value and subtract the target value and then Mod the remainder away while storing it to add back when the effect ends.

Link to comment
Share on other sites

As the speed rate is reduced the animation matches the rate of movement. Eventually, "run" (i.e. full press of the controller stick) visually becomes "walk". The only real concern with this approach is sprint. The sprint animation does not get affected but the speed rate for sprint does. So... the player could try to sprint and end up with a fast sprint animation while moving a disproportionate amount of distance (i.e. almost running in place). The only way to prevent sprint is to use the encumbered approach.

 

If by run you meant sprint, changing the carry weight and / or inventory weight is the only viable approach.

If by run you meant default full forward speed, changing the speed multiplier may be a viable approach depending upon usage.

Link to comment
Share on other sites

Afaik player is able to run until his stamina is gone. By using this approach you could attach a script to your spell effect and use next script. Maybe it works for you.

 

lofgPlayerNotRunningEffectScript

 

Scriptname lofgPlayerNotRunningEffectScript extend ActiveMagicEffect
; https://forums.nexusmods.com/index.php?/topic/9708733-prevent-the-player-from-running/

  Bool bSpellActive     ; [default=False]


; -- EVENTs --

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
IF (akTarget == Game.GetPlayer())            ; just a safety condition
    bSpellActive = TRUE
    RegisterForSingleUpdate(1.0)                         ; first time for calling OnUpdate() event
ENDIF
ENDEVENT


EVENT OnEffectFinish(Actor akTarget, Actor akCaster)
    bSpellActive = False
ENDEVENT


EVENT OnUpdate()
    actor player = Game.GetPlayer()                      ; get it once here

; https://www.creationkit.com/index.php?title=GetActorValue_-_Actor
    float f0 = player.GetActorValue("Stamina")           ; obtains players current stamina, before changing
    float f  = f0

    bool bOK = player.IsRunning()                        ; set our break condition
    WHILE (bOK)
        f = f * 0.5                                      ; reduce by 50 percent, 0.75 -> reducing by 25%, 0.25 -> reducing by 75%
        player.DamageActorValue("Stamina", f)            ; reduce players stamina

        Utility.Wait(1.0)
        
        IF ( bSpellActive )                 ; spell effect is still running
            bOK = player.IsRunning()
        ELSE                                ; spell effect has been finished by time
            bOK = False
        ENDIF
    ENDWHILE

; https://www.creationkit.com/index.php?title=RestoreActorValue_-_Actor
    f = player.GetActorValue("Stamina")                  ; obtains players current stamina, after reduction
    IF (f < f0)
        player.RestoreActorValue("Stamina", f0 - f)      ; restore players stamina
    ENDIF
    
    IF ( bSpellActive )
        RegisterForSingleUpdate(1.0)                     ; register again for this event
    ENDIF
ENDEVENT

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

@lofgren

Use IsSprinting() in place of IsRunning() in ReDragon2013's code and you'll be set for trying to prevent the player from sprinting. IsRunning() does not return whether the player is sprinting or not and it is sprinting that is governed by stamina. Running as far at the game is concerned is the normal forward movement.

 

Probably best to get a definition of what you mean by "run" as I fear there has been some confusion.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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