Script v1.7.1.0
- AI
- Animals
- AnimalFoodManager
- AnimalHusbandryNoMorePall...
- AnimalManager
- AnimalNameManager
- CrowsWildlife
- Dog
- Horse
- HusbandryModuleBase
- HusbandryModuleFood
- HusbandryModuleFoodSpilla...
- HusbandryModuleLiquidManu...
- HusbandryModuleManure
- HusbandryModuleMilk
- HusbandryModulePallets
- HusbandryModuleStraw
- LightWildlife
- RideableAnimal
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- 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
Dog
ParentObjectFunctions
- delete
- feed
- fetchItem
- followEntity
- getUpdatePriority
- goToSpawn
- hourChanged
- idleStay
- idleWander
- isAbandoned
- load
- loadFromXMLFile
- new
- onGhostAdd
- onGhostRemove
- onPlayerLeave
- pet
- playerFarmChanged
- playerInteractionTriggerCallback
- readStream
- readUpdateStream
- resetSteeringParms
- saveToXMLFile
- setName
- setVisibility
- teleportToSpawn
- testScope
- update
- updateTick
- writeStream
- writeUpdateStream
delete
DescriptionDeleteDefinition
delete()Code
74 | function Dog:delete() |
75 | self.isDeleted = true -- mark as deleted so we can track it in Doghouse |
76 | if self.dogInstance ~= 0 then |
77 | delete(self.dogInstance) |
78 | end |
79 | |
80 | if self.isServer then |
81 | g_messageCenter:unsubscribeAll(self) |
82 | g_currentMission.environment:removeHourChangeListener(self) |
83 | end |
84 | |
85 | unregisterObjectClassName(self) |
86 | |
87 | Dog:superClass().delete(self) |
88 | end |
feed
DescriptionDefinitionfeed()Code
336 | function Dog:feed() |
337 | self.entityFollow = nil |
338 | self.entityThrower = nil |
339 | if not self.isServer then |
340 | g_client:getServerConnection():sendEvent(DogFeedEvent:new(self)) |
341 | else |
342 | self.spawner:setFoodVisibility(true) |
343 | self.foodPending = true |
344 | setCompanionFeed(self.dogInstance, self.animalId, self.spawner.foodNode, 1.0, 0.55, 1.5) |
345 | end |
346 | end |
fetchItem
DescriptionActivate fetch ball behaviorDefinition
fetchItem(object object)Arguments
object | object | of type DogBall |
351 | function Dog:fetchItem(player, ball) |
352 | if not self.isServer then |
353 | g_client:getServerConnection():sendEvent(DogFetchItemEvent:new(self, player, ball)) |
354 | else |
355 | local x, y, z = getWorldTranslation(ball.nodeId) |
356 | ball.throwPos = {x, y, z} |
357 | setCompanionFetch(self.dogInstance, self.animalId, ball.nodeId, 1.0, 0.5, player.rootNode, 3.0, 2.0, 3.0, 4.0) |
358 | self.entityThrower = player.rootNode |
359 | end |
360 | end |
followEntity
DescriptionActivate follow playerDefinition
followEntity(integer scenegraph)Arguments
integer | scenegraph | node of the ball |
299 | function Dog:followEntity(player) |
300 | -- Note: we also set entityFollow on the client side so that we can update the gui (it won't be 100% accurate if an other player interacts, but that should be good enough) |
301 | self.entityFollow = player.rootNode |
302 | self.entityThrower = nil |
303 | if not self.isServer then |
304 | g_client:getServerConnection():sendEvent(DogFollowEvent:new(self, player)) |
305 | else |
306 | setCompanionBehaviorIdleWander(self.dogInstance, self.animalId) |
307 | setCompanionFollowEntity(self.dogInstance, self.animalId, self.entityFollow, 3.0, 2.0, 4.0) |
308 | self.isStaying = false |
309 | if self.foodPending then |
310 | self.spawner:setFoodVisibility(false) |
311 | self.foodPending = false |
312 | end |
313 | end |
314 | end |
getUpdatePriority
DescriptionGet update priorityDefinition
getUpdatePriority(float skipCount, float x, float y, float z, float coeff, table connection)Arguments
float | skipCount | skip count |
float | x | x position |
float | y | y position |
float | z | z position |
float | coeff | coeff |
table | connection | connection |
float | priority | priority |
233 | function Dog:getUpdatePriority(skipCount, x, y, z, coeff, connection) |
234 | local distance, clipDistance = getCompanionClosestDistance(self.dogInstance, x, y, z) |
235 | local clipDist = math.min(clipDistance * coeff, self.forcedClipDistance) |
236 | local result = (1.0 - distance / clipDist) * 0.8 + 0.5 * skipCount * 0.2 |
237 | |
238 | return result |
239 | end |
goToSpawn
DescriptionActivate fetch ball behaviorDefinition
goToSpawn(integer scenegraph)Arguments
integer | scenegraph | node of the ball |
319 | function Dog:goToSpawn() |
320 | self.entityFollow = nil |
321 | self.entityThrower = nil |
322 | if not self.isServer then |
323 | g_client:getServerConnection():sendEvent(DogFollowEvent:new(self, nil)) |
324 | else |
325 | setCompanionBehaviorIdleWander(self.dogInstance, self.animalId) |
326 | setCompanionGotoEntity(self.dogInstance, self.animalId, self.spawner.spawnNode, 3.0, 2.0, 2.5) |
327 | if self.foodPending then |
328 | self.spawner:setFoodVisibility(false) |
329 | self.foodPending = false |
330 | end |
331 | end |
332 | end |
hourChanged
DescriptionCalled by the environment when an hour has changed.Definition
hourChanged()Code
255 | function Dog:hourChanged() |
256 | if not self.isServer then |
257 | return |
258 | end |
259 | |
260 | setCompanionDaytime(self.dogInstance, g_currentMission.environment.dayTime) |
261 | end |
idleStay
DescriptionActivate dog staying behavior (used when the currently followed player is switching vehicles or leaving the game)Definition
idleStay()Code
378 | function Dog:idleStay() |
379 | -- This is only supposed to be called on the server |
380 | self.entityFollow = nil |
381 | self.entityThrower = nil |
382 | setCompanionBehaviorIdleStay(self.dogInstance, self.animalId) |
383 | self.isStaying = true |
384 | if self.foodPending then |
385 | self.spawner:setFoodVisibility(false) |
386 | self.foodPending = false |
387 | end |
388 | end |
idleWander
DescriptionDefinitionidleWander()Code
392 | function Dog:idleWander() |
393 | -- This is only supposed to be called on the server |
394 | setCompanionBehaviorIdleWander(self.dogInstance, self.animalId) |
395 | |
396 | if self.foodPending then |
397 | self.spawner:setFoodVisibility(false) |
398 | self.foodPending = false |
399 | end |
400 | end |
isAbandoned
DescriptionDefinitionisAbandoned()Code
404 | function Dog:isAbandoned(dt) |
405 | local isEntityInRange = false |
406 | for _, player in pairs(g_currentMission.players) do |
407 | if player.isControlled then |
408 | local entityX, entityY, entityZ = getWorldTranslation(player.rootNode) |
409 | local distance, _ = getCompanionClosestDistance(self.dogInstance, entityX, entityY, entityZ) |
410 | if distance < self.abandonRange then |
411 | isEntityInRange = true |
412 | break |
413 | end |
414 | end |
415 | end |
416 | |
417 | if not isEntityInRange then |
418 | for _, enterable in pairs(g_currentMission.enterables) do |
419 | if enterable.spec_enterable ~= nil and enterable.spec_enterable.isControlled then |
420 | local entityX, entityY, entityZ = getWorldTranslation(enterable.rootNode) |
421 | local distance, _ = getCompanionClosestDistance(self.dogInstance, entityX, entityY, entityZ) |
422 | if distance < self.abandonRange then |
423 | isEntityInRange = true |
424 | break |
425 | end |
426 | end |
427 | end |
428 | end |
429 | |
430 | if isEntityInRange then |
431 | self.abandonTimer = self.abandonTimerDuration |
432 | else |
433 | self.abandonTimer = self.abandonTimer - dt |
434 | if self.abandonTimer <= 0 then |
435 | return true |
436 | end |
437 | end |
438 | |
439 | return false |
440 | end |
load
DescriptionDefinitionload()Code
47 | function Dog:load(spawner, xmlFilename, spawnX, spawnY, spawnZ) |
48 | self.spawner = spawner |
49 | self.animalId = 0 |
50 | self.spawnX = spawnX |
51 | self.spawnY = spawnY |
52 | self.spawnZ = spawnZ |
53 | self.xmlFilename = xmlFilename |
54 | self.dogInstance = createAnimalCompanionManager("dog", xmlFilename, "dog", spawnX, spawnY, spawnZ, g_currentMission.terrainRootNode, self.isServer, self.isClient, 1) |
55 | setCompanionWaterLevel(self.dogInstance, g_currentMission.waterY) |
56 | setCompanionTrigger(self.dogInstance, self.animalId, "playerInteractionTriggerCallback", self) |
57 | -- maxSteeringforce, maxVelocity, maxAngularVelocity, obstacleRadius |
58 | setCompanionCommonSteeringParameters(self.dogInstance, self.animalId, 1.5, 2.5, MathUtil.degToRad(3.0), 0.25) |
59 | -- target, wanderRadius, wanderDistance, wanderJitter |
60 | setCompanionWanderSteeringParameters(self.dogInstance, self.animalId, spawnX, spawnY, spawnZ, 1.0, 0.2, 0.01) |
61 | -- arriveRadius, arriveStopDistance |
62 | setCompanionArriveSteeringParameters(self.dogInstance, self.animalId, 1.0, 0.5) |
63 | setCompanionBehaviorWanderParameters(self.dogInstance, self.animalId, 10.0) |
64 | self.name = g_animalNameManager:getRandomName() |
65 | |
66 | if self.isServer then |
67 | g_currentMission.environment:addHourChangeListener(self) |
68 | g_messageCenter:subscribe(MessageType.PLAYER_FARM_CHANGED, Dog.playerFarmChanged, self) |
69 | end |
70 | end |
loadFromXMLFile
DescriptionLoading from attributes and nodesDefinition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)Arguments
integer | xmlFile | id of xml object |
string | key | key |
boolean | resetVehicles | reset vehicles |
boolean | success | success |
96 | function Dog:loadFromXMLFile(xmlFile, key, resetVehicles) |
97 | self:setName(getXMLString(xmlFile, key.."#name") or "") |
98 | |
99 | return true |
100 | end |
new
DescriptionCreatingDefinition
new()Return Values
table | instance | instance of object |
17 | function Dog:new(isServer, isClient, customMt) |
18 | local self = Object:new(isServer, isClient, customMt or Dog_mt) |
19 | |
20 | self.dogInstance = 0 |
21 | self.animalId = 0 |
22 | self.spawner = nil |
23 | self.xmlFilename = nil |
24 | self.entityFollow = nil |
25 | self.entityThrower = nil |
26 | self.playersInRange = {} |
27 | self.isStaying = false |
28 | self.abandonTimer = 0.0 |
29 | self.abandonTimerDuration = 6000 |
30 | self.abandonRange = 100 |
31 | self.name = "" |
32 | |
33 | self.spawnX = 0 |
34 | self.spawnY = 0 |
35 | self.spawnZ = 0 |
36 | |
37 | self.forcedClipDistance = 80 |
38 | |
39 | registerObjectClassName(self, "Dog") |
40 | |
41 | self.dirtyFlag = self:getNextDirtyFlag() |
42 | return self |
43 | end |
onGhostAdd
DescriptionOn ghost addDefinition
onGhostAdd()Code
249 | function Dog:onGhostAdd() |
250 | self:setVisibility(true) |
251 | end |
onGhostRemove
DescriptionOn ghost removeDefinition
onGhostRemove()Code
243 | function Dog:onGhostRemove() |
244 | self:setVisibility(false) |
245 | end |
onPlayerLeave
DescriptionTells the dog to stay at the current place when we leave the currently followed playerDefinition
onPlayerLeave()Code
486 | function Dog:onPlayerLeave(player) |
487 | -- return dog to it's house |
488 | if self.isServer then |
489 | if self.entityFollow == player.rootNode or self.entityThrower == player.rootNode then |
490 | self:idleStay() |
491 | end |
492 | if self.playersInRange[player.rootNode] ~= nil then |
493 | self.playersInRange[player.rootNode] = nil |
494 | end |
495 | end |
496 | end |
pet
DescriptionActivate dog petting response behaviorDefinition
pet()Code
364 | function Dog:pet() |
365 | if not self.isServer then |
366 | g_client:getServerConnection():sendEvent(DogPetEvent:new(self)) |
367 | else |
368 | setCompanionPet(self.dogInstance, self.animalId) |
369 | if self.foodPending then |
370 | self.spawner:setFoodVisibility(false) |
371 | self.foodPending = false |
372 | end |
373 | end |
374 | end |
playerFarmChanged
DescriptionDefinitionplayerFarmChanged()Code
476 | function Dog:playerFarmChanged(player) |
477 | if self.isServer then |
478 | if self.entityFollow == player.rootNode or self.entityThrower == player.rootNode then |
479 | self:idleStay() |
480 | end |
481 | end |
482 | end |
playerInteractionTriggerCallback
DescriptionCallback when dog interaction trigger is activatedDefinition
playerInteractionTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)Arguments
integer | triggerId | id of trigger |
integer | otherId | id of actor |
boolean | onEnter | on enter |
boolean | onLeave | on leave |
boolean | onStay | on stay |
283 | function Dog:playerInteractionTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
284 | local player = g_currentMission.players[otherId] |
285 | if player ~= nil then |
286 | if onEnter then |
287 | if g_currentMission.accessHandler:canFarmAccess(player.farmId, self, false) then |
288 | self.playersInRange[otherId] = true |
289 | end |
290 | elseif onLeave then |
291 | self.playersInRange[otherId] = nil |
292 | end |
293 | end |
294 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
115 | function Dog:readStream(streamId, connection) |
116 | if connection:getIsServer() then |
117 | local spawner = NetworkUtil.readNodeObject(streamId) |
118 | -- Note: the spawner can be when the doghouse not synced yet. The spawner will be set later on |
119 | local xmlFilename = NetworkUtil.convertFromNetworkFilename(streamReadString(streamId)) |
120 | |
121 | local spawnX = streamReadFloat32(streamId) |
122 | local spawnY = streamReadFloat32(streamId) |
123 | local spawnZ = streamReadFloat32(streamId) |
124 | local name = streamReadString(streamId) |
125 | |
126 | local isNew = self.xmlFilename == nil |
127 | if isNew then |
128 | self:load(spawner, xmlFilename, spawnX, spawnY, spawnZ) |
129 | if spawner ~= nil then |
130 | spawner.dog = self |
131 | end |
132 | end |
133 | |
134 | self:setName(name) |
135 | end |
136 | Dog:superClass().readStream(self, streamId, connection) |
137 | end |
readUpdateStream
DescriptionRead update network streamDefinition
readUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | network stream identification |
integer | timestamp | |
table | connection | connection information |
171 | function Dog:readUpdateStream(streamId, timestamp, connection) |
172 | if connection:getIsServer() then |
173 | readAnimalCompanionManagerFromStream(self.dogInstance, streamId, g_clientInterpDelay, g_packetPhysicsNetworkTime, g_client.tickDuration) |
174 | end |
175 | end |
resetSteeringParms
DescriptionDefinitionresetSteeringParms()Code
444 | function Dog:resetSteeringParms() |
445 | -- This is only supposed to be called on the server |
446 | |
447 | -- maxSteeringforce, maxVelocity, maxAngularVelocity, obstacleRadius |
448 | setCompanionCommonSteeringParameters(self.dogInstance, self.animalId, 1.5, 2.5, MathUtil.degToRad(3.0), 0.25) |
449 | -- target, wanderRadius, wanderDistance, wanderJitter |
450 | setCompanionWanderSteeringParameters(self.dogInstance, self.animalId, self.spawnX, self.spawnY, self.spawnZ, 1.0, 0.2, 0.01) |
451 | -- arriveRadius, arriveStopDistance |
452 | setCompanionArriveSteeringParameters(self.dogInstance, self.animalId, 1.0, 0.5) |
453 | end |
saveToXMLFile
DescriptionGet save attributes and nodesDefinition
saveToXMLFile(string nodeIdent)Arguments
string | nodeIdent | node ident |
string | attributes | attributes |
string | nodes | nodes |
107 | function Dog:saveToXMLFile(xmlFile, key, usedModNames) |
108 | setXMLString(xmlFile, key.."#name", HTMLUtil.encodeToHTML(self.name)) |
109 | end |
setName
DescriptionDefinitionsetName()Code
265 | function Dog:setName(name) |
266 | self.name = name or "" |
267 | end |
setVisibility
DescriptionDefinitionsetVisibility()Code
271 | function Dog:setVisibility(state) |
272 | setCompanionsVisibility(self.dogInstance, state) |
273 | setCompanionsPhysicsUpdate(self.dogInstance, state) |
274 | end |
teleportToSpawn
DescriptionDefinitionteleportToSpawn()Code
457 | function Dog:teleportToSpawn() |
458 | if self.isServer then |
459 | setCompanionPosition(self.dogInstance, self.animalId, self.spawnX, self.spawnY, self.spawnZ) |
460 | self:idleWander() |
461 | self:resetSteeringParms() |
462 | self.isStaying = false |
463 | self.entityFollow = nil |
464 | self.entityThrower = nil |
465 | if self.foodPending then |
466 | self.spawner:setFoodVisibility(false) |
467 | self.foodPending = false |
468 | end |
469 | -- TODO sync notification |
470 | g_currentMission:addIngameNotification(FSBaseMission.INGAME_NOTIFICATION_OK, g_i18n:getText("ingameNotification_dogInDogHouse")) |
471 | end |
472 | end |
testScope
DescriptionTest scopeDefinition
testScope(float x, float y, float z, float coeff)Arguments
float | x | x position |
float | y | y position |
float | z | z position |
float | coeff | coeff |
boolean | inScope | in scope |
217 | function Dog:testScope(x,y,z, coeff) |
218 | local distance, clipDistance = getCompanionClosestDistance(self.dogInstance, x, y, z) |
219 | local clipDist = math.min(clipDistance * coeff, self.forcedClipDistance) |
220 | |
221 | return distance < clipDist |
222 | end |
update
DescriptionUpdateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
180 | function Dog:update(dt) |
181 | -- companionDebugDraw(self.dogInstance, self.animalId, true, true, true) |
182 | |
183 | if self.isServer then |
184 | if self.isStaying and self:isAbandoned(dt) then |
185 | self:teleportToSpawn() |
186 | end |
187 | if self.foodPending and not getVisibility(self.spawner.foodNode) then |
188 | self.spawner:setFoodVisibility(false) |
189 | self.foodPending = false |
190 | end |
191 | -- The dog is always active |
192 | -- The only time when it could be disabled is when it is staying. But we don't care to optimize for that case |
193 | self:raiseActive() |
194 | end |
195 | Dog:superClass().update(self, dt) |
196 | end |
updateTick
DescriptionUpdate network tickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
201 | function Dog:updateTick(dt) |
202 | if self.isServer then |
203 | if getAnimalCompanionNeedNetworkUpdate(self.dogInstance) then |
204 | self:raiseDirtyFlags(self.dirtyFlag) |
205 | end |
206 | end |
207 | Dog:superClass().updateTick(self, dt) |
208 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
143 | function Dog:writeStream(streamId, connection) |
144 | if not connection:getIsServer() then |
145 | NetworkUtil.writeNodeObject(streamId, self.spawner) |
146 | streamWriteString(streamId, NetworkUtil.convertToNetworkFilename(self.xmlFilename)) |
147 | streamWriteFloat32(streamId, self.spawnX) |
148 | streamWriteFloat32(streamId, self.spawnY) |
149 | streamWriteFloat32(streamId, self.spawnZ) |
150 | streamWriteString(streamId, self.name) |
151 | end |
152 | Dog:superClass().writeStream(self, streamId, connection) |
153 | end |
writeUpdateStream
DescriptionWrite update network streamDefinition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | network stream identification |
table | connection | connection information |
integer | dirtyMask |
160 | function Dog:writeUpdateStream(streamId, connection, dirtyMask) |
161 | if not connection:getIsServer() then |
162 | writeAnimalCompanionManagerToStream(self.dogInstance, streamId) |
163 | end |
164 | end |