Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Player
- PlayerModelManager
- PlayerPickUpObjectEvent
- PlayerSetFarmAnswerEvent
- PlayerSetFarmEvent
- PlayerSetHandToolEvent
- PlayerStateActivateObject
- PlayerStateAnimalFeed
- PlayerStateAnimalInteract
- PlayerStateAnimalPet
- PlayerStateAnimalRide
- PlayerStateBase
- PlayerStateCrouch
- PlayerStateCycleHandtool
- PlayerStateDrop
- PlayerStateFall
- PlayerStateIdle
- PlayerStateJump
- PlayerStateMachine
- PlayerStatePickup
- PlayerStateRun
- PlayerStateSwim
- PlayerStateThrow
- PlayerStateUseLight
- PlayerStateWalk
- PlayerStyle
- PlayerSwitchedFarmEvent
- PlayerTeleportEvent
- PlayerThrowObjectEvent
- PlayerToggleLightEvent
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
PlayerStateAnimalInteract
ParentPlayerStateBaseFunctions
activate
DescriptionActivate method. If animal is a dog, we pet him.Definition
activate()Code
64 | function 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 |
82 | end |
deactivate
DescriptionDeactivate methodDefinition
deactivate()Code
86 | function PlayerStateAnimalInteract:deactivate() |
87 | PlayerStateAnimalInteract:superClass().deactivate(self) |
88 | g_soundManager:stopSample(self.player.soundInformation.samples.horseBrush) |
89 | self.isDog = false |
90 | self.husbandryInfo = {} |
91 | end |
isAvailable
DescriptionCheck if we can interact with an animal.Definition
isAvailable()Return Values
bool | returns | true if player can interact with an animal |
32 | function 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 |
60 | end |
new
DescriptionCreating instance of state.Definition
new(table player, table stateMachine)Arguments
table | player | instance of player |
table | stateMachine | instance of the state machine manager |
table | instance | instance of object |
19 | function 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 |
27 | end |
update
DescriptionUpdate methodDefinition
update(float dt)Arguments
float | dt | delta time in ms |
104 | function 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 |
113 | end |