Guest User

Untitled

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