LUADOC - Farming Simulator 19

WoodSellStationPlaceable

Parent
Placeable
Functions

addUpdateEventListener

Description
Add listener to update listeners
Definition
addUpdateEventListener()
Code
207function WoodSellStationPlaceable:addUpdateEventListener(listener)
208 if listener ~= nil then
209 self.updateEventListeners[listener] = listener
210 end
211end

delete

Description
Deleting trigger
Definition
delete()
Code
38function WoodSellStationPlaceable:delete()
39 if self.mapHotspot ~= nil then
40 g_currentMission:removeMapHotspot(self.mapHotspot)
41 self.mapHotspot:delete()
42 end
43
44 if self.woodSellTrigger ~= nil then
45 removeTrigger(self.woodSellTrigger)
46 self.woodSellTrigger = nil
47 end
48
49 if self.sellTrigger ~= nil then
50 g_currentMission:removeActivatableObject(self)
51 removeTrigger(self.sellTrigger)
52 self.sellTrigger = nil
53 end
54
55 unregisterObjectClassName(self)
56 WoodSellStationPlaceable:superClass().delete(self)
57end

getIsActivatable

Description
Returns true if wood can be sold
Definition
getIsActivatable()
Return Values
booleanisActivateableis activateable
Code
277function WoodSellStationPlaceable:getIsActivatable()
278 return g_currentMission.controlPlayer
279end

load

Description
Load woodsell station
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
70function WoodSellStationPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
71 if not WoodSellStationPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
72 return false
73 end
74
75 local xmlFile = loadXMLFile("TempXML", xmlFilename)
76
77 self.appearsOnPDA = Utils.getNoNil(getXMLBool(xmlFile, "placeable.woodSellStation#appearsOnPDA"), false)
78 local rawName = Utils.getNoNil(getXMLString(xmlFile, "placeable.woodSellStation#stationName"), "WoodSellStation")
79 self.stationName = g_i18n:convertText(rawName) -- returns input if it cannot be resolved
80
81 local woodSellTrigger = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.woodSellStation#triggerNode"))
82 if woodSellTrigger == nil then
83 g_logManager:xmlWarning(xmlFilename, "Missing wood trigger node in 'placeable.woodSellStation#triggerNode'!")
84 delete(xmlFile)
85 return false
86 end
87
88 local colMask = getCollisionMask(woodSellTrigger)
89 if bitAND(SplitTypeManager.COLLISIONMASK_TRIGGER, colMask) == 0 then
90 g_logManager:xmlWarning(xmlFilename, "Invalid collision mask for wood trigger 'placeable.woodSellStation#triggerNode'. Bit 24 needs to be set!")
91 delete(xmlFile)
92 return false
93 end
94
95 addTrigger(woodSellTrigger, "woodTriggerCallback", self)
96 self.woodSellTrigger = woodSellTrigger
97
98
99 local sellTrigger = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.woodSellStation#sellTrigger"))
100 if sellTrigger == nil then
101 g_logManager:xmlWarning(xmlFilename, "Missing sell trigger in 'placeable.woodSellStation#sellTrigger'!")
102 delete(xmlFile)
103 return false
104 end
105
106 colMask = getCollisionMask(sellTrigger)
107 if bitAND(Player.COLLISIONMASK_TRIGGER, colMask) == 0 then
108 g_logManager:xmlWarning(xmlFilename, "Invalid collision mask for sell trigger 'placeable.woodSellStation#triggerNode'. Bit 20 needs to be set!")
109 delete(xmlFile)
110 return false
111 end
112
113 if self.appearsOnPDA then
114 local mapPosition = self.woodSellTrigger
115 local mapPositionIndex = getUserAttribute(self.woodSellTrigger, "mapPositionIndex")
116 if mapPositionIndex ~= nil then
117 mapPosition = I3DUtil.indexToObject(self.woodSellTrigger, mapPositionIndex)
118 if mapPosition == nil then
119 mapPosition = self.woodSellTrigger
120 end
121 end
122 local filenames = nil
123 local imageUVs = getNormalizedUVs(MapHotspot.UV.SELLING_POINT)
124 local x, _, z = getWorldTranslation(mapPosition)
125
126 local hotspotTextOffset = Utils.getNoNil(getXMLString(xmlFile, "placeable.woodSellStation#hotspotTextOffset"), "0px 0px")
127
128 self.mapHotspot = MapHotspot:new("woodSellStation", MapHotspot.CATEGORY_TRIGGER)
129 self.mapHotspot:setText(self.stationName)
130 self.mapHotspot:setBorderedImage(nil, imageUVs, {0.9559, 0.5647, 0.0423, 1})
131 self.mapHotspot:setTextOptions(nil, nil, nil, {0.9559, 0.5647, 0.0423, 1})
132 self.mapHotspot:setWorldPosition(x, z)
133 self.mapHotspot:setRawTextOffset(hotspotTextOffset)
134
135 g_currentMission:addMapHotspot(self.mapHotspot)
136 end
137
138 addTrigger(sellTrigger, "woodSellTriggerCallback", self)
139 self.sellTrigger = sellTrigger
140
141 self.activateText = g_i18n:getText("action_sellWood")
142 self.objectActivated = false
143
144 self.updateEventListeners = {}
145
146 delete(xmlFile)
147
148 return true
149end

new

Description
Creating woodsell station
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
26function WoodSellStationPlaceable:new(isServer, isClient, customMt)
27 local self = Placeable:new(isServer, isClient, customMt or WoodSellStationPlaceable_mt)
28
29 registerObjectClassName(self, "WoodSellStationPlaceable")
30
31 self.woodInTrigger = {}
32
33 return self
34end

onActivateObject

Description
Called on activate object
Definition
onActivateObject()
Code
287function WoodSellStationPlaceable:onActivateObject()
288 g_currentMission:addActivatableObject(self)
289 self.objectActivated = true
290 self:sellWood(g_currentMission:getFarmId())
291end

removeUpdateEventListener

Description
Remove listener from update listeners
Definition
removeUpdateEventListener()
Code
215function WoodSellStationPlaceable:removeUpdateEventListener(listener)
216 if listener ~= nil then
217 self.updateEventListeners[listener] = nil
218 end
219end