enderalse/source/scripts/_00e_animtest_sc.psc

154 lines
3.6 KiB
Plaintext
Raw Normal View History

2021-10-05 22:22:24 +00:00
Scriptname _00E_AnimTest_SC extends Actor
2021-10-05 22:59:59 +00:00
Package[] Property akCustomAnimPackageArray Auto
Bool Property SyncAnimations = False Auto
{ (Optional) If True, sets bIsSynced animation variable to True on the packages' start. By default, False. }
Bool bIsInCombat ; Flag protecting from IdleForceDefaultState spam in combat
;=====================================================================================
; EVENTS
;=====================================================================================
Event OnCellAttach()
; Failsafe resets
bIsInCombat = False
EndEvent
Event OnPackageStart(Package akNewPackage)
If IsAnimPackage(akNewPackage)
RegisterForSleep()
TriggerAnimationSyncUpdate()
EndIf
EndEvent
Event OnPackageChange(Package akOldPackage)
2021-10-05 22:59:59 +00:00
If IsAnimPackage(akOldPackage)
GoToState("") ; Quit PackageStartUpdate state
UnregisterForSleep()
ResetAnimations()
EndIf
EndEvent
State PackageStartUpdate
Event OnUpdate()
If IsInDialogueWithPlayer()
RegisterForSingleUpdate(3.0)
Return
EndIf
GoToState("")
If SyncAnimations && Is3DLoaded() && bIsInCombat == False
SetAnimationVariableBool("bIsSynced", True)
EndIf
EndEvent
EndState
Event OnSleepStop(bool abInterrupted)
If Is3DLoaded()
Package akCurPackage = GetCurrentPackage()
If IsAnimPackage(akCurPackage)
ResetAnimations()
TriggerAnimationSyncUpdate()
EndIf
EndIf
EndEvent
2021-10-05 22:59:59 +00:00
Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
If bIsInCombat == False
CombatResetAnimations()
EndIf
2021-10-05 22:59:59 +00:00
EndEvent
2021-10-05 22:59:59 +00:00
Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
If aeCombatState != 0
If bIsInCombat == False
bIsInCombat = True
CombatResetAnimations()
EndIf
Else ; aeCombatState == 0
GetCombatState()
If GetCombatState() == 0
bIsInCombat = False
EndIf
EndIf
2021-10-05 22:22:24 +00:00
EndEvent
2021-10-05 22:59:59 +00:00
Event OnDying(Actor akKiller)
UnregisterForSleep()
GoToState("DoNothing")
EndEvent
Event OnDeath(Actor akKiller)
UnregisterForSleep()
GoToState("DoNothing")
EndEvent
State DoNothing
Event OnPackageStart(Package akNewPackage)
; Do nothing
EndEvent
Event OnPackageChange(Package akOldPackage)
; Do nothing
EndEvent
Event OnSleepStop(bool abInterrupted)
; Do nothing
EndEvent
Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
; Do nothing
EndEvent
Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
; Do nothing
EndEvent
Event OnDying(Actor akKiller)
; Do nothing
EndEvent
Event OnDeath(Actor akKiller)
; Do nothing
EndEvent
EndState
;=====================================================================================
; FUNCTIONS
;=====================================================================================
Bool bCombatResetLocked = False
Function CombatResetAnimations()
If bCombatResetLocked == False
bCombatResetLocked = True
If IsAnimPackage(GetCurrentPackage())
ResetAnimations()
EndIf
Utility.Wait(1.0)
bCombatResetLocked = False
EndIf
EndFunction
Function ResetAnimations()
If SyncAnimations
SetAnimationVariableBool("bIsSynced", False)
EndIf
Debug.SendAnimationEvent(Self, "IdleForceDefaultState")
EndFunction
Bool Function IsAnimPackage(Package akPackage)
Return (akPackage && akCustomAnimPackageArray.Find(akPackage) >= 0)
EndFunction
Function TriggerAnimationSyncUpdate()
If SyncAnimations && bIsInCombat == False
GoToState("PackageStartUpdate")
RegisterForSingleUpdate(3.0)
EndIf
EndFunction