Stopping a Script that uses a few Not-Short "Wait" F

Post » Fri Mar 01, 2013 9:09 am

So I have a script that sits the player down and applies and removes different spells to the player based on how long they've been sitting, and everything works great so far, however I've run into a potential issue that I'm struggling to find a good solution for, the player getting up and then sitting back down rapidly.

So a super short snippet of my script looks like this so far:
Spoiler
if (PlayerRef.HasMagicEffect(T0FocusState4)) ;Check for current tier of the "Focus" spellUtility.Wait(15)if PlayerRef.GetSitState() == 3 ;Makes sure the player is sitting before casting the appropriate "Focus" spell, in this case, recasting the existing since it's the highest tier.T0FocusState4Spell.Cast(PlayerRef)Debug.Notification("Focus State 4 Spell Renewed")EndIfelseif (PlayerRef.HasMagicEffect(T0FocusState3))Utility.Wait(10)if PlayerRef.GetSitState() == 3PlayerRef.DispelSpell(T0FocusState3Spell)T0FocusState4Spell.Cast(PlayerRef)Debug.Notification("Entered Focus State 4 from State 3")EndIf

My problem would be introduced if the player got up during one of the longer wait functions, the 15 second one for example, being the longest, and then reused the power, they'd be back in a sitstate, the script refires and then there are two instances of it rolling with each one showing true for getsitstate.
I toyed with using a bool, that shows false when my OnUpdate event gets cleans up the sitting down process, but that works the exact same way.

So I guess my question is really, can I tell this script to just stop completely in the OnUpdate event? Since that'd just interrupt the functions right?
User avatar
Laurenn Doylee
 
Posts: 3427
Joined: Sun Dec 03, 2006 11:48 am

Post » Fri Mar 01, 2013 2:25 pm

Use RegisterForSingleUpdate() instead, as I beleive if they sit again and it restarts the script, it will register again for a later update, erasing the first one. Meaning they have to sit there for the 15 seconds in it's entirety for it have effect.
User avatar
Isabell Hoffmann
 
Posts: 3463
Joined: Wed Apr 18, 2007 11:34 pm


Return to V - Skyrim