LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

PlayerStateAnimalInteract

Parent
PlayerStateBase
Functions

activate

Description
Activate method. If animal is a dog, we pet him.
Definition
activate()
Code
64function PlayerStateAnimalInteract:activate()
65 PlayerStateAnimalInteract:superClass().activate(self)
66
67 if self.isDog then
68 local dogHouse = g_currentMission:getDoghouse(self.player.farmId)
69 if dogHouse.dog ~= nil then
70 if dogHouse.dog.entityFollow == self.player.rootNode then
71 dogHouse.dog:goToSpawn()
72 else
73 dogHouse.dog:followEntity(self.player)
74 end
75 end
76 self:deactivate()
77 else
78 if self.husbandryInfo.husbandryId ~= nil then
79 g_soundManager:playSample(self.player.soundInformation.samples.horseBrush)
80 end
81 end
82end

deactivate

Description
Deactivate method
Definition
deactivate()
Code
86function PlayerStateAnimalInteract:deactivate()
87 PlayerStateAnimalInteract:superClass().deactivate(self)
88 g_soundManager:stopSample(self.player.soundInformation.samples.horseBrush)
89 self.isDog = false
90 self.husbandryInfo = {}
91end

isAvailable

Description
Check if we can interact with an animal.
Definition
isAvailable()
Return Values
boolreturnstrue if player can interact with an animal
Code
32function PlayerStateAnimalInteract:isAvailable()
33 self.isDog = false
34 if self.player.isClient and self.player.isEntered and not g_gui:getIsGuiVisible() then
35 local playerHandsEmpty = self.player.baseInformation.currentHandtool == nil and not self.player.isCarryingObject
36 local dogHouse = g_currentMission:getDoghouse(self.player.farmId)
37
38 if playerHandsEmpty and dogHouse ~= nil and dogHouse.dog ~= nil and dogHouse.dog.playersInRange[self.player.rootNode] then
39 self.isDog = true
40 if dogHouse.dog.entityFollow == self.player.rootNode then
41 self.interactText = g_i18n:getText("action_interactAnimalStopFollow")
42 else
43 self.interactText = g_i18n:getText("action_interactAnimalFollow")
44 end
45 return true
46 end
47 end
48
49 self:detectAnimal()
50
51 if self.husbandryInfo.husbandryId ~= nil then
52 local husbandry = g_currentMission.husbandries[self.husbandryInfo.husbandryId]
53 if husbandry ~= nil and husbandry:getCanBeRidden(self.husbandryInfo.visualId) and husbandry:isAnimalDirty(self.husbandryInfo.visualId) then
54 self.interactText = string.format(g_i18n:getText("action_interactAnimalClean"), husbandry:getAnimalName(self.husbandryInfo.visualId))
55 return true
56 end
57 end
58 self.interactText = ""
59 return false
60end

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 PlayerStateAnimalInteract:new(player, stateMachine)
20 local self = PlayerStateBase:new(player, stateMachine, PlayerStateAnimalInteract_mt)
21
22 self.isDog = false
23 self.husbandryInfo = {}
24 self.castDistance = 1.5 -- in m
25 self.interactText = ""
26 return self
27end

update

Description
Update method
Definition
update(float dt)
Arguments
floatdtdelta time in ms
Code
104function PlayerStateAnimalInteract:update(dt)
105 self:detectAnimal()
106
107 if self.husbandryInfo.husbandryId ~= nil and self.player.inputInformation.interactState == Player.BUTTONSTATES.PRESSED then
108 local husbandry = g_currentMission.husbandries[self.husbandryInfo.husbandryId]
109 husbandry:cleanAnimal(self.husbandryInfo.visualId, dt)
110 else
111 self:deactivate()
112 end
113end