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
- Bool Initialized = 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 OnLoad()
- If(!Initialized)
- If(!DummyPlaced)
- PutDummy()
- EndIf
- If(InitialyOff)
- myFusionCore = NONE
- bCoreTaken = TRUE
- If(WaitFor3dLoad())
- BlockActivation(false)
- playAnimation("autoFade")
- int instanceID = GeneratorOff.play(self)
- Sound.SetInstanceVolume(instanceID, 0.0)
- EndIf
- Else
- PutCore()
- EndIf
- Initialized = True
- Else
- If(!bCoreTaken)
- If(myFusionCore == NONE)
- PutCore()
- EndIf
- Else
- If(myFusionCore != NONE)
- myFusionCore.Disable()
- myFusionCore.Delete()
- myFusionCore = NONE
- If(WaitFor3dLoad())
- BlockActivation(false)
- playAnimation("autoFade")
- int instanceID = GeneratorOff.play(self)
- Sound.SetInstanceVolume(instanceID, 0.0)
- EndIf
- EndIf
- EndIf
- EndIf
- ; It seems bad logic to me
- ;If GeneratorLoopMarkerA != NONE
- ; no looping SFX marker in environment. Create one.
- ;GeneratorLoopMarkerA = self.placeatme(GeneratorLoopSFX)
- ;Endif
- EndEvent
- Event ObjectReference.OnActivate(ObjectReference akSender, ObjectReference akActionRef)
- If(akSender == myFusionCore && !bCoreTaken)
- UnRegisterForRemoteEvent(myFusionCore, "OnActivate")
- myFusionCore = NONE
- bCoreTaken = TRUE
- BlockActivation(false)
- 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)
- fOffTimerSoFar += (fOffTimerTotal-fOffTimerSoFar)
- else
- wait(0.1)
- fOffTimerSoFar += 0.1
- endif
- If(linkedLight)
- linkedLight.disable()
- EndIf
- GeneratorBeep.play(self)
- If(linkedLight)
- linkedlight.enable()
- EndIf
- 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
- 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)
- 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")
- EndIf
- EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement