Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scriptname PQ_MiningByPlayer extends ObjectReference
- ; niston's player mining script for Productive Quarry
- LeveledItem Property MineItemsList Auto Const
- {Sets the leveled list of items to roll from and add to player's inventory}
- Int Property DebugMode = 0 Auto Const
- {set to 1 for debug messages.}
- Sound Property SoundOnMining Auto Const
- {sound for each mining turn}
- Sound Property SoundOnMined Auto Const
- {sound for material mined}
- Sound Property SoundOnExhaustionFemale Auto Const
- {sound for when getting exhausted, female}
- Sound Property SoundOnExhaustionMale Auto Const
- {sound for when getting exhausted, male}
- Spell Property SpellOnMining Auto Const
- {Spell for each mining turn}
- Spell Property SpellOnExhaustion Auto Const
- {Spell when mining for too long and getting exhausted}
- Int Property MiningDuration = 5 Auto Const
- {Duration in real world seconds of each mining turn}
- Int Property MiningTurnsLimit = 5 Auto Const
- {Maximum number of mining turns before the player gets exhausted}
- Int enumTimerID_MiningTurnDuration = 1 Const
- Int turnsMined = 0
- Actor myPlayer = none
- bool inUseByNPC = false
- Auto State IDLE
- Event OnBeginState(string asOldState)
- If (DebugMode == 1)
- Debug.Notification("PQ_MiningByPlayer: State IDLE")
- EndIf
- ; cancel mining turn timer on IDLE
- CancelTimer(enumTimerID_MiningTurnDuration)
- ; reset turns mined to zero
- turnsMined = 0
- myPlayer = Game.GetPlayer()
- ; probably toggles animation state?
- SetAnimationVariableFloat("fDampRate", 0.08)
- SetAnimationVariableFloat("fToggleBlend", 0.0)
- ; register for event that tells us when we got into the furniture
- RegisterForRemoteEvent(myPlayer, "OnSit")
- EndEvent
- ; catch this event to see if player actually entered the furniture
- Event Actor.OnSit(Actor akActor, ObjectReference akFurniture)
- ;akActor == myPlayer is unnecessary since myPlayer is the only actor we've registered for.
- If (akFurniture == Self)
- ; player entered mine furniture
- If (DebugMode == 1)
- Debug.Notification("PQ_MiningByPlayer (IDLE): Actor.OnSit")
- EndIf
- ; not sure what I am doing here - probably toggling animation state or something the like?
- SetAnimationVariableFloat("fDampRate", 0.03)
- SetAnimationVariableFloat("fToggleBlend", 1.0)
- ; start with zero turns
- turnsMined = 0
- ; unregister
- UnregisterForRemoteEvent(myPlayer, "OnSit")
- ; begin mining
- GotoState("MINING")
- EndIf
- EndEvent
- EndState
- State MINING
- ; player is mining
- Event OnBeginState(string asOldState)
- If DebugMode == 1
- Debug.Notification("PQ_MiningByPlayer: State MINING")
- EndIf
- ; start mining turn timer
- StartTimer(MiningDuration, enumTimerID_MiningTurnDuration)
- ;play mining sound
- SoundOnMining.play(self)
- EndEvent
- Event OnTimer(int aiTimerID)
- ; check if proper timer?
- If (aiTimerID == enumTimerID_MiningTurnDuration)
- If (DebugMode == 1)
- Debug.Notification("PQ_MiningByPlayer: OnTimer(Mining Turn)")
- EndIf
- ; if player is still using the mine, reward them and continue
- If (GetBaseObject() is furniture && IsFurnitureInUse())
- ; increment turns counter
- turnsMined = turnsMined + 1
- ; give player what's have been mined
- myPlayer.AddItem(MineItemsList, 1)
- ; play acoustic reward
- SoundOnMined.play(myPlayer)
- ; optionally cast spell fx on player for each mining turn
- spellOnMining.Cast(myPlayer)
- ; notify player about impending exhaustion
- If (turnsMined == (MiningTurnsLimit - 1)) ; watch out that MiningTurnsLimit isn't < 2
- Debug.Notification("Mining is very hard work...")
- EndIf
- ; player exhaustion
- If (turnsMined >= (MiningTurnsLimit + 1))
- ; excessive mining gets the player exhausted
- PlayerExhausted()
- ; have the player exit the furniture by activating it
- self.Activate(myPlayer, true)
- ; back into idle state
- GotoState("IDLE")
- Else
- ; play mining sound
- SoundOnMining.play(self)
- ; continue mining operations by restarting mining turn timer
- StartTimer(MiningDuration, enumTimerID_MiningTurnDuration)
- EndIf
- Else
- ; player has exited the furniture and doesn't get any reward from this turn
- GotoState("IDLE")
- EndIf
- EndIf
- EndEvent
- Event OnActivate(ObjectReference akActionRef)
- if DebugMode == 1
- Debug.Notification("PQ_MiningByPlayer (MINING): OnActivate")
- endIf
- ; Do Nothing
- EndEvent
- EndState
- Event OnExitFurniture(ObjectReference akActionRef)
- if DebugMode == 1
- Debug.Notification("OnExitFurniture");
- endIf
- ; always go to idle state if player exited furniture
- If akActionRef == Game.GetPlayer()
- gotoState("IDLE")
- endIf
- EndEvent
- Function PlayerExhausted()
- ; cast exhaustion spell on player
- SpellOnExhaustion.Cast(myPlayer)
- ; play exhaustion sound
- if (myPlayer.GetBaseObject() as ActorBase).GetSex() == 1
- SoundOnExhaustionFemale.play(myPlayer)
- else
- SoundOnExhaustionMale.play(myPlayer)
- endIf
- Debug.Notification("You need a break.")
- EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement