LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlaceableInfoTrigger

Description
Specialization for placeables
Functions

onDelete

Description
Definition
onDelete()
Code
75function PlaceableInfoTrigger:onDelete()
76 local spec = self.spec_infoTrigger
77
78 if spec.infoTrigger ~= nil then
79 removeTrigger(spec.infoTrigger)
80 spec.infoTrigger = nil
81 end
82
83 spec.showInfo = false
84 g_currentMission:removeDrawable(self)
85
86 if spec.hudBox ~= nil then
87 g_currentMission.hud.infoDisplay:destroyBox(spec.hudBox)
88 end
89end

onDraw

Description
Definition
onDraw()
Code
102function PlaceableInfoTrigger:onDraw()
103 local spec = self.spec_infoTrigger
104 if spec.showInfo then
105 if spec.showAllPlayers or self:getOwnerFarmId() == g_currentMission:getFarmId() then
106 -- Gather info
107 self:updateInfo(spec.info)
108
109 if #spec.info > 0 then
110 local box = spec.hudBox
111 box:clear()
112 box:setTitle(self:getName())
113
114 for i = 1, #spec.info do
115 local element = spec.info[i]
116
117 box:addLine(element.title, element.text, element.accentuate)
118
119 spec.info[i] = nil
120 end
121
122 box:showNextFrame()
123 end
124 end
125 end
126end

onFinalizePlacement

Description
Definition
onFinalizePlacement()
Code
93function PlaceableInfoTrigger:onFinalizePlacement()
94 local spec = self.spec_infoTrigger
95 if spec.infoTrigger ~= nil then
96 addTrigger(spec.infoTrigger, "onInfoTriggerCallback", self)
97 end
98end

onInfoTriggerCallback

Description
Definition
onInfoTriggerCallback()
Code
130function PlaceableInfoTrigger:onInfoTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
131 local spec = self.spec_infoTrigger
132 if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then
133 if onEnter then
134 spec.showInfo = true
135 g_currentMission:addDrawable(self)
136 SpecializationUtil.raiseEvent(self, "onInfoTriggerEnter", otherId)
137
138 else
139 spec.showInfo = false
140 g_currentMission:removeDrawable(self)
141 SpecializationUtil.raiseEvent(self, "onInfoTriggerLeave", otherId)
142 end
143 end
144end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
57function PlaceableInfoTrigger:onLoad(savegame)
58 local spec = self.spec_infoTrigger
59
60 spec.info = {}
61 spec.showInfo = false
62 spec.showAllPlayers = self.xmlFile:getValue("placeable.infoTrigger#showAllPlayers", false)
63 spec.infoTrigger = self.xmlFile:getValue("placeable.infoTrigger#triggerNode", nil, self.components, self.i3dMappings)
64 if spec.infoTrigger ~= nil then
65 if not CollisionFlag.getHasFlagSet(spec.infoTrigger, CollisionFlag.TRIGGER_PLAYER) then
66 Logging.xmlWarning(self.xmlFile, "Info trigger collison mask is missing bit 'TRIGGER_PLAYER' (%d)", CollisionFlag.getBit(CollisionFlag.TRIGGER_PLAYER))
67 end
68 end
69
70 spec.hudBox = g_currentMission.hud.infoDisplay:createBox(KeyValueInfoHUDBox)
71end

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 PlaceableInfoTrigger.prerequisitesPresent(specializations)
19 return true
20end

registerEventListeners

Description
Definition
registerEventListeners()
Code
31function PlaceableInfoTrigger.registerEventListeners(placeableType)
32 SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableInfoTrigger)
33 SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableInfoTrigger)
34 SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", PlaceableInfoTrigger)
35 SpecializationUtil.registerEventListener(placeableType, "onDraw", PlaceableInfoTrigger)
36end

registerEvents

Description
Definition
registerEvents()
Code
24function PlaceableInfoTrigger.registerEvents(placeableType)
25 SpecializationUtil.registerEvent(placeableType, "onInfoTriggerEnter")
26 SpecializationUtil.registerEvent(placeableType, "onInfoTriggerLeave")
27end

registerFunctions

Description
Definition
registerFunctions()
Code
40function PlaceableInfoTrigger.registerFunctions(placeableType)
41 SpecializationUtil.registerFunction(placeableType, "updateInfo", PlaceableInfoTrigger.updateInfo)
42 SpecializationUtil.registerFunction(placeableType, "onInfoTriggerCallback", PlaceableInfoTrigger.onInfoTriggerCallback)
43end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
47function PlaceableInfoTrigger.registerXMLPaths(schema, basePath)
48 schema:setXMLSpecializationType("InfoTrigger")
49 schema:register(XMLValueType.NODE_INDEX, basePath .. ".infoTrigger#triggerNode", "Info trigger", nil, false)
50 schema:register(XMLValueType.BOOL, basePath .. ".infoTrigger#showAllPlayers", "Show info to all players", false, false)
51 schema:setXMLSpecializationType()
52end

updateInfo

Description
Definition
updateInfo()
Code
148function PlaceableInfoTrigger:updateInfo(info)
149end