Advertisement
DieFeM

PQ_MiningByPlayer

Feb 15th, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 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_MiningTurnDuration = 1 Const
  36. Int turnsMined = 0
  37. Actor myPlayer = none
  38. bool inUseByNPC = false
  39.  
  40. Auto State IDLE
  41. Event OnBeginState(string asOldState)
  42. If (DebugMode == 1)
  43. Debug.Notification("PQ_MiningByPlayer: State IDLE")
  44. EndIf
  45.  
  46. ; cancel mining turn timer on IDLE
  47. CancelTimer(enumTimerID_MiningTurnDuration)
  48.  
  49. ; reset turns mined to zero
  50. turnsMined = 0
  51.  
  52. myPlayer = Game.GetPlayer()
  53.  
  54. ; probably toggles animation state?
  55. SetAnimationVariableFloat("fDampRate", 0.08)
  56. SetAnimationVariableFloat("fToggleBlend", 0.0)
  57.  
  58. ; register for event that tells us when we got into the furniture
  59. RegisterForRemoteEvent(myPlayer, "OnSit")
  60. EndEvent
  61.  
  62. ; catch this event to see if player actually entered the furniture
  63. Event Actor.OnSit(Actor akActor, ObjectReference akFurniture)
  64. ;akActor == myPlayer is unnecessary since myPlayer is the only actor we've registered for.
  65. If (akFurniture == Self)
  66. ; player entered mine furniture
  67. If (DebugMode == 1)
  68. Debug.Notification("PQ_MiningByPlayer (IDLE): Actor.OnSit")
  69. EndIf
  70.  
  71. ; not sure what I am doing here - probably toggling animation state or something the like?
  72. SetAnimationVariableFloat("fDampRate", 0.03)
  73. SetAnimationVariableFloat("fToggleBlend", 1.0)
  74.  
  75. ; start with zero turns
  76. turnsMined = 0
  77.  
  78. ; unregister
  79. UnregisterForRemoteEvent(myPlayer, "OnSit")
  80.  
  81. ; begin mining
  82. GotoState("MINING")
  83. EndIf
  84. EndEvent
  85.  
  86. EndState
  87.  
  88. State MINING
  89. ; player is mining
  90. Event OnBeginState(string asOldState)
  91. If DebugMode == 1
  92. Debug.Notification("PQ_MiningByPlayer: State MINING")
  93. EndIf
  94.  
  95. ; start mining turn timer
  96. StartTimer(MiningDuration, enumTimerID_MiningTurnDuration)
  97.  
  98. ;play mining sound
  99. SoundOnMining.play(self)
  100. EndEvent
  101.  
  102. Event OnTimer(int aiTimerID)
  103. ; check if proper timer?
  104. If (aiTimerID == enumTimerID_MiningTurnDuration)
  105. If (DebugMode == 1)
  106. Debug.Notification("PQ_MiningByPlayer: OnTimer(Mining Turn)")
  107. EndIf
  108.  
  109. ; if player is still using the mine, reward them and continue
  110. If (GetBaseObject() is furniture && IsFurnitureInUse())
  111.  
  112. ; increment turns counter
  113. turnsMined = turnsMined + 1
  114.  
  115. ; give player what's have been mined
  116. myPlayer.AddItem(MineItemsList, 1)
  117.  
  118. ; play acoustic reward
  119. SoundOnMined.play(myPlayer)
  120.  
  121. ; optionally cast spell fx on player for each mining turn
  122. spellOnMining.Cast(myPlayer)
  123.  
  124. ; notify player about impending exhaustion
  125. If (turnsMined == (MiningTurnsLimit - 1)) ; watch out that MiningTurnsLimit isn't < 2
  126. Debug.Notification("Mining is very hard work...")
  127. EndIf
  128.  
  129. ; player exhaustion
  130. If (turnsMined >= (MiningTurnsLimit + 1))
  131. ; excessive mining gets the player exhausted
  132. PlayerExhausted()
  133.  
  134. ; have the player exit the furniture by activating it
  135. self.Activate(myPlayer, true)
  136.  
  137. ; back into idle state
  138. GotoState("IDLE")
  139.  
  140. Else
  141. ; play mining sound
  142. SoundOnMining.play(self)
  143.  
  144. ; continue mining operations by restarting mining turn timer
  145. StartTimer(MiningDuration, enumTimerID_MiningTurnDuration)
  146.  
  147. EndIf
  148. Else
  149. ; player has exited the furniture and doesn't get any reward from this turn
  150. GotoState("IDLE")
  151. EndIf
  152. EndIf
  153. EndEvent
  154.  
  155. Event OnActivate(ObjectReference akActionRef)
  156. if DebugMode == 1
  157. Debug.Notification("PQ_MiningByPlayer (MINING): OnActivate")
  158. endIf
  159. ; Do Nothing
  160. EndEvent
  161. EndState
  162.  
  163. Event OnExitFurniture(ObjectReference akActionRef)
  164. if DebugMode == 1
  165. Debug.Notification("OnExitFurniture");
  166. endIf
  167.  
  168. ; always go to idle state if player exited furniture
  169. If akActionRef == Game.GetPlayer()
  170. gotoState("IDLE")
  171. endIf
  172. EndEvent
  173.  
  174. Function PlayerExhausted()
  175. ; cast exhaustion spell on player
  176. SpellOnExhaustion.Cast(myPlayer)
  177. ; play exhaustion sound
  178. if (myPlayer.GetBaseObject() as ActorBase).GetSex() == 1
  179. SoundOnExhaustionFemale.play(myPlayer)
  180. else
  181. SoundOnExhaustionMale.play(myPlayer)
  182. endIf
  183. Debug.Notification("You need a break.")
  184. EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement