LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlaceableFarmhouse

Description
Specialization for placeables
Functions

farmhouseSleepingTriggerCallback

Description
Definition
farmhouseSleepingTriggerCallback()
Code
123function PlaceableFarmhouse:farmhouseSleepingTriggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
124 if onEnter or onLeave then
125 if g_currentMission.player ~= nil and otherActorId == g_currentMission.player.rootNode then
126 if onEnter then
127 g_currentMission.player:onEnterFarmhouse()
128 end
129
130 local spec = self.spec_farmhouse
131 if onEnter then
132 g_currentMission.activatableObjectsSystem:addActivatable(spec.activatable)
133 else
134 g_currentMission.activatableObjectsSystem:removeActivatable(spec.activatable)
135 end
136 end
137 end
138end

getSleepCamera

Description
Definition
getSleepCamera()
Code
117function PlaceableFarmhouse:getSleepCamera()
118 return self.spec_farmhouse.sleepingCamera
119end

getSpawnPoint

Description
Definition
getSpawnPoint()
Code
105function PlaceableFarmhouse:getSpawnPoint()
106 return self.spec_farmhouse.spawnNode
107end

getSpawnWorldPosition

Description
Definition
getSpawnWorldPosition()
Code
111function PlaceableFarmhouse:getSpawnWorldPosition()
112 return getWorldTranslation(self.spec_farmhouse.spawnNode)
113end

onDelete

Description
Definition
onDelete()
Code
91function PlaceableFarmhouse:onDelete()
92 local spec = self.spec_farmhouse
93
94 g_currentMission.activatableObjectsSystem:removeActivatable(spec.activatable)
95
96 g_currentMission.placeableSystem:removeFarmhouse(self)
97
98 if spec.sleepingTrigger ~= nil then
99 removeTrigger(spec.sleepingTrigger)
100 end
101end

onFinalizePlacement

Description
Definition
onFinalizePlacement()
Code
85function PlaceableFarmhouse:onFinalizePlacement()
86 g_currentMission.placeableSystem:addFarmhouse(self)
87end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
52function PlaceableFarmhouse:onLoad(savegame)
53 local spec = self.spec_farmhouse
54
55 spec.activatable = PlaceableFarmhouseActivatable.new(self)
56
57 spec.spawnNode = self.xmlFile:getValue("placeable.farmhouse#spawnNode", nil, self.components, self.i3dMappings)
58 if spec.spawnNode == nil then
59 Logging.xmlError(self.xmlFile, "No spawn node defined for farmhouse")
60 spec.spawnNode = self.rootNode
61 end
62
63 local sleepingTriggerKey = "placeable.farmhouse.sleeping#triggerNode"
64 spec.sleepingTrigger = self.xmlFile:getValue(sleepingTriggerKey, nil, self.components, self.i3dMappings)
65 if spec.sleepingTrigger ~= nil then
66 if not CollisionFlag.getHasFlagSet(spec.sleepingTrigger, CollisionFlag.TRIGGER_PLAYER) then
67 Logging.warning("%s sleep trigger '%s' does not have 'TRIGGER_PLAYER' bit (%s) set", self.configFileName, sleepingTriggerKey, CollisionFlag.getBit(CollisionFlag.TRIGGER_PLAYER))
68 end
69 addTrigger(spec.sleepingTrigger, "farmhouseSleepingTriggerCallback", self)
70 end
71
72 local cameraKey = "placeable.farmhouse.sleeping#cameraNode"
73 local camera = self.xmlFile:getValue(cameraKey, nil, self.components, self.i3dMappings)
74 if camera then
75 if getHasClassId(camera, ClassIds.CAMERA) then
76 spec.sleepingCamera = camera
77 else
78 Logging.xmlError(self.xmlFile, "Sleeping camera node '%s' (%s) is not a camera!", getName(camera), cameraKey)
79 end
80 end
81end

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
18function PlaceableFarmhouse.prerequisitesPresent(specializations)
19 return true
20end

registerEventListeners

Description
Definition
registerEventListeners()
Code
33function PlaceableFarmhouse.registerEventListeners(placeableType)
34 SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableFarmhouse)
35 SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableFarmhouse)
36 SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableFarmhouse)
37end

registerFunctions

Description
Definition
registerFunctions()
Code
24function PlaceableFarmhouse.registerFunctions(placeableType)
25 SpecializationUtil.registerFunction(placeableType, "farmhouseSleepingTriggerCallback", PlaceableFarmhouse.farmhouseSleepingTriggerCallback)
26 SpecializationUtil.registerFunction(placeableType, "getSleepCamera", PlaceableFarmhouse.getSleepCamera)
27 SpecializationUtil.registerFunction(placeableType, "getSpawnWorldPosition", PlaceableFarmhouse.getSpawnWorldPosition)
28 SpecializationUtil.registerFunction(placeableType, "getSpawnPoint", PlaceableFarmhouse.getSpawnPoint)
29end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
41function PlaceableFarmhouse.registerXMLPaths(schema, basePath)
42 schema:setXMLSpecializationType("Farmhouse")
43 schema:register(XMLValueType.NODE_INDEX, basePath .. ".farmhouse#spawnNode", "Player spawn node")
44 schema:register(XMLValueType.NODE_INDEX, basePath .. ".farmhouse.sleeping#triggerNode", "Sleeping trigger")
45 schema:register(XMLValueType.NODE_INDEX, basePath .. ".farmhouse.sleeping#cameraNode", "Camera while sleeping")
46 schema:setXMLSpecializationType()
47end