LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

PlayerStateAnimalPet

Parent
PlayerStateBase
Functions

activate

Description
Activate method
Definition
activate()
Code
49function PlayerStateAnimalPet:activate()
50 PlayerStateAnimalPet:superClass().activate(self)
51 local dogHouse = g_currentMission:getDoghouse(self.player.farmId)
52 if dogHouse ~= nil and dogHouse.dog ~= nil then
53 dogHouse.dog:pet()
54 end
55 self:deactivate()
56end

deactivate

Description
Deactivate method
Definition
deactivate()
Code
60function PlayerStateAnimalPet:deactivate()
61 PlayerStateAnimalPet:superClass().deactivate(self)
62 self.isDog = false
63end

isAvailable

Description
Check if we can pet an animal.
Definition
isAvailable()
Return Values
boolreturnstrue if player can pet an animal
Code
29function PlayerStateAnimalPet:isAvailable()
30 self.isDog = false
31 if self.player.isClient and self.player.isEntered and not g_gui:getIsGuiVisible() then
32 local playerHandsEmpty = self.player.baseInformation.currentHandtool == nil and not self.player.isCarryingObject
33 local dogHouse = g_currentMission:getDoghouse(self.player.farmId)
34 local _, playerY, _ = getWorldTranslation(self.player.rootNode)
35 playerY = playerY - self.player.baseInformation.capsuleTotalHeight * 0.5
36 local deltaWater = playerY - g_currentMission.waterY
37 local playerInWater = deltaWater < 0.0
38
39 if playerHandsEmpty and not playerInWater and dogHouse ~= nil and dogHouse.dog ~= nil and dogHouse.dog.playersInRange[self.player.rootNode] then
40 self.isDog = true
41 return true
42 end
43 end
44 return false
45end

new

Description
Creating instance of state.
Definition
new(table player, table stateMachine)
Arguments
tableplayerinstance of player
tablestateMachineinstance of the state machine manager
Return Values
tableinstanceinstance of object
Code
19function PlayerStateAnimalPet:new(player, stateMachine)
20 local self = PlayerStateBase:new(player, stateMachine, PlayerStateAnimalPet_mt)
21
22 self.isDog = false
23 return self
24end