Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scriptname FusionGeneratorActivatorScript extends ObjectReference Conditional
- import utility
- Sound Property tempSFX Auto Const
- Sound Property GeneratorOff Auto const
- Sound Property GeneratorBeep Auto const
- Sound Property GeneratorLoopSFX Auto Const
- ObjectReference Property linkedLight Auto const
- ObjectReference Property GeneratorLoopMarkerA Auto
- ObjectReference Property GeneratorLoopMarkerB Auto Const hidden
- Form Property FusionCoreBaseObject Auto Const
- MiscObject Property DummyNoEdit_FusionCore Auto Const
- Bool Property bCoreTaken = False Auto Conditional
- Bool Property InitialyOff = False Auto
- ObjectReference myFusionCore
- ObjectReference PlacedDummyCoreRef
- Bool DummyPlaced = False
- Float fOffTimerTotal = 1.0
- Float fOffTimerSoFar = 0.00
- Float PGRotationZ = 0.000126
- Float DiffPosZ = 61.246826
- Float angle = 211.399384
- Float hypotenuse = 75.845207
- Float DiffAngleX = -0.000066
- Float DiffAngleY = -27.811234
- Float DiffAngleZ = 90.000008
- Event ObjectReference.OnActivate(ObjectReference akSender, ObjectReference akActionRef)
- ;Dummy Event
- EndEvent
- Auto State GeneratorInitialize
- Event OnCellLoad()
- If(WaitFor3dLoad())
- PutDummy()
- If(!InitialyOff)
- PutCore()
- Else
- SilentShutdown()
- EndIf
- GoToState("GeneratorReady")
- EndIf
- EndEvent
- EndState
- State GeneratorReady
- Event ObjectReference.OnActivate(ObjectReference akSender, ObjectReference akActionRef)
- If(akSender == myFusionCore && !bCoreTaken)
- UnRegisterForRemoteEvent(myFusionCore, "OnActivate")
- playAnimation("AutoFade")
- If(tempSFX)
- tempSFX.play(Self)
- EndIf
- GeneratorOff.play(Self)
- If(GeneratorLoopMarkerA)
- GeneratorLoopMarkerA.Disable()
- EndIf
- If(GeneratorLoopMarkerB)
- ; only Disable secondary marker if on exists.
- GeneratorLoopMarkerB.Disable()
- Endif
- WaitRandomSlice(11)
- If(linkedLight)
- linkedLight.Disable()
- EndIf
- GeneratorBeep.play(Self)
- WaitRandomSlice(10)
- If(linkedLight)
- linkedlight.Enable()
- EndIf
- WaitRandomSlice(9)
- If(linkedLight)
- linkedLight.Disable()
- EndIf
- GeneratorBeep.play(Self)
- WaitRandomSlice(8)
- If(linkedLight)
- linkedlight.Enable()
- EndIf
- WaitRandomSlice(7)
- If(linkedLight)
- linkedLight.Disable()
- EndIf
- GeneratorBeep.play(Self)
- WaitRandomSlice(6)
- If(linkedLight)
- linkedlight.Enable()
- EndIf
- WaitRandomSlice(5)
- If(linkedLight)
- linkedLight.Disable()
- EndIf
- GeneratorBeep.play(Self)
- WaitRandomSlice(4)
- If(linkedLight)
- linkedlight.Enable()
- EndIf
- WaitRandomSlice(3)
- If(linkedLight)
- linkedLight.Disable()
- EndIf
- GeneratorBeep.play(Self)
- WaitRandomSlice(2)
- If(linkedLight)
- linkedlight.Enable()
- EndIf
- ; last blink, use up any remaining time - or just do a 0.1 slice if we're close.
- If(fOffTimerSoFar < fOffTimerTotal)
- wait(fOffTimerTotal-fOffTimerSoFar)
- Else
- wait(0.1)
- EndIf
- If(linkedLight)
- linkedLight.Disable()
- EndIf
- GeneratorBeep.play(Self)
- fOffTimerTotal = 1.0
- fOffTimerSoFar = 0.00
- myFusionCore = None
- bCoreTaken = True
- BlockActivation(False)
- EndIf
- EndEvent
- Event OnActivate(ObjectReference akActionRef)
- If(bCoreTaken == True)
- If(Game.GetPlayer().GetItemCount(FusionCoreBaseObject) >= 1)
- myFusionCore = Game.GetPlayer().DropObject(FusionCoreBaseObject)
- PutCore()
- PlayAnimation("Reset")
- Else
- Debug.MessageBox("You don't have any fusion core in your inventory.")
- EndIf
- EndIf
- EndEvent
- EndState
- Function WaitRandomSlice(int Slices)
- ; insert a wait of a random slice of time, but make sure th whole sequence takes a specific amount of time.
- ; fOffTimerTotal == the MAX amount of time we'd like to spend, although we may go a bit over in total. We're okay being dumb about that given the scope of this operation.
- ; fOffTimerSoFar = 0.00 == the ACCRUED amount of time we've spent so far.
- Float fMin = 0.1
- Float fMax = 1.5*(fOffTimerTotal/Slices)
- If (fOffTimerTotal - fOffTimerSoFar) < fMin
- ; if we generated a tiny slice of time then force the min/max to be very small
- fMax = math.Abs(fOffTimerTotal - fOffTimerSoFar)
- If fMax < 0.05
- fMax = 0.05 ; clamp to prevent hyper-short flickers
- EndIf
- fMin = fMax/2
- EndIf
- Float myTime = RandomFloat(fMin,fMax)
- fOffTimerSoFar += myTime
- Wait(myTime)
- EndFunction
- Function PutDummy()
- PlacedDummyCoreRef = Self.PlaceAtMe(akFormToPlace = DummyNoEdit_FusionCore, abForcePersist = True, abInitiallyDisabled = True, abDeleteWhEnable = False)
- Float angleZOffset = Self.GetAngleZ() - PGRotationZ
- Float adjacent = hypotenuse * math.cos(angleZOffset + angle)
- Float opposite = hypotenuse * math.sin(angleZOffset + angle)
- PlacedDummyCoreRef.MoveTo(akTarget = Self, afXOffset = opposite, afYOffset = adjacent, afZOffset = DiffPosZ, abMatchRotation = False)
- Float CoreAngleY = GetAngleY() + DiffAngleY
- Float CoreAngleZ = (((GetAngleZ() + DiffAngleZ) / 360) - Math.Floor((GetAngleZ() + DiffAngleZ) / 360)) * 360
- If(CoreAngleZ > 180)
- If(CoreAngleY < 0)
- CoreAngleY = CoreAngleY * -1
- Else
- CoreAngleY = 0 - CoreAngleY
- EndIf
- EndIf
- PlacedDummyCoreRef.SetAngle(GetAngleX() + DiffAngleX, CoreAngleY, CoreAngleZ)
- PlacedDummyCoreRef.Enable()
- DummyPlaced = True
- EndFunction
- Function PutCore()
- If(!DummyPlaced)
- PutDummy()
- EndIf
- If(linkedLight)
- linkedlight.Enable()
- EndIf
- BlockActivation(True, True)
- If(myFusionCore == None)
- myFusionCore = PlacedDummyCoreRef.PlaceAtMe(akFormToPlace = FusionCoreBaseObject, abForcePersist = True, abInitiallyDisabled = False, abDeleteWhEnable = False)
- EndIf
- myFusionCore.SetMotionType(myFusionCore.Motion_Keyframed, True)
- myFusionCore.MoveTo(akTarget = PlacedDummyCoreRef, abMatchRotation = True)
- bCoreTaken = False
- RegisterForRemoteEvent(myFusionCore, "OnActivate")
- EndFunction
- Function SilentShutdown()
- bCoreTaken = True
- BlockActivation(False)
- playAnimation("AutoFade")
- int instanceID = GeneratorOff.play(Self)
- If(instanceID > 0)
- Sound.SetInstanceVolume(instanceID, 0.0)
- EndIf
- If(linkedLight)
- linkedLight.Disable()
- EndIf
- EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement