ReDragon2013 Posted April 15, 2020 Share Posted April 15, 2020 AHVA_PortalButtonScript Scriptname AHVA_PortalButtonScript extends ObjectReference ; https://forums.nexusmods.com/index.php?/topic/8571488-scripting-block-or-allow-activators/ GlobalVariable Property myBusyGV auto ; "I would like to put a restriction in my script that block doors ; from being enabled if one already is.." Sound PROPERTY RumbleSFX auto Sound PROPERTY DoorAppearSFX auto Sound PROPERTY DoorDisappearSFX auto Sound PROPERTY DoorLoopSFX auto Sound PROPERTY BeamFireSFX auto Sound PROPERTY BeamOffSFX auto Sound PROPERTY BeamLoopSFX auto ;ObjectReference[] PROPERTY myRefs auto ; Refs as follow, may be pre-filled into array (to shrink properties) ObjectReference PROPERTY DoortoSummon auto ObjectReference PROPERTY FXSource auto ObjectReference PROPERTY BeamVFX01 auto ObjectReference PROPERTY BeamVFX02 auto ObjectReference PROPERTY BeamVFX03 auto ObjectReference PROPERTY FogVFX auto ObjectReference PROPERTY DoorLight auto ; Purpose: Enables or disable a portal door, does nothing if another is already activated! ;--------- ; -- EVENTs -- 1 + "Busy" + "Waiting" EVENT OnActivate(ObjectReference akActionRef) IF (myBusyGV.GetValueInt() == 1) RETURN ; - STOP - a door is already summoned ENDIF ;--------------------- IF IsPlayer(akActionRef) ELSE RETURN ; - STOP - not player activated, for whatever reason ENDIF ;--------------------- IF DoorToSummon.IsDisabled() gotoState("Busy") ; ### STATE ### myBusyGV.SetValueInt(1) ; door will be enabled - block any other door activator by setting value to 1.0 RumbleSFX.Play(FXSource) ; RumbleSFX.Play( myRefs[1] ) Game.ShakeCamera(afDuration = 2) BeamFireSFX.Play(FXSource) BeamVFX01.Enable(TRUE) ; 1 fade in BeamFireSFX.Play(FXSource) BeamVFX02.Enable(TRUE) ; 2 BeamFireSFX.Play(FXSource) BeamVFX03.Enable(TRUE) ; 3 FogVFX.Enable(TRUE) ; 4 DoorLight.Enable() ; 5 DoorAppearSFX.Play(FXSource) DoortoSummon.Enable(TRUE) ; 6 gotoState("Waiting") ; ### STATE ### RegisterForSingleUpdateGameTime(0.0) ENDIF ENDEVENT ;======================== State Busy ; do not allow activation while summoning the portal ;========= EVENT OnActivate(ObjectReference akActivator) ENDEVENT ;======= endState ;======================== State Waiting ;============ EVENT OnUpdateGameTime() Utility.Wait(0.25) ; just wait a bit IF ( BeamLoopSFX ) IF BeamVFX01.Is3DLoaded() ; Plays the sound from the location of the specified object reference, ; and waits for the sound to finish playing. This function is latent. BeamLoopSFX.PlayAndWait(BeamVFX01) ENDIF IF BeamVFX02.Is3DLoaded() BeamLoopSFX.PlayAndWait(BeamVFX02) ENDIF IF BeamVFX03.Is3DLoaded() BeamLoopSFX.PlayAndWait(BeamVFX03) ENDIF IF (DoorLoopSFX) && DoortoSummon.Is3DLoaded() DoorLoopSFX.PlayAndWait(DoortoSummon) ENDIF IF BeamVFX01.IsDisabled() ; door deactivation in progress ELSE RegisterForSingleUpdateGameTime(0.0) ; update again, simulate a while loop ENDIF ENDIF ENDEVENT EVENT OnActivate(ObjectReference akActionRef) IF IsPlayer(akActionRef) ELSE RETURN ; - STOP - ENDIF ;--------------------- IF DoortoSummon.IsDisabled() ; safety net ; disabled ELSE gotoState("") ; ### STATE ### BeamVFX01.Disable(TRUE) BeamOffSFX.Play(FXSource) BeamVFX02.Disable(TRUE) BeamOffSFX.Play(FXSource) DoortoSummon.Disable(TRUE) DoorDisappearSFX.Play(FXSource) DoorLight.Disable() BeamVFX03.Disable(TRUE) BeamOffSFX.Play(FXSource) FogVFX.Disable(TRUE) myBusyGV.SetValueInt(0) ; door has been disabled, back to normal activation ENDIF ENDEVENT EVENT OnCellAttach() ; player is going into the cell (can be fast travel) myF_Visible(TRUE) RegisterForUpdateGameTime(0.0) ENDEVENT EVENT OnCellDetach() ; player is leaving the cell (can be fast travel) UnRegisterForUpdateGameTime() myF_Visible(False) ENDEVENT ;======= endState ; -- FUNCTIONs -- 2 ;-------------------------------------------------- Bool FUNCTION IsPlayer(ObjectReference akActionRef) ;-------------------------------------------------- IF (akActionRef == Game.GetPlayer() as ObjectReference) Return TRUE ENDIF ;--------- Return False ENDFUNCTION ;----------------------------- FUNCTION myF_Visible(Bool bOK) ; internal helper ;----------------------------- IF ( bOK ) BeamVFX01.EnableNoWait() ; 1 BeamVFX02.EnableNoWait() ; 2 BeamVFX03.EnableNoWait() ; 3 FogVFX.EnableNoWait() ; 4 DoorLight.EnableNoWait() ; 5 DoortoSummon.EnableNoWait() ; 6 ELSE BeamVFX01.DisableNoWait() BeamVFX02.DisableNoWait() BeamVFX03.DisableNoWait() DoortoSummon.DisableNoWait() DoorLight.DisableNoWait() FogVFX.DisableNoWait() ENDIF ENDFUNCTION Link to comment Share on other sites More sharing options...
Recommended Posts