Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.52 KB | None | 0 0
  1. Scriptname PQ_MiningByPlayer extends ObjectReference
  2.  
  3. ; niston's player mining script for Productive Quarry
  4. ; thanks to DieFeM for helping out a noob! :)
  5.  
  6. LeveledItem Property MineItemsList Auto Const
  7. {Sets the leveled list of items to roll from and add to player's inventory}
  8.  
  9. Int Property DebugMode = 0 Auto Const
  10. {set to 1 for debug messages.}
  11.  
  12. Sound Property SoundOnMining Auto Const
  13. {sound for each mining turn}
  14.  
  15. Sound Property SoundOnMined Auto Const
  16. {sound for material mined}
  17.  
  18. Sound Property SoundOnExhaustionFemale Auto Const
  19. {sound for when getting exhausted, female}
  20.  
  21. Sound Property SoundOnExhaustionMale Auto Const
  22. {sound for when getting exhausted, male}
  23.  
  24. Spell Property SpellOnMining Auto Const
  25. {Spell for each mining turn}
  26.  
  27. Spell Property SpellOnExhaustion Auto Const
  28. {Spell when mining for too long and getting exhausted}
  29.  
  30. Int Property MiningDuration = 5 Auto Const
  31. {Duration in real world seconds of each mining turn}
  32.  
  33. Int Property MiningTurnsLimit = 5 Auto Const
  34. {Maximum number of mining turns before the player gets exhausted}
  35.  
  36. Int enumTimerID_FurnitureEnterTimeout = 1 Const
  37. Int enumTimerID_MiningTurnDuration = 2 Const
  38. Int turnsMined = 0
  39. Actor myPlayer = none
  40. bool inUseByNPC = false
  41.  
  42. Auto State IDLE
  43. Event OnBeginState(string asOldState)
  44. If (DebugMode == 1)
  45. Debug.Notification("PQ_MiningByPlayer: State IDLE")
  46. EndIf
  47.  
  48. ; cancel mining turn timer on IDLE
  49. CancelTimer(enumTimerID_MiningTurnDuration)
  50.  
  51. ; reset turns mined to zero
  52. turnsMined = 0
  53.  
  54. ; we don't have a player in IDLE state
  55. myPlayer = none
  56.  
  57. ; probably toggles animation state?
  58. SetAnimationVariableFloat("fDampRate", 0.08)
  59. SetAnimationVariableFloat("fToggleBlend", 0.0)
  60.  
  61. EndEvent
  62.  
  63. ; mine activated
  64. Event OnActivate(ObjectReference akActionRef)
  65. If (inUseByNPC == false)
  66. ; activated by player?
  67. If akActionRef == Game.GetPlayer()
  68. ; activation by player
  69. If (DebugMode == 1)
  70. Debug.Notification("PQ_MiningByPlayer (IDLE): OnActivate")
  71. EndIf
  72.  
  73. ; set our player reference
  74. myPlayer = Game.GetPlayer()
  75.  
  76. ; register for animation event that tells us when we got into the furniture
  77. RegisterForAnimationEvent(myPlayer, "idleChairSitting")
  78.  
  79. ; spawn timeout timer for animation event
  80. StartTimer(10, enumTimerID_FurnitureEnterTimeout)
  81. Else
  82. ; activation by NPC presumed
  83. inUseByNPC = true
  84. EndIf
  85. Else
  86. If (DebugMode == 1)
  87. Debug.Notification("PQ_MiningByPlayer (IDLE): Mine in use by NPC; Not activating")
  88. EndIf
  89. EndIf
  90. EndEvent
  91.  
  92. Event OnTimer(int aiTimerID)
  93. If (aiTimerID == enumTimerID_FurnitureEnterTimeout)
  94. ; animation event for entering furniture did not occur in time, so clean up the registration
  95. UnregisterForAnimationEvent(myPlayer, "idleChairSitting")
  96. If (DebugMode == 1)
  97. Debug.Notification("PQ_MiningByPlayer (IDLE): OnAnimationEvent timed out")
  98. EndIf
  99. EndIf
  100. EndEvent
  101.  
  102. ; catch this event to see if player actually entered the furniture
  103. Event OnAnimationEvent(ObjectReference akSource, string asEventName)
  104. If (DebugMode == 1)
  105. Debug.Notification("PQ_MiningByPlayer (IDLE): OnAnimationEvent")
  106. EndIf
  107. If (asEventName == "idleChairSitting")
  108. If (myPlayer != none)
  109. If (akSource == myPlayer)
  110. ; Cancel timeout and unregister animation event (now that it has just fired)
  111. CancelTimer(enumTimerID_FurnitureEnterTimeout)
  112. UnregisterForAnimationEvent(myPlayer, "idleChairSitting")
  113.  
  114. If (inUseByNPC == false)
  115. ; furniture not in use by NPC, this means that the player entered the mine furniture
  116. If (DebugMode == 1)
  117. Debug.Notification("PQ_MiningByPlayer (IDLE): Furniture entered by player")
  118. EndIf
  119.  
  120. ; not sure what I am doing here - probably toggling animation state or something the like?
  121. SetAnimationVariableFloat("fDampRate", 0.03)
  122. SetAnimationVariableFloat("fToggleBlend", 1.0)
  123.  
  124. ; start with zero turns
  125. turnsMined = 0
  126.  
  127. ; begin mining
  128. GotoState("MINING")
  129.  
  130. Else
  131. ; player can't have entered the mining furniture, because it is being used by NPC
  132. If (DebugMode == 1)
  133. Debug.Notification("PQ_MiningByPlayer (IDLE): Furniture in use by NPC; Aborting.")
  134. EndIf
  135. ; do NOT go to MINING state
  136. EndIf
  137. EndIf
  138. EndIf
  139. Else
  140. If (DebugMode == 1)
  141. Debug.Notification("PQ_MiningByPlayer (IDLE): myPlayer is none; Event ignored.")
  142. EndIf
  143. EndIf
  144. EndEvent
  145.  
  146. EndState
  147.  
  148. State MINING
  149. ; player is mining
  150. Event OnBeginState(string asOldState)
  151. If DebugMode == 1
  152. Debug.Notification("PQ_MiningByPlayer: State MINING")
  153. EndIf
  154.  
  155. ; start mining turn timer
  156. StartTimer(MiningDuration, enumTimerID_MiningTurnDuration)
  157.  
  158. ;play mining sound
  159. SoundOnMining.play(self)
  160. EndEvent
  161.  
  162. Event OnTimer(int aiTimerID)
  163. ; check if proper timer?
  164. If (aiTimerID == enumTimerID_MiningTurnDuration)
  165. If (DebugMode == 1)
  166. Debug.Notification("PQ_MiningByPlayer (MINING): OnTimer(Mining Turn)")
  167. EndIf
  168.  
  169. ; if player is still using the mine, reward them and continue
  170. If (GetBaseObject() is furniture && IsFurnitureInUse() && (inUseByNPC == false))
  171.  
  172. ; increment turns counter
  173. turnsMined = turnsMined + 1
  174.  
  175. ; give player what they mined for
  176. myPlayer.AddItem(MineItemsList, 1)
  177.  
  178. ; play acoustic reward
  179. SoundOnMined.play(myPlayer)
  180.  
  181. ; optionally cast spell fx on player for each mining turn
  182. spellOnMining.Cast(myPlayer)
  183.  
  184. ; notify player about impending exhaustion
  185. If (turnsMined == (MiningTurnsLimit - 1)) ; watch out that MiningTurnsLimit isn't < 2
  186. Debug.Notification("Mining is very hard work...")
  187. EndIf
  188.  
  189. ; player exhaustion
  190. If (turnsMined >= (MiningTurnsLimit + 1))
  191. ; excessive mining gets the player exhausted
  192. PlayerExhausted()
  193.  
  194. ; notify player
  195. Debug.Notification("You need a break.")
  196.  
  197. ; have the player exit the furniture by activating it
  198. self.Activate(myPlayer, true)
  199.  
  200. ; back into idle state
  201. GotoState("IDLE")
  202.  
  203. Else
  204. ; play mining sound
  205. SoundOnMining.play(self)
  206.  
  207. ; continue mining operations by restarting mining turn timer
  208. StartTimer(MiningDuration, enumTimerID_MiningTurnDuration)
  209.  
  210. EndIf
  211. Else
  212. ; player has exited the furniture and doesn't get any reward from this turn
  213. GotoState("IDLE")
  214. EndIf
  215. EndIf
  216. EndEvent
  217.  
  218. Event OnActivate(ObjectReference akActionRef)
  219. If DebugMode == 1
  220. Debug.Notification("PQ_MiningByPlayer (MINING): OnActivate")
  221. EndIf
  222. ; ignore this
  223. EndEvent
  224. EndState
  225.  
  226. ; always handle this event, so it's not part of a state
  227. Event OnExitFurniture(ObjectReference akActionRef)
  228. If akActionRef == Game.GetPlayer()
  229. If DebugMode == 1
  230. Debug.Notification("PQ_MiningByPlayer: OnExitFurniture (Player)");
  231. EndIf
  232. ; always go to idle state if player exited furniture
  233. gotoState("IDLE")
  234. Else
  235. If DebugMode == 1
  236. Debug.Notification("PQ_MiningByPlayer: OnExitFurniture (NPC)");
  237. EndIf
  238. ; clear NPC usage flag in case anyone other than the player exited the furniture
  239. inUseByNPC = false
  240. EndIf
  241. EndEvent
  242.  
  243. Function PlayerExhausted()
  244. ; cast exhaustion spell on player
  245. SpellOnExhaustion.Cast(myPlayer)
  246. ; play exhaustion sound
  247. If (myPlayer.GetBaseObject() as ActorBase).GetSex() == 1
  248. SoundOnExhaustionFemale.play(myPlayer)
  249. Else
  250. SoundOnExhaustionMale.play(myPlayer)
  251. EndIf
  252. EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement