LUADOC - Farming Simulator 22

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
68function PlayerStateAnimalInteract:activate()
69 PlayerStateAnimalInteract:superClass().activate(self)
70
71 if self.dog ~= nil then
72 if self.dog.entityFollow == self.player.rootNode then
73 self.dog:goToSpawn()
74 else
75 self.dog:followEntity(self.player)
76 end
77
78 self:deactivate()
79
80 else
81 if self.husbandry ~= nil and self.cluster ~= nil then
82 g_client:getServerConnection():sendEvent(AnimalCleanEvent.new(self.husbandry, self.cluster.id))
83 g_soundManager:playSample(self.player.model.soundInformation.samples.horseBrush)
84 self:deactivate()
85 end
86 end
87end

deactivate

Description
Deactivate method
Definition
deactivate()
Code
91function PlayerStateAnimalInteract:deactivate()
92 PlayerStateAnimalInteract:superClass().deactivate(self)
93 self.dog = nil
94 self.husbandry = nil
95 self.cluster = nil
96end

isAvailable

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

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.dog = nil
23 self.husbandry = nil
24 self.cluster = nil
25
26 self.castDistance = 1.5 -- in m
27 self.interactText = ""
28 return self
29end

update

Description
Update method
Definition
update(float dt)
Arguments
floatdtdelta time in ms
Code
110function PlayerStateAnimalInteract:update(dt)
111 self:detectAnimal()
112end