Guest User

TrapBase.psc

a guest
May 30th, 2016
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. ScriptName TrapBase extends objectReference
  2.  
  3. ;-- Properties --------------------------------------
  4. Group WarnProperties collapsedonref
  5. bool Property UseWarnTimer = True Auto Const
  6. { if this is set, use the WarnTimer otherwise it goes by the animation End }
  7. float Property WarnTime = 1.5 Auto Const
  8. { this is used if UseWarnTimer is true }
  9. int Property WarnTimerNumber = 100 Auto Const hidden
  10. Sound Property WarnSound Auto Const
  11. { Played from warn state is specified, but most should be hooked up on the anim }
  12. string Property WarnAnim = "Arm" Auto Const
  13. { Alert anim name }
  14. string Property WarnAnimEndEvent = "ArmState" Auto Const
  15. { Alert anim name }
  16. EndGroup
  17.  
  18. Group FireTrapProperies collapsedonref
  19. bool Property IsPhysicalTrap = False Auto Const
  20. { if this is true, prep for a phyical hit, this trap must have TrapHitBase to function }
  21. string Property FireTrapAnim = "Trip" Auto Const
  22. { Anim played when this is fired }
  23. string Property FireTrapAnimEndEvent = "TransitionComplete" Auto Const
  24. { Anim played when this is fired }
  25. int Property aiSoundLevel = 50 Auto Const
  26. EndGroup
  27.  
  28. Group DisarmProperties collapsedonref
  29. ObjectReference Property lastActivateRef Auto hidden
  30. { This tracks who activated this last across states for disarming }
  31. bool Property UseDefaultDisarm = True Auto Const
  32. { use the default Disarm behavior - IE just play the anim and disable if needed }
  33. LeveledItem Property TrapDisarmedReward Auto Const
  34. { This is given to the disarming actor }
  35. bool Property DisarmDisables = False Auto Const
  36. { if true, disarming this "disables" the object }
  37. string Property DisarmAnim = "Disarm" Auto Const
  38. { Disarm Anim to play }
  39. Sound Property DisarmSound Auto Const
  40. { This is the sound to play when disarming
  41. TRPDisarmHiTech & TRPDisarmLoTech are the usual choices }
  42. GlobalVariable Property TrapDisarmXPReward Auto Const
  43. Keyword Property WorkshopNoRepairKeyword Auto Const
  44. EndGroup
  45.  
  46. bool Property init Auto hidden
  47. traphitbase Property hitBase Auto hidden
  48. int Property TrapLevel = 1 Auto Const
  49. { Used to determine the difficulty of the trap, currently only tied to damage
  50. 0 = Easy
  51. 1 = Medium (DEFAULT)
  52. 2 = Hard
  53. 3 = VeryHard }
  54. int Property damage Auto Const hidden
  55. bool Property IsWorkshopVersion = False Auto
  56.  
  57. ;-- Variables ---------------------------------------
  58. bool isGrabbed = False
  59.  
  60. ;-- Functions ---------------------------------------
  61.  
  62. Function LocalOnTimer(int aiTimerID)
  63. ; Empty function
  64. EndFunction
  65.  
  66. Function DisarmTrap()
  67. If (UseDefaultDisarm)
  68. Self.PlayAnimation(DisarmAnim)
  69. Else
  70. Self.LocalDisarmTrap()
  71. EndIf
  72. If (DisarmSound)
  73. ObjectReference ObjSelf = Self as ObjectReference
  74. DisarmSound.Play(ObjSelf)
  75. EndIf
  76. If (!Self.DefaultDisarmReward())
  77. Self.LocalDisarmReward()
  78. EndIf
  79. If (!IsWorkshopVersion)
  80. Game.RewardPlayerXP(TrapDisarmXPReward.GetValueInt(), False)
  81. EndIf
  82. If (DisarmDisables)
  83. Self.Disable(False)
  84. EndIf
  85. Self.SetDestroyed(True)
  86. EndFunction
  87.  
  88. Function RepairTrap()
  89. Self.SetDestroyed(False)
  90. Self.PlayAnimation("set")
  91. Self.GoToState("Idle")
  92. EndFunction
  93.  
  94. Function LocalRepairTrap()
  95. ; Empty function
  96. EndFunction
  97.  
  98. Event OnTimer(int aiTimerID)
  99. If (Self.getState() != "Disarm" && Self.getState() != "Disarmed" && Self.getState() != "TrapFired")
  100. If (aiTimerID == WarnTimerNumber)
  101. Self.FireTrap()
  102. EndIf
  103. EndIf
  104. Self.LocalOnTimer(aiTimerID)
  105. EndEvent
  106.  
  107. Function StartWarn()
  108. Self.ResolveLeveledDamage()
  109. If (UseWarnTimer)
  110. Self.PlayAnimation(WarnAnim)
  111. Self.StartTimer(WarnTime, WarnTimerNumber)
  112. Else
  113. Self.PlayAnimationAndWait(WarnAnim, WarnAnimEndEvent)
  114. Self.FireTrap()
  115. EndIf
  116. EndFunction
  117.  
  118. Function resetLimiter()
  119. ; Empty function
  120. EndFunction
  121.  
  122. bool Function DefaultDisarmReward()
  123. If ((lastActivateRef as Actor) as bool && TrapDisarmedReward as bool)
  124. If (lastActivateRef == Game.GetPlayer() as ObjectReference)
  125. (lastActivateRef as Actor).AddItem(TrapDisarmedReward as Form, 1, False)
  126. Else
  127. (lastActivateRef as Actor).AddItem(TrapDisarmedReward as Form, 1, True)
  128. EndIf
  129. return True
  130. Else
  131. return False
  132. EndIf
  133. EndFunction
  134.  
  135. Function LocalDisarmReward()
  136. ; Empty function
  137. EndFunction
  138.  
  139. Event OnWorkshopObjectMoved(ObjectReference akReference)
  140. isGrabbed = False
  141. If (Self.IsPowered())
  142. Self.Activate(Self as ObjectReference, False)
  143. EndIf
  144. EndEvent
  145.  
  146. Function ResolveLeveledDamage()
  147. hitBase = (Self as ObjectReference) as traphitbase
  148. hitBase.damage = 0
  149. EndFunction
  150.  
  151. Function initialize()
  152. ; Empty function
  153. EndFunction
  154.  
  155. Event OnWorkshopObjectGrabbed(ObjectReference akReference)
  156. isGrabbed = True
  157. EndEvent
  158.  
  159. Event onReset()
  160. Self.GoToState("Idle")
  161. Self.Enable(False)
  162. Self.SetDestroyed(False)
  163. Self.reset(None)
  164. EndEvent
  165.  
  166. Event OnWorkshopObjectRepaired(ObjectReference akReference)
  167. Self.RepairTrap()
  168. If (Self.IsPowered())
  169. Self.Activate(Self as ObjectReference, False)
  170. EndIf
  171. EndEvent
  172.  
  173. Function FireTrap()
  174. ObjectReference ObjSelf = Self as ObjectReference
  175. ObjSelf.AddKeyword(WorkshopNoRepairKeyword)
  176. Self.GoToState("TrapFired")
  177. Self.LocalFireTrap()
  178. Self.CreateDetectionEvent(Game.GetPlayer(), aiSoundLevel)
  179. If (IsPhysicalTrap)
  180. hitBase.GoToState("canHit")
  181. Self.PlayAnimationAndWait(FireTrapAnim, FireTrapAnimEndEvent)
  182. hitBase.GoToState("cannotHit")
  183. EndIf
  184. ObjSelf.RemoveKeyword(WorkshopNoRepairKeyword)
  185. EndFunction
  186.  
  187. Function LocalDisarmTrap()
  188. ; Empty function
  189. EndFunction
  190.  
  191. Function LocalFireTrap()
  192. ; Empty function
  193. EndFunction
  194.  
  195. ;-- State -------------------------------------------
  196. State warn
  197.  
  198. Event OnBeginState(string asOldState)
  199. Self.StartWarn()
  200. EndEvent
  201.  
  202. Event onActivate(ObjectReference activateRef)
  203. lastActivateRef = activateRef
  204. If (activateRef as Actor)
  205. Self.GoToState("Disarm")
  206. EndIf
  207. EndEvent
  208. EndState
  209.  
  210. ;-- State -------------------------------------------
  211. State Disarm
  212.  
  213. Event OnBeginState(string asOldState)
  214. Self.DisarmTrap()
  215. EndEvent
  216. EndState
  217.  
  218. ;-- State -------------------------------------------
  219. State TrapFired
  220. EndState
  221.  
  222. ;-- State -------------------------------------------
  223. Auto State Idle
  224.  
  225. Event onActivate(ObjectReference activateRef)
  226. lastActivateRef = activateRef
  227. If (init == False)
  228. Self.initialize()
  229. init = True
  230. EndIf
  231. If (activateRef as Actor)
  232. If (!IsWorkshopVersion)
  233. Self.GoToState("Disarm")
  234. EndIf
  235. Else
  236. Self.GoToState("warn")
  237. EndIf
  238. EndEvent
  239.  
  240. Event OnPowerOn(ObjectReference akPowerGenerator)
  241. If (!isGrabbed)
  242. Self.Activate(Self as ObjectReference, False)
  243. EndIf
  244. EndEvent
  245. EndState
Advertisement
Add Comment
Please, Sign In to add comment