Jump to content

[LE] OnUpdateGameTime Not being called


Recommended Posts

Hello fellow modders. I'm trying to get a custom enchantment working for a skyrim mod, but the papyrus script on the magic effect does not want to cooperate. I registered for UpdateGameTime(), made sure it was being called by using Debug.Trace in the same place that RegisterForUpdateGameTime(0.5) (for every half second, right?) is being called, and have not called wait() anywhere, so I don't know why OnUpdateGameTime is being called.

 

The boots that the enchantment is attached to have the enchantment and magic effect applied properly, so I'm confident that's not the issue. The papyrus logs also write "yo" and TRUE, amidst other chaos, but nothing that appears in OnUpdateGameTime. If you can offer any insight as to what the issue may be, I would greatly appreciate it!

 

Here's the full script:

Scriptname flightSpeedEnchant extends activemagiceffect  
{This will make a magic effect increase speed based on missing health.}

import debug

Float Property maxSpeed = 1000.0 Auto
Actor target

Event OnEffectStart(Actor akTarget, Actor akCaster)
	; Target Actor
	target = GetTargetActor()
	self.RegisterForUpdateGameTime(0.5)
	Debug.Trace("yo")
	Debug.Trace(target == Game.GetPlayer())
endEvent

Event OnUpdateGameTime()

	Debug.Trace("HI THERE FUTURE ME!")
	Float percentage = 1 - (target.GetActorValuePercentage("Health"))
	Float baseSpeed = target.GetActorValue("SpeedMult")
	; adjustedSpeed = interpolate with percentage and magnitude
	Float adjustedSpeed = baseSpeed + (percentage * (maxSpeed - baseSpeed))
	target.SetActorValue("SpeedMult", adjustedSpeed)
	Debug.Trace("percentage is: " + percentage )
	Debug.Trace("baseSpeed is: " + baseSpeed)
	Debug.Trace("adjustedSpeed is: " + adjustedSpeed )
	Debug.Trace("target is: " + target)
	Debug.Trace("maxSpeed is: " + maxSpeed )

endEvent

	; Player's current health value
	; Float currentHP = target.GetActorValue("Health")
	; Player's max health
	; Float maxHP = target.GetAVMax("Health")
	; Float percentage = 1 - (currentHP / maxHP)
Link to comment
Share on other sites

GameTime updates are in game hours, not seconds, so you might just not be waiting long enough. If you want an update every half second of actual time, you probably want to use just normal updates instead.

 

Also, be aware that it is considerably better practice to register for a single update (of either sort), and then in the OnUpdate block, register for the next one. It avoids orphaning the registration if something unexpected happens.

Edited by foamyesque
Link to comment
Share on other sites

I believe foamyesque gave you the right answer already.

 

flightSpeedEnchantScript

 

Scriptname flightSpeedEnchantScript extends activemagiceffect  
{This will make a magic effect increase speed based on missing health.}

; https://forums.nexusmods.com/index.php?/topic/7539816-onupdategametime-not-being-called/

  Float PROPERTY fmaxSpeed = 1000.0 auto


; -- EVENTs --
; https://www.creationkit.com/index.php?title=Category:Scripting

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
IF (akTarget == Game.GetPlayer())
ELSE
    self.Dispel()
    RETURN    ; - STOP -    player is not the target
ENDIF
;---------------------
    gotoState("Waiting")            ; ### STATE ###
    RegisterForSingleUpdate(1.0)                                        ; first time registration
    Debug.Trace(" OnEffectStart() - target is the player.. yo  " +self)
ENDEVENT


EVENT OnEffectFinish(Actor akTarget, Actor akCaster)
    Debug.Trace(" OnEffectFinish() - has been reached..  " +self)
ENDEVENT


;==========================
state Waiting
;============
EVENT OnUpdate()
    Debug.Trace("HI THERE FUTURE ME with " +fMaxSpeed)

    actor aRef = self.GetTargetActor()
IF ( aRef )
    Debug.Trace("target is: " + aRef)
ELSE
    RETURN    ; - STOP -    target is gone or mod has been removed
ENDIF
;---------------------
    float f = 1.0 - aRef.GetActorValuePercentage("Health")
    Debug.Trace("health percentage left is: " + f)

    float fSpeedMulti = aRef.GetActorValue("SpeedMult")
    Debug.Trace("baseSpeed is: " + fSpeedMulti)

; adjustedSpeed = interpolate with percentage and magnitude
    float fNewSpeed = fSpeedMulti + (f * (fmaxSpeed - fSpeedMulti))

    aRef.SetActorValue("SpeedMult", fNewSpeed)
    Debug.Trace("adjustedSpeed is: " + fNewSpeed)

    RegisterForSingleUpdate(1.0)                                        ; create update chain
ENDEVENT
;=======
endState

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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