Create a recharge timer for passive ability without OnUpdate

Post » Fri Jul 18, 2014 2:13 pm

I am new to sjyrim scripting. I am trying to add a cooldown for a passive ability that is always active on the player. I have come to understand that OnUpdate is something to be avoided to reduce the load. I saw something about using RegisterForSingleUpdate to create an update chain but I dont fully understand how that works.

Here's what I have so far utilising OnUpdate (note: this doesnt work either)

Spoiler
Scriptname DamageGate extends ActiveMagicEffect  Spell Property HealSpell  Auto  float timer = 1float Property PercentHealth = 100.0 Auto  Function SomeFunction()                    RegisterForUpdate(5.0)EndFunctionEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked )        PercentHealth = GetTargetActor().GetAVPercentage("Health")    If timer = 1        If PercentHealth < 0.8            HealSpell.Cast(GetTargetActor())            ;Utility.Wait(15.0)            ;RegisterForUpdate(5.0)            timer = 0        EndIf    EndIfendEvent Event OnUpdate() ; This event occurs every five seconds            timer = 1    ;UnregisterForUpdate()EndEvent

I'm pretty sure I'm missing a few basics, but I can't seem to figure it out.

User avatar
Rachell Katherine
 
Posts: 3380
Joined: Wed Oct 11, 2006 5:21 pm

Post » Fri Jul 18, 2014 5:01 am

Call SomeFunction in OnHit and place a RegisterForSingleUpdate inside the OnUpdate event. That's how you get a chain going.

And you can put in a control bool of sorts to stop it whenever, if the bool is set to false or true in the script.

And half-baked way to achieve what you want is through a while loop, but it'll keep running til the statement inside the loop is false.

Come to think of it.. given how OnHit operates, I'm not sure it's safe to run a chain through that event?

User avatar
Ruben Bernal
 
Posts: 3364
Joined: Sun Nov 18, 2007 5:58 pm


Return to V - Skyrim