LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlaceableHotspots

Description
Specialization for placeables
Functions

getHotspot

Description
Definition
getHotspot()
Code
145function PlaceableHotspots:getHotspot(index)
146 local spec = self.spec_hotspots
147 return spec.mapHotspots[index or 1]
148end

onDelete

Description
Definition
onDelete()
Code
106function PlaceableHotspots:onDelete()
107 local spec = self.spec_hotspots
108
109 g_messageCenter:unsubscribeAll(self)
110 if spec.mapHotspots ~= nil then
111 for _, hotspot in ipairs(spec.mapHotspots) do
112 g_currentMission:removeMapHotspot(hotspot)
113 hotspot:delete()
114 end
115 end
116end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
53function PlaceableHotspots:onLoad(savegame)
54 local spec = self.spec_hotspots
55
56 spec.mapHotspots = {}
57 self.xmlFile:iterate("placeable.hotspots.hotspot", function(_, key)
58 local hotspot = PlaceableHotspot.new()
59 hotspot:setPlaceable(self)
60
61 local hotspotTypeName = self.xmlFile:getValue(key .. "#type", "UNLOADING")
62 local hotspotType = PlaceableHotspot.getTypeByName(hotspotTypeName)
63 if hotspotType == nil then
64 Logging.xmlWarning(self.xmlFile, "Unknown placeable hotspot type '%s'. Falling back to type 'UNLOADING'\nAvailable types: %s", hotspotTypeName, table.concatKeys(PlaceableHotspot.TYPE, " "))
65 hotspotType = PlaceableHotspot.TYPE.UNLOADING
66 end
67 hotspot:setPlaceableType(hotspotType)
68
69 local linkNode = self.xmlFile:getValue(key .. "#linkNode", nil, self.components, self.i3dMappings) or self.rootNode
70 if linkNode ~= nil then
71 local x, _, z = getWorldTranslation(linkNode)
72 hotspot:setWorldPosition(x, z)
73 end
74
75 local teleportNode = self.xmlFile:getValue(key .. "#teleportNode", nil, self.components, self.i3dMappings)
76 if teleportNode ~= nil then
77 local x, y, z = getWorldTranslation(teleportNode)
78 hotspot:setTeleportWorldPosition(x, y, z)
79 end
80
81 local worldPositionX, worldPositionZ = self.xmlFile:getValue(key .. "#worldPosition", nil)
82 if worldPositionX ~= nil then
83 hotspot:setWorldPosition(worldPositionX, worldPositionZ)
84 end
85
86 local teleportX, teleportY, teleportZ = self.xmlFile:getValue(key .. "#teleportWorldPosition", nil)
87 if teleportX ~= nil then
88 if g_currentMission ~= nil then
89 teleportY = math.max(teleportY, getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, teleportX, 0, teleportZ))
90 end
91 hotspot:setTeleportWorldPosition(teleportX, teleportY, teleportZ)
92 end
93
94 local text = self.xmlFile:getValue(key.."#text", nil)
95 if text ~= nil then
96 text = g_i18n:convertText(text, self.customEnvironment)
97 hotspot:setName(text)
98 end
99
100 table.insert(spec.mapHotspots, hotspot)
101 end)
102end

onOwnerChanged

Description
Definition
onOwnerChanged()
Code
133function PlaceableHotspots:onOwnerChanged()
134 local spec = self.spec_hotspots
135 if spec.mapHotspots ~= nil then
136 for _, hotspot in ipairs(spec.mapHotspots) do
137 hotspot:setOwnerFarmId(self.ownerFarmId)
138 hotspot:setVisible(self.ownerFarmId ~= AccessHandler.NOBODY)
139 end
140 end
141end

onPostFinalizePlacement

Description
Definition
onPostFinalizePlacement()
Code
120function PlaceableHotspots:onPostFinalizePlacement()
121 local spec = self.spec_hotspots
122
123 -- Add now so that the hotspot does not show up during placement
124 for _, hotspot in ipairs(spec.mapHotspots) do
125 hotspot:setOwnerFarmId(self.ownerFarmId)
126 hotspot:setVisible(self.ownerFarmId ~= AccessHandler.NOBODY)
127 g_currentMission:addMapHotspot(hotspot)
128 end
129end

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

registerEventListeners

Description
Definition
registerEventListeners()
Code
30function PlaceableHotspots.registerEventListeners(placeableType)
31 SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableHotspots)
32 SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableHotspots)
33 SpecializationUtil.registerEventListener(placeableType, "onPostFinalizePlacement", PlaceableHotspots)
34 SpecializationUtil.registerEventListener(placeableType, "onOwnerChanged", PlaceableHotspots)
35end

registerFunctions

Description
Definition
registerFunctions()
Code
24function PlaceableHotspots.registerFunctions(placeableType)
25 SpecializationUtil.registerFunction(placeableType, "getHotspot", PlaceableHotspots.getHotspot)
26end

registerXMLPaths

Description
Definition
registerXMLPaths()
Code
39function PlaceableHotspots.registerXMLPaths(schema, basePath)
40 schema:setXMLSpecializationType("Hotspots")
41 schema:register(XMLValueType.NODE_INDEX, basePath .. ".hotspots.hotspot(?)#linkNode", "Node where hotspot is linked to")
42 schema:register(XMLValueType.NODE_INDEX, basePath .. ".hotspots.hotspot(?)#teleportNode", "Node where player is teleported to. Teleporting is only available if this is set")
43 schema:register(XMLValueType.STRING, basePath .. ".hotspots.hotspot(?)#type", "Placeable hotspot type")
44 schema:register(XMLValueType.VECTOR_2, basePath .. ".hotspots.hotspot(?)#worldPosition", "Placeable world position")
45 schema:register(XMLValueType.VECTOR_3, basePath .. ".hotspots.hotspot(?)#teleportWorldPosition", "Placeable teleport world position")
46 schema:register(XMLValueType.STRING, basePath .. ".hotspots.hotspot(?)#text", "Placeable hotspot text")
47 schema:setXMLSpecializationType()
48end