LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlayerStateAnimalPet

Parent
PlayerStateBase
Functions

activate

Description
Activate method
Definition
activate()
Code
60function PlayerStateAnimalPet:activate()
61 PlayerStateAnimalPet:superClass().activate(self)
62
63 if self.dog ~= nil then
64 self.dog:pet()
65 end
66
67 self:deactivate()
68end

deactivate

Description
Deactivate method
Definition
deactivate()
Code
72function PlayerStateAnimalPet:deactivate()
73 PlayerStateAnimalPet:superClass().deactivate(self)
74 self.dog = nil
75end

isAvailable

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

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.dog = nil
23
24 return self
25end