Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 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 animation event that tells us when we got into the furniture
  74. RegisterForAnimationEvent(myPlayer, "idleChairSitting")
  75.  
  76. ; spawn timeout timer for animation event
  77. StartTimer(10, enumTimerID_FurnitureEnterTimeout)
  78. Else
  79. ; activation by NPC presumed
  80. inUseByNPC = true
  81. EndIf
  82. EndEvent
  83.  
  84. Event OnTimer(int aiTimerID)
  85. If (aiTimerID == enumTimerID_FurnitureEnterTimeout)
  86. ; animation event for entering furniture did not occur in time, so clean up the registration
  87. UnregisterForAnimationEvent(myPlayer, "idleChairSitting")
  88. If (DebugMode == 1)
  89. Debug.Notification("PQ_MiningByPlayer (IDLE): OnAnimationEvent timed out")
  90. EndIf
  91. EndIf
  92. EndEvent
  93.  
  94. ; catch this event to see if player actually entered the furniture
  95. Event OnAnimationEvent(ObjectReference akSource, string asEventName)
  96. If (DebugMode == 1)
  97. Debug.Notification("PQ_MiningByPlayer (IDLE): OnAnimationEvent")
  98. EndIf
  99. If (myPlayer != none)
  100. If (akSource == myPlayer)
  101. If (asEventName == "idleChairSitting")
  102. ; Cancel timeout and unregister animation event (now that it has just fired)
  103. CancelTimer(enumTimerID_FurnitureEnterTimeout)
  104. UnregisterForAnimationEvent(myPlayer, "idleChairSitting")
  105.  
  106. If (inUseByNPC == false)
  107. ; furniture not in use by NPC, this means that the player entered the mine furniture
  108. If (DebugMode == 1)
  109. Debug.Notification("PQ_MiningByPlayer (IDLE): Furniture entered by player")
  110. EndIf
  111.  
  112. ; not sure what I am doing here - probably toggling animation state or something the like?
  113. SetAnimationVariableFloat("fDampRate", 0.03)
  114. SetAnimationVariableFloat("fToggleBlend", 1.0)
  115.  
  116. ; start with zero turns
  117. turnsMined = 0
  118.  
  119. ; begin mining
  120. GotoState("MINING")
  121.  
  122. Else
  123. ; player can't have entered the mining furniture, because it is being used by NPC
  124. If (DebugMode == 1)
  125. Debug.Notification("PQ_MiningByPlayer (IDLE): Furniture in use by NPC; Aborting.")
  126. EndIf
  127. ; do NOT go to MINING state
  128. EndIf
  129. EndIf
  130. EndIf
  131. Else
  132. If (DebugMode == 1)
  133. Debug.Notification("PQ_MiningByPlayer (IDLE): myPlayer is none; Event ignored.")
  134. EndIf
  135. EndIf
  136. EndEvent
  137.  
  138. EndState
  139.  
  140. State MINING
  141. ; player is mining
  142. Event OnBeginState(string asOldState)
  143. If DebugMode == 1
  144. Debug.Notification("PQ_MiningByPlayer: State MINING")
  145. EndIf
  146.  
  147. ; start mining turn timer
  148. StartTimer(MiningDuration, enumTimerID_MiningTurnDuration)
  149.  
  150. ;play mining sound
  151. SoundOnMining.play(self)
  152. EndEvent
  153.  
  154. Event OnTimer(int aiTimerID)
  155. ; check if proper timer?
  156. If (aiTimerID == enumTimerID_MiningTurnDuration)
  157. If (DebugMode == 1)
  158. Debug.Notification("PQ_MiningByPlayer: OnTimer(Mining Turn)")
  159. EndIf
  160.  
  161. ; if player is still using the mine, reward them and continue
  162. If (GetBaseObject() is furniture && IsFurnitureInUse() && (inUseByNPC == false))
  163.  
  164. ; increment turns counter
  165. turnsMined = turnsMined + 1
  166.  
  167. ; give player what's have been mined
  168. myPlayer.AddItem(MineItemsList, 1)
  169.  
  170. ; play acoustic reward
  171. SoundOnMined.play(myPlayer)
  172.  
  173. ; optionally cast spell fx on player for each mining turn
  174. spellOnMining.Cast(myPlayer)
  175.  
  176. ; notify player about impending exhaustion
  177. If (turnsMined == (MiningTurnsLimit - 1)) ; watch out that MiningTurnsLimit isn't < 2
  178. Debug.Notification("Mining is very hard work...")
  179. EndIf
  180.  
  181. ; player exhaustion
  182. If (turnsMined >= (MiningTurnsLimit + 1))
  183. ; excessive mining gets the player exhausted
  184. PlayerExhausted()
  185.  
  186. ; notify player
  187. Debug.Notification("You need a break.")
  188.  
  189. ; have the player exit the furniture by activating it
  190. self.Activate(myPlayer, true)
  191.  
  192. ; back into idle state
  193. GotoState("IDLE")
  194.  
  195. Else
  196. ; play mining sound
  197. SoundOnMining.play(self)
  198.  
  199. ; continue mining operations by restarting mining turn timer
  200. StartTimer(MiningDuration, enumTimerID_MiningTurnDuration)
  201.  
  202. EndIf
  203. Else
  204. ; player has exited the furniture and doesn't get any reward from this turn
  205. GotoState("IDLE")
  206. EndIf
  207. EndIf
  208. EndEvent
  209.  
  210. Event OnActivate(ObjectReference akActionRef)
  211. If DebugMode == 1
  212. Debug.Notification("PQ_MiningByPlayer (MINING): OnActivate")
  213. EndIf
  214. ; ignore this
  215. EndEvent
  216. EndState
  217.  
  218. Event OnExitFurniture(ObjectReference akActionRef)
  219. If DebugMode == 1
  220. Debug.Notification("OnExitFurniture");
  221. EndIf
  222.  
  223. If akActionRef == Game.GetPlayer()
  224. ; always go to idle state if player exited furniture
  225. gotoState("IDLE")
  226. Else
  227. ; clear NPC usage flag in case anyone other than the player exited the furniture
  228. inUseByNPC = false
  229. EndIf
  230. EndEvent
  231.  
  232. Function PlayerExhausted()
  233. ; cast exhaustion spell on player
  234. SpellOnExhaustion.Cast(myPlayer)
  235. ; play exhaustion sound
  236. If (myPlayer.GetBaseObject() as ActorBase).GetSex() == 1
  237. SoundOnExhaustionFemale.play(myPlayer)
  238. Else
  239. SoundOnExhaustionMale.play(myPlayer)
  240. EndIf
  241. EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement