Advertisement
DieFeM

FusionGeneratorActivatorScript

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