Advertisement
Guest User

niston's player mining script

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