Advertisement
DieFeM

FusionGeneratorActivatorScript V2

Oct 3rd, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. Scriptname FusionGeneratorActivatorScript extends ObjectReference Conditional
  2.  
  3. import utility
  4.  
  5. Sound Property tempSFX Auto Const
  6. Sound Property GeneratorOff Auto const
  7. Sound Property GeneratorBeep Auto const
  8. Sound Property GeneratorLoopSFX Auto Const
  9. ObjectReference Property linkedLight Auto const
  10. ObjectReference Property GeneratorLoopMarkerA Auto
  11. ObjectReference Property GeneratorLoopMarkerB Auto Const hidden
  12. Form Property FusionCoreBaseObject Auto Const
  13. MiscObject Property DummyNoEdit_FusionCore Auto Const
  14. Bool Property bCoreTaken = False Auto Conditional
  15. Bool Property InitialyOff = False Auto
  16.  
  17. ObjectReference myFusionCore
  18.  
  19. ObjectReference PlacedDummyCoreRef
  20. Bool DummyPlaced = False
  21.  
  22. Float fOffTimerTotal = 1.0
  23. Float fOffTimerSoFar = 0.00
  24.  
  25. Float PGRotationZ = 0.000126
  26. Float DiffPosZ = 61.246826
  27. Float angle = 211.399384
  28. Float hypotenuse = 75.845207
  29. Float DiffAngleX = -0.000066
  30. Float DiffAngleY = -27.811234
  31. Float DiffAngleZ = 90.000008
  32.  
  33. Event ObjectReference.OnActivate(ObjectReference akSender, ObjectReference akActionRef)
  34. ;Dummy Event
  35. EndEvent
  36.  
  37. Auto State GeneratorInitialize
  38. Event OnCellLoad()
  39. If(WaitFor3dLoad())
  40. PutDummy()
  41. If(!InitialyOff)
  42. PutCore()
  43. Else
  44. SilentShutdown()
  45. EndIf
  46. GoToState("GeneratorReady")
  47. EndIf
  48. EndEvent
  49. EndState
  50.  
  51. State GeneratorReady
  52. Event ObjectReference.OnActivate(ObjectReference akSender, ObjectReference akActionRef)
  53. If(akSender == myFusionCore && !bCoreTaken)
  54. UnRegisterForRemoteEvent(myFusionCore, "OnActivate")
  55. playAnimation("AutoFade")
  56. If(tempSFX)
  57. tempSFX.play(Self)
  58. EndIf
  59. GeneratorOff.play(Self)
  60. If(GeneratorLoopMarkerA)
  61. GeneratorLoopMarkerA.Disable()
  62. EndIf
  63. If(GeneratorLoopMarkerB)
  64. ; only Disable secondary marker if on exists.
  65. GeneratorLoopMarkerB.Disable()
  66. Endif
  67. WaitRandomSlice(11)
  68. If(linkedLight)
  69. linkedLight.Disable()
  70. EndIf
  71. GeneratorBeep.play(Self)
  72. WaitRandomSlice(10)
  73. If(linkedLight)
  74. linkedlight.Enable()
  75. EndIf
  76. WaitRandomSlice(9)
  77. If(linkedLight)
  78. linkedLight.Disable()
  79. EndIf
  80. GeneratorBeep.play(Self)
  81. WaitRandomSlice(8)
  82. If(linkedLight)
  83. linkedlight.Enable()
  84. EndIf
  85. WaitRandomSlice(7)
  86. If(linkedLight)
  87. linkedLight.Disable()
  88. EndIf
  89. GeneratorBeep.play(Self)
  90. WaitRandomSlice(6)
  91. If(linkedLight)
  92. linkedlight.Enable()
  93. EndIf
  94. WaitRandomSlice(5)
  95. If(linkedLight)
  96. linkedLight.Disable()
  97. EndIf
  98. GeneratorBeep.play(Self)
  99. WaitRandomSlice(4)
  100. If(linkedLight)
  101. linkedlight.Enable()
  102. EndIf
  103. WaitRandomSlice(3)
  104. If(linkedLight)
  105. linkedLight.Disable()
  106. EndIf
  107. GeneratorBeep.play(Self)
  108. WaitRandomSlice(2)
  109. If(linkedLight)
  110. linkedlight.Enable()
  111. EndIf
  112. ; last blink, use up any remaining time - or just do a 0.1 slice if we're close.
  113. If(fOffTimerSoFar < fOffTimerTotal)
  114. wait(fOffTimerTotal-fOffTimerSoFar)
  115. Else
  116. wait(0.1)
  117. EndIf
  118. If(linkedLight)
  119. linkedLight.Disable()
  120. EndIf
  121. GeneratorBeep.play(Self)
  122. fOffTimerTotal = 1.0
  123. fOffTimerSoFar = 0.00
  124. myFusionCore = None
  125. bCoreTaken = True
  126. BlockActivation(False)
  127. EndIf
  128. EndEvent
  129.  
  130. Event OnActivate(ObjectReference akActionRef)
  131. If(bCoreTaken == True)
  132. If(Game.GetPlayer().GetItemCount(FusionCoreBaseObject) >= 1)
  133. myFusionCore = Game.GetPlayer().DropObject(FusionCoreBaseObject)
  134. PutCore()
  135. PlayAnimation("Reset")
  136. Else
  137. Debug.MessageBox("You don't have any fusion core in your inventory.")
  138. EndIf
  139. EndIf
  140. EndEvent
  141. EndState
  142.  
  143. Function WaitRandomSlice(int Slices)
  144. ; insert a wait of a random slice of time, but make sure th whole sequence takes a specific amount of time.
  145. ; 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.
  146. ; fOffTimerSoFar = 0.00 == the ACCRUED amount of time we've spent so far.
  147. Float fMin = 0.1
  148. Float fMax = 1.5*(fOffTimerTotal/Slices)
  149.  
  150. If (fOffTimerTotal - fOffTimerSoFar) < fMin
  151. ; if we generated a tiny slice of time then force the min/max to be very small
  152. fMax = math.Abs(fOffTimerTotal - fOffTimerSoFar)
  153. If fMax < 0.05
  154. fMax = 0.05 ; clamp to prevent hyper-short flickers
  155. EndIf
  156. fMin = fMax/2
  157. EndIf
  158. Float myTime = RandomFloat(fMin,fMax)
  159. fOffTimerSoFar += myTime
  160. Wait(myTime)
  161. EndFunction
  162.  
  163. Function PutDummy()
  164. PlacedDummyCoreRef = Self.PlaceAtMe(akFormToPlace = DummyNoEdit_FusionCore, abForcePersist = True, abInitiallyDisabled = True, abDeleteWhEnable = False)
  165. Float angleZOffset = Self.GetAngleZ() - PGRotationZ
  166. Float adjacent = hypotenuse * math.cos(angleZOffset + angle)
  167. Float opposite = hypotenuse * math.sin(angleZOffset + angle)
  168. PlacedDummyCoreRef.MoveTo(akTarget = Self, afXOffset = opposite, afYOffset = adjacent, afZOffset = DiffPosZ, abMatchRotation = False)
  169. Float CoreAngleY = GetAngleY() + DiffAngleY
  170. Float CoreAngleZ = (((GetAngleZ() + DiffAngleZ) / 360) - Math.Floor((GetAngleZ() + DiffAngleZ) / 360)) * 360
  171. If(CoreAngleZ > 180)
  172. If(CoreAngleY < 0)
  173. CoreAngleY = CoreAngleY * -1
  174. Else
  175. CoreAngleY = 0 - CoreAngleY
  176. EndIf
  177. EndIf
  178. PlacedDummyCoreRef.SetAngle(GetAngleX() + DiffAngleX, CoreAngleY, CoreAngleZ)
  179. PlacedDummyCoreRef.Enable()
  180. DummyPlaced = True
  181. EndFunction
  182.  
  183. Function PutCore()
  184. If(!DummyPlaced)
  185. PutDummy()
  186. EndIf
  187. If(linkedLight)
  188. linkedlight.Enable()
  189. EndIf
  190. BlockActivation(True, True)
  191. If(myFusionCore == None)
  192. myFusionCore = PlacedDummyCoreRef.PlaceAtMe(akFormToPlace = FusionCoreBaseObject, abForcePersist = True, abInitiallyDisabled = False, abDeleteWhEnable = False)
  193. EndIf
  194. myFusionCore.SetMotionType(myFusionCore.Motion_Keyframed, True)
  195. myFusionCore.MoveTo(akTarget = PlacedDummyCoreRef, abMatchRotation = True)
  196. bCoreTaken = False
  197. RegisterForRemoteEvent(myFusionCore, "OnActivate")
  198. EndFunction
  199.  
  200. Function SilentShutdown()
  201. bCoreTaken = True
  202. BlockActivation(False)
  203. playAnimation("AutoFade")
  204. int instanceID = GeneratorOff.play(Self)
  205. If(instanceID > 0)
  206. Sound.SetInstanceVolume(instanceID, 0.0)
  207. EndIf
  208. If(linkedLight)
  209. linkedLight.Disable()
  210. EndIf
  211. EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement