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
- ; thanks to DieFeM for helping out a noob! :)
- 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_FurnitureEnterTimeout = 1 Const
- Int enumTimerID_MiningTurnDuration = 2 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 on IDLE
- turnsMined = 0
- ; we don't have a player in IDLE state
- myPlayer = none
- ; probably toggles animation state?
- SetAnimationVariableFloat("fDampRate", 0.08)
- SetAnimationVariableFloat("fToggleBlend", 0.0)
- EndEvent
- ; mine activated
- Event OnActivate(ObjectReference akActionRef)
- If (inUseByNPC == false)
- ; activated by player?
- If akActionRef == Game.GetPlayer()
- ; activation by player
- If (DebugMode == 1)
- Debug.Notification("PQ_MiningByPlayer (IDLE): OnActivate")
- EndIf
- ; set our player reference
- myPlayer = Game.GetPlayer()
- ; register for OnSit event
- RegisterForRemoteEvent(myPlayer, "OnSit")
- ; register for animation event that tells us when we got into the furniture
- ;RegisterForAnimationEvent(myPlayer, "idleChairSitting")
- ; spawn timeout timer for animation event; 10 seconds
- ;StartTimer(10, enumTimerID_FurnitureEnterTimeout)
- Else
- ; activation by NPC presumed
- inUseByNPC = true
- EndIf
- Else
- If (DebugMode == 1)
- Debug.Notification("PQ_MiningByPlayer (IDLE): Mine in use by NPC; Not activating")
- EndIf
- EndIf
- EndEvent
- Event Actor.OnSit(Actor akActor, ObjectReference akFurniture)
- ; I love this <3
- If (akFurniture == Self)
- ; player entered the mining 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
- Event OnTimer(int aiTimerID)
- If (aiTimerID == enumTimerID_FurnitureEnterTimeout)
- ; animation event for entering furniture did not occur in time, so clean up the registration
- UnregisterForAnimationEvent(myPlayer, "idleChairSitting")
- If (DebugMode == 1)
- Debug.Notification("PQ_MiningByPlayer (IDLE): OnAnimationEvent timed out")
- EndIf
- ; keep in IDLE state
- EndIf
- EndEvent
- ; catch this event to see if player actually entered the furniture
- Event OnAnimationEvent(ObjectReference akSource, string asEventName)
- If (DebugMode == 1)
- Debug.Notification("PQ_MiningByPlayer (IDLE): OnAnimationEvent")
- EndIf
- If (asEventName == "idleChairSitting")
- ; the player entered some furniture
- If (myPlayer != none)
- If (akSource == myPlayer)
- ; Cancel timeout and unregister animation event (now that it has just fired)
- CancelTimer(enumTimerID_FurnitureEnterTimeout)
- UnregisterForAnimationEvent(myPlayer, "idleChairSitting")
- If (inUseByNPC == false)
- ; furniture not in use by NPC, so presumably, the player entered the mining furniture
- If (DebugMode == 1)
- Debug.Notification("PQ_MiningByPlayer (IDLE): Furniture entered by player")
- 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
- ; begin mining
- GotoState("MINING")
- Else
- ; player can't have entered the mining furniture, because it is being used by NPC
- If (DebugMode == 1)
- Debug.Notification("PQ_MiningByPlayer (IDLE): Furniture in use by NPC; Aborting.")
- EndIf
- ; do NOT go to MINING state
- EndIf
- EndIf
- EndIf
- Else
- If (DebugMode == 1)
- Debug.Notification("PQ_MiningByPlayer (IDLE): myPlayer is none; Event ignored.")
- EndIf
- 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 (MINING): OnTimer(Mining Turn)")
- EndIf
- ; if player is still using the mine, reward them and continue
- If (GetBaseObject() is furniture && IsFurnitureInUse() && (inUseByNPC == false))
- ; increment turns counter
- turnsMined = turnsMined + 1
- ; give player what they mined for
- 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()
- ; notify player
- Debug.Notification("You need a break.")
- ; 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
- ; ignore this
- EndEvent
- EndState
- ; always handle this event, so it's not part of a state
- Event OnExitFurniture(ObjectReference akActionRef)
- If akActionRef == Game.GetPlayer()
- If DebugMode == 1
- Debug.Notification("PQ_MiningByPlayer: OnExitFurniture (Player)");
- EndIf
- ; always go to idle state if player exited furniture
- gotoState("IDLE")
- Else
- If DebugMode == 1
- Debug.Notification("PQ_MiningByPlayer: OnExitFurniture (NPC)");
- EndIf
- ; clear NPC usage flag in case anyone other than the player exited the furniture
- inUseByNPC = false
- EndIf
- EndEvent
- Event Actor.OnSit(Actor akActor, ObjectReference akFurniture)
- ;Do Nothing
- 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
- EndFunction
Add Comment
Please, Sign In to add comment