diff --git a/scripts/fxbirdfleescript.pex b/scripts/fxbirdfleescript.pex index 3f1d9852..2c47a14b 100644 Binary files a/scripts/fxbirdfleescript.pex and b/scripts/fxbirdfleescript.pex differ diff --git a/source/scripts/fxbirdfleescript.psc b/source/scripts/fxbirdfleescript.psc index 4a5bf78b..c4842533 100644 --- a/source/scripts/fxbirdfleescript.psc +++ b/source/scripts/fxbirdfleescript.psc @@ -1,10 +1,7 @@ Scriptname FXBirdFleeSCRIPT extends ObjectReference {Triggers birds to fly away} -import debug ; import debug.psc for acces to trace() -import game ; game.psc for access to getPlayer() -import utility ; utility.psc for access to wait() -import sound ; sound.psc for access to play() +; Eddoursul 2024.01.21: Use states and updates, added OnReset sound property BirdFlockSound auto sound property BirdFlockFleeSound auto @@ -15,32 +12,50 @@ int instanceID00 ;************************************************* -Event onCellAttach() - ;USKP 2.0.1 - Short delay added to let 3D catch up. - Utility.Wait(0.5) - instanceID00 = BirdFlockSound.Play(Self) - gotoState("Waiting") -endEvent +auto state Init + Event OnCellAttach() + RegisterForSingleUpdate(0.5) + endEvent + + event OnUpdate() + instanceID00 = BirdFlockSound.Play(Self) + GotoState("Waiting") + endevent +endstate ;************************************************* State Waiting Event onTriggerEnter(ObjectReference akActionRef) - Actor actionRef = akActionRef as Actor - if(((PlayerTriggered) && (actionRef == game.GetPlayer() as Actor)) || (PlayerTriggered == False)) - gotoState("doNothing") - Self.PlayAnimation("PlayAnim01") - int instanceID01 = BirdFlockFleeSound.Play(Self) - wait (0.5) - StopInstance(instanceID00) + if ! PlayerTriggered || (akActionRef as Actor && akActionRef == Game.GetForm(0x14)) + GotoState("Triggered") + PlayAnimation("PlayAnim01") + BirdFlockFleeSound.Play(Self) + RegisterForSingleUpdate(0.5) endif endEvent endState ;************************************************* -State doNothing - ;do nothing +State Triggered + event OnUpdate() + GotoState("WaitForReset") + Sound.StopInstance(instanceID00) + instanceID00 = 0 + endevent +endState + +;************************************************* + +State WaitForReset + event OnReset() + GotoState("Init") + ; OnReset fires after onCellAttach() + if Is3DLoaded() + RegisterForSingleUpdate(0.5) + endif + endevent endState -;************************************************* \ No newline at end of file +;*************************************************