Script v1.4.4.0
Engine v7.0.0.2
- General
- Entity
- Node
- Scenegraph
- Lighting
- Camera
- Shape
- Particle System
- Physics
- Spline
- Animation
- Overlays
- Sound
- Input
- XML
- Network
- Callbacks
- Text Rendering
- Terrain Detail
- Tire Track
- Editor
- Rendering
- String
- Math
- I3D
- Fillplanes
Foundation Reference
FillablePallet
DescriptionClass for fillable palletsParent
MountableObjectFunctions
- new
- delete
- getAllowsAutoDelete
- readStream
- writeStream
- readUpdateStream
- writeUpdateStream
- mount
- unmount
- setNodeId
- createNode
- load
- loadObjectXML
- loadFromMemory
- loadFromAttributesAndNodes
- getSaveAttributesAndNodes
- getValue
- update
- updateTick
- getFillType
- setFillLevel
- fillableObjectRaycastCallback
- getFillLevel
- getCapacity
- getMeshNodes
- fillableTriggerCallback
new
DescriptionCreating fillable palletDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | customMt |
table | instance | Instance of object |
23 | function FillablePallet:new(isServer, isClient, customMt) |
24 | local mt = customMt; |
25 | if mt == nil then |
26 | mt = FillablePallet_mt; |
27 | end; |
28 | |
29 | local self = MountableObject:new(isServer, isClient, mt); |
30 | |
31 | self.forcedClipDistance = 150; |
32 | registerObjectClassName(self, "FillablePallet"); |
33 | |
34 | self.fillType = FillUtil.FILLTYPE_STRAW; |
35 | self.fillLevel = 0; |
36 | self.capacity = 2000; |
37 | self.fillablePalletValueScale = 0; |
38 | self.isReferenced = false; |
39 | self.synchronizeFillLevel = true; |
40 | self.updateUnloadingEffects = false; |
41 | |
42 | self.fillablePalletDirtyFlag = self:getNextDirtyFlag(); |
43 | self.syncEffectDirtyFlag = self:getNextDirtyFlag(); |
44 | |
45 | g_currentMission:addLimitedObject(FSBaseMission.LIMITED_OBJECT_TYPE_PALLET, self); |
46 | |
47 | return self; |
48 | end; |
delete
DescriptionDelete fillable palletDefinition
delete()Code
52 | function FillablePallet:delete() |
53 | if self.isClient and self.unloadingEffects ~= nil then |
54 | EffectManager:deleteEffects(self.unloadingEffects); |
55 | end; |
56 | if self.fillTrigger ~= nil then |
57 | self.fillTrigger:delete(); |
58 | self.fillTrigger = nil; |
59 | end; |
60 | if self.i3dFilename ~= nil then |
61 | Utils.releaseSharedI3DFile(self.i3dFilename, nil, true); |
62 | end |
63 | g_currentMission:removeLimitedObject(FSBaseMission.LIMITED_OBJECT_TYPE_PALLET, self); |
64 | unregisterObjectClassName(self); |
65 | g_currentMission:removeItemToSave(self); |
66 | if self.fillableTriggerNode ~= nil then |
67 | removeTrigger(self.fillableTriggerNode); |
68 | end |
69 | FillablePallet:superClass().delete(self); |
70 | end; |
getAllowsAutoDelete
DescriptionGet allows auto deleteDefinition
getAllowsAutoDelete()Return Values
boolean | allowsAutoDelete | allows auto delete |
75 | function FillablePallet:getAllowsAutoDelete() |
76 | return not self.isReferenced and FillablePallet:superClass().getAllowsAutoDelete(self); |
77 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
83 | function FillablePallet:readStream(streamId, connection) |
84 | local i3dFilename = Utils.convertFromNetworkFilename(streamReadString(streamId)); |
85 | local xmlFilename; |
86 | if streamReadBool(streamId) then |
87 | xmlFilename = Utils.convertFromNetworkFilename(streamReadString(streamId)); |
88 | end |
89 | if self.nodeId == 0 then |
90 | self:createNode(i3dFilename, xmlFilename); |
91 | end; |
92 | local fillLevel = nil; |
93 | if self.synchronizeFillLevel then |
94 | fillLevel = streamReadUIntN(streamId, 15)/32767*self.capacity; |
95 | end; |
96 | |
97 | FillablePallet:superClass().readStream(self, streamId, connection); |
98 | g_currentMission:addItemToSave(self); |
99 | |
100 | if self.synchronizeFillLevel then |
101 | self:setFillLevel(fillLevel, false); |
102 | end; |
103 | end; |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
109 | function FillablePallet:writeStream(streamId, connection) |
110 | streamWriteString(streamId, Utils.convertToNetworkFilename(self.i3dFilename)); |
111 | if streamWriteBool(streamId, self.xmlFilename ~= nil) then |
112 | streamWriteString(streamId, Utils.convertToNetworkFilename(self.xmlFilename)); |
113 | end |
114 | |
115 | if self.synchronizeFillLevel then |
116 | local percent = 0; |
117 | if self.capacity ~= 0 then |
118 | percent = Utils.clamp(self.fillLevel / self.capacity, 0, 1); |
119 | end |
120 | streamWriteUIntN(streamId, math.floor(percent*32767), 15); |
121 | end; |
122 | FillablePallet:superClass().writeStream(self, streamId, connection); |
123 | end; |
readUpdateStream
DescriptionCalled on client side on updateDefinition
readUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | stream ID |
integer | timestamp | timestamp |
table | connection | connection |
130 | function FillablePallet:readUpdateStream(streamId, timestamp, connection) |
131 | if connection:getIsServer() then |
132 | if self.synchronizeFillLevel then |
133 | if streamReadBool(streamId) then |
134 | local fillLevel = streamReadUIntN(streamId, 15)/32767*self.capacity; |
135 | self:setFillLevel(fillLevel, false); |
136 | end |
137 | end; |
138 | |
139 | if streamReadBool(streamId) then |
140 | local raycastDistance = streamReadUIntN(streamId, 11); |
141 | self.currentRaycastDistance = raycastDistance/100; |
142 | else |
143 | self.currentRaycastDistance = 0; |
144 | end; |
145 | end; |
146 | |
147 | FillablePallet:superClass().readUpdateStream(self, streamId, timestamp, connection); |
148 | end; |
writeUpdateStream
DescriptionCalled on server side on updateDefinition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | stream ID |
table | connection | connection |
integer | dirtyMask | dirty mask |
155 | function FillablePallet:writeUpdateStream(streamId, connection, dirtyMask) |
156 | if not connection:getIsServer() then |
157 | if self.synchronizeFillLevel then |
158 | if streamWriteBool(streamId, bitAND(dirtyMask, self.fillablePalletDirtyFlag) ~= 0) then |
159 | local percent = 0; |
160 | if self.capacity ~= 0 then |
161 | percent = Utils.clamp(self.fillLevel / self.capacity, 0, 1); |
162 | end |
163 | streamWriteUIntN(streamId, math.floor(percent*32767), 15); |
164 | end |
165 | end; |
166 | |
167 | if streamWriteBool(streamId, bitAND(dirtyMask, self.syncEffectDirtyFlag) ~= 0) then |
168 | streamWriteUIntN(streamId, math.floor(math.min(self.currentRaycastDistance*100, 2048)), 11); |
169 | end; |
170 | end; |
171 | |
172 | FillablePallet:superClass().writeUpdateStream(self, streamId, connection, dirtyMask); |
173 | end; |
mount
DescriptionMount pallet to objectDefinition
mount(table object, integer node, float x, float y, float z, float rx, float ry, float rz)Arguments
table | object | target object |
integer | node | target node id |
float | x | x position |
float | y | z position |
float | z | z position |
float | rx | rx rotation |
float | ry | ry rotation |
float | rz | rz rotation |
185 | function FillablePallet:mount(object, node, x,y,z, rx,ry,rz) |
186 | g_currentMission:removeItemToSave(self); |
187 | FillablePallet:superClass().mount(self, object, node, x,y,z, rx,ry,rz); |
188 | end; |
unmount
DescriptionUnmount palletDefinition
unmount()Return Values
boolean | success | success |
193 | function FillablePallet:unmount() |
194 | if FillablePallet:superClass().unmount(self) then |
195 | g_currentMission:addItemToSave(self); |
196 | return true; |
197 | end |
198 | return false; |
199 | end; |
setNodeId
DescriptionSet node idDefinition
setNodeId(integer nodeId)Arguments
integer | nodeId | node Id |
204 | function FillablePallet:setNodeId(nodeId) |
205 | FillablePallet:superClass().setNodeId(self, nodeId); |
206 | |
207 | self.capacity = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "capacity")), self.capacity); |
208 | self.fillablePalletValueScale = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "fillablePalletValueScale")), 1); |
209 | |
210 | self.fillType = FillUtil.FILLTYPE_WOOL; |
211 | local fillTypeStr = getUserAttribute(nodeId, "fillType"); |
212 | if fillTypeStr ~= nil then |
213 | local fillTypeInt = FillUtil.fillTypeNameToInt[fillTypeStr]; |
214 | if fillTypeInt ~= nil then |
215 | self.fillType = fillTypeInt; |
216 | end |
217 | end |
218 | |
219 | self.visibilityNodes = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "visibilityNodesIndex")); |
220 | self.visibilityNodesAdditive = Utils.getNoNil(getUserAttribute(nodeId, "visibilityNodesAdditive"), false); |
221 | |
222 | self.iconNode = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "iconNode")); |
223 | self.iconColor = Utils.getVectorNFromString(Utils.getNoNil(getUserAttribute(nodeId, "iconColor"), "0 0 0 1"), 4); |
224 | |
225 | self.movingPlane = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "movingPlane")); |
226 | self.movingPlaneMinY = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "movingPlaneMinY")), 0); |
227 | self.movingPlaneMaxY = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "movingPlaneMaxY")), 1); |
228 | |
229 | local meshNodeIndices = getUserAttribute(nodeId, "meshNodes") |
230 | if meshNodeIndices ~= nil then |
231 | local meshNodeIndicesStr = Utils.splitString(" ", meshNodeIndices) |
232 | local meshNodes = {} |
233 | for _, index in pairs(meshNodeIndicesStr) do |
234 | local node = Utils.indexToObject(nodeId, index); |
235 | if node ~= nil then |
236 | table.insert(meshNodes, node) |
237 | end |
238 | end |
239 | if #meshNodes > 0 then |
240 | self.meshNodes = meshNodes |
241 | end |
242 | end |
243 | self.meshNodesAddVisibleChildren = Utils.getNoNil(getUserAttribute(nodeId, "meshNodesAddVisibleChildren"), false) |
244 | |
245 | self.raycastNode = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "raycastNode")); |
246 | self.raycastDistance = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "raycastDistance")), 5); |
247 | self.currentRaycastDistance = 0; |
248 | |
249 | self.fillLevel = -1; |
250 | self:setFillLevel(Utils.getNoNil(tonumber(getUserAttribute(nodeId, "startFillLevel")), 0), false); |
251 | |
252 | self.fillTriggerNode = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "fillTrigger")); |
253 | if self.fillTriggerNode ~= nil then |
254 | local fillClass = getUserAttribute(nodeId, "fillTriggerClass"); |
255 | local fillTriggerClass = nil; |
256 | if fillClass ~= nil then |
257 | fillTriggerClass = getClassObject(fillClass); |
258 | end; |
259 | |
260 | if fillTriggerClass ~= nil then |
261 | self.fillTrigger = fillTriggerClass:new(); |
262 | if not self.fillTrigger:load(self.fillTriggerNode, self.fillType, self) then |
263 | self.fillTrigger:delete(); |
264 | self.fillTrigger = nil; |
265 | end |
266 | else |
267 | print("Warning: fillTriggerClass '"..tostring(fillClass).."' not found!"); |
268 | end; |
269 | end; |
270 | |
271 | self.fillableTriggerNode = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "fillableTrigger")); |
272 | if self.isServer and self.fillableTriggerNode ~= nil then |
273 | addTrigger(self.fillableTriggerNode, "fillableTriggerCallback", self); |
274 | end |
275 | self.fillablePalletUnloadSpeed = Utils.getNoNil(getUserAttribute(nodeId, "fillablePalletUnloadSpeed"), 200)*0.001; |
276 | self.fillableObjects = {}; |
277 | |
278 | if self.fillableTriggerNode ~= nil then |
279 | local node = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "fillableTriggerDischargeInfoNode")); |
280 | if node ~= nil then |
281 | self.fillableDischargeInfo = {}; |
282 | self.fillableDischargeInfo.nodes = {}; |
283 | local x,_,z = getTranslation(node); |
284 | table.insert(self.fillableDischargeInfo.nodes, {priority=1, node=node, width=2*x, length=2*z}); |
285 | end |
286 | end |
287 | |
288 | self.deletePalletIfEmpty = Utils.getNoNil(getUserAttribute(nodeId, "deletePalletIfEmpty"), true); |
289 | self.fillWasNotZero = false; |
290 | end; |
createNode
DescriptionLoad node from i3d fileDefinition
createNode(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
295 | function FillablePallet:createNode(i3dFilename, xmlFilename) |
296 | local xmlFile; |
297 | if xmlFilename ~= nil then |
298 | self.xmlFilename = xmlFilename; |
299 | xmlFile = loadXMLFile("tempObjectXML", self.xmlFilename); |
300 | |
301 | i3dFilename = getXMLString(xmlFile, "object.filename"); |
302 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(xmlFilename); |
303 | i3dFilename = Utils.getFilename(i3dFilename, self.baseDirectory); |
304 | else |
305 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
306 | end; |
307 | |
308 | self.i3dFilename = i3dFilename; |
309 | local fillablePalletRoot = Utils.loadSharedI3DFile(i3dFilename); |
310 | |
311 | local fillablePalletId = getChildAt(fillablePalletRoot, 0); |
312 | link(getRootNode(), fillablePalletId); |
313 | delete(fillablePalletRoot); |
314 | |
315 | self:setNodeId(fillablePalletId); |
316 | |
317 | if xmlFile ~= nil then |
318 | FillablePallet.loadObjectXML(self, xmlFile) |
319 | delete(xmlFile); |
320 | end; |
321 | end; |
load
DescriptionLoad palletDefinition
load(string i3dFilename, float x, float y, float z, float rx, float ry, float rz, string xmlFilename)Arguments
string | i3dFilename | i3d file name |
float | x | x world position |
float | y | z world position |
float | z | z world position |
float | rx | rx world rotation |
float | ry | ry world rotation |
float | rz | rz world rotation |
string | xmlFilename | xml file name |
boolean | success | success |
334 | function FillablePallet:load(i3dFilename, x,y,z, rx,ry,rz, xmlFilename) |
335 | self.i3dFilename = i3dFilename; |
336 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
337 | self:createNode(i3dFilename, xmlFilename); |
338 | setTranslation(self.nodeId, x, y, z); |
339 | setRotation(self.nodeId, rx, ry, rz); |
340 | |
341 | g_currentMission:addItemToSave(self); |
342 | return true; |
343 | end; |
loadObjectXML
DescriptionLoad xml parametersDefinition
loadObjectXML(integer xmlFile)Arguments
integer | xmlFile | id of xml object |
348 | function FillablePallet:loadObjectXML(xmlFile) |
349 | self.fillableObjectRaycastCallback = FillablePallet.fillableObjectRaycastCallback; |
350 | self.unloadingEffects = EffectManager:loadEffect(xmlFile, "object.unloadingEffects", self.nodeId, self); |
351 | self.unloadingEffectExtraDistance = getXMLFloat(xmlFile, "object.unloadingEffectExtraDistance#value"); |
352 | end; |
loadFromMemory
DescriptionSetting node id and i3d file nameDefinition
loadFromMemory(integer nodeId, string i3dFilename)Arguments
integer | nodeId | node id |
string | i3dFilename | i3d file name |
358 | function FillablePallet:loadFromMemory(nodeId, i3dFilename) |
359 | self.i3dFilename = i3dFilename; |
360 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(Utils.getNoNil(self.xmlFilename, i3dFilename)); |
361 | self:setNodeId(nodeId); |
362 | end; |
loadFromAttributesAndNodes
DescriptionLoading from attributes and nodesDefinition
loadFromAttributesAndNodes(integer xmlFile, string key, boolean resetVehicles)Arguments
integer | xmlFile | id of xml object |
string | key | key |
boolean | resetVehicles | reset vehicles |
boolean | success | success |
370 | function FillablePallet:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) |
371 | |
372 | local x,y,z = Utils.getVectorFromString(getXMLString(xmlFile, key.."#position")); |
373 | local xRot,yRot,zRot = Utils.getVectorFromString(getXMLString(xmlFile, key.."#rotation")); |
374 | if x == nil or y == nil or z == nil or xRot == nil or yRot == nil or zRot == nil then |
375 | return false; |
376 | end; |
377 | |
378 | local i3dFilename; |
379 | local objectXMLFile; |
380 | |
381 | self.xmlFilename = getXMLString(xmlFile, key.."#filename"); |
382 | if self.xmlFilename ~= nil then |
383 | self.xmlFilename = Utils.convertFromNetworkFilename(self.xmlFilename); |
384 | objectXMLFile = loadXMLFile("tempObjectXML", self.xmlFilename); |
385 | i3dFilename = getXMLString(objectXMLFile, "object.filename"); |
386 | if i3dFilename == nil then |
387 | delete(objectXMLFile); |
388 | return false; |
389 | end; |
390 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(self.xmlFilename); |
391 | i3dFilename = Utils.getFilename(i3dFilename, self.baseDirectory); |
392 | else |
393 | i3dFilename = getXMLString(xmlFile, key.."#i3dFilename"); |
394 | if i3dFilename == nil then |
395 | return false; |
396 | end; |
397 | i3dFilename = Utils.convertFromNetworkFilename(i3dFilename); |
398 | end; |
399 | |
400 | local rootNode = Utils.loadSharedI3DFile(i3dFilename); |
401 | if rootNode == 0 then |
402 | if objectXMLFile ~= nil then |
403 | delete(objectXMLFile); |
404 | end |
405 | return false; |
406 | end; |
407 | |
408 | local ret = false; |
409 | local node = getChildAt(rootNode, 0); |
410 | if node ~= nil and node ~= 0 then |
411 | setTranslation(node, x,y,z); |
412 | setRotation(node, xRot,yRot,zRot); |
413 | link(getRootNode(), node); |
414 | ret = true; |
415 | end; |
416 | delete(rootNode); |
417 | if not ret then |
418 | if objectXMLFile ~= nil then |
419 | delete(objectXMLFile); |
420 | end |
421 | return false; |
422 | end; |
423 | |
424 | self:loadFromMemory(node, i3dFilename); |
425 | |
426 | local fillLevel = getXMLFloat(xmlFile, key.."#fillLevel"); |
427 | if fillLevel ~= nil then |
428 | self.fillLevel = -1; |
429 | self:setFillLevel(fillLevel, false); |
430 | end |
431 | |
432 | if objectXMLFile ~= nil then |
433 | FillablePallet.loadObjectXML(self, objectXMLFile) |
434 | delete(objectXMLFile); |
435 | end; |
436 | |
437 | return true; |
438 | end; |
getSaveAttributesAndNodes
DescriptionGet save attributes and nodesDefinition
getSaveAttributesAndNodes(string nodeIdent)Arguments
string | nodeIdent | node ident |
string | attributes | attributes |
string | nodes | nodes |
445 | function FillablePallet:getSaveAttributesAndNodes(nodeIdent) |
446 | |
447 | local x,y,z = getTranslation(self.nodeId); |
448 | local xRot,yRot,zRot = getRotation(self.nodeId); |
449 | |
450 | local filename; |
451 | if self.xmlFilename ~= nil then |
452 | filename = 'filename="'.. Utils.encodeToHTML(Utils.convertToNetworkFilename(self.xmlFilename))..'"' |
453 | else |
454 | filename = 'i3dFilename="'.. Utils.encodeToHTML(Utils.convertToNetworkFilename(self.i3dFilename))..'"' |
455 | end; |
456 | |
457 | local attributes = filename..' position="'..x..' '..y..' '..z..'" rotation="'..xRot..' '..yRot..' '..zRot..'" fillLevel="'..self.fillLevel..'"'; |
458 | local nodes = ""; |
459 | return attributes, nodes; |
460 | end; |
getValue
DescriptionGet price value of palletDefinition
getValue()Return Values
integer | priceValue | price value |
465 | function FillablePallet:getValue() |
466 | local pricePerLiter = g_currentMission.economyManager:getPricePerLiter(self.fillType); |
467 | return self.fillLevel * pricePerLiter * self.fillablePalletValueScale; |
468 | end; |
update
DescriptionUpdateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
473 | function FillablePallet:update(dt) |
474 | FillablePallet:superClass().update(self, dt); |
475 | end |
updateTick
DescriptionupdateTickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
480 | function FillablePallet:updateTick(dt) |
481 | FillablePallet:superClass().updateTick(self, dt); |
482 | if self.baseMass == nil and self.isServer and self.updateTickRunOnce then |
483 | self.baseMass = getMass(self.nodeId); |
484 | self:setFillLevel(self.fillLevel) -- to update total mass |
485 | end |
486 | self.updateTickRunOnce = true; |
487 | |
488 | if self.fillableTriggerNode ~= nil then |
489 | local fillableObject = next(self.fillableObjects); |
490 | if fillableObject ~= nil then |
491 | if fillableObject.getAllowFillFromAir == nil or fillableObject:getAllowFillFromAir() then |
492 | local delta = self.fillablePalletUnloadSpeed * dt; |
493 | delta = math.min(delta, self:getFillLevel(), fillableObject:getCapacity(self.fillType) - fillableObject:getFillLevel(self.fillType)); |
494 | if delta > 0 then |
495 | fillableObject:setFillLevel(fillableObject:getFillLevel(self.fillType) + delta, self.fillType, nil, self.fillableDischargeInfo); |
496 | self:setFillLevel(self:getFillLevel() - delta); |
497 | end |
498 | end; |
499 | end |
500 | end |
501 | |
502 | if self.raycastNode ~= nil then |
503 | if self.isServer then |
504 | self.currentRaycastDistance = 0; |
505 | |
506 | if self.updateUnloadingEffects and next(self.fillableObjects) ~= nil then |
507 | local x,y,z = getWorldTranslation(self.raycastNode); |
508 | raycastClosest(x, y, z, 0,-1,0, "fillableObjectRaycastCallback", self.raycastDistance, self, 255); |
509 | |
510 | self.updateUnloadingEffects = false; |
511 | |
512 | if self.currentRaycastDistance ~= 0 then |
513 | self:raiseDirtyFlags(self.syncEffectDirtyFlag); |
514 | end; |
515 | end; |
516 | end; |
517 | |
518 | if self.currentRaycastDistance ~= 0 then |
519 | if self.unloadingEffects ~= nil then |
520 | EffectManager:setFillType(self.unloadingEffects, self:getFillType()) |
521 | EffectManager:startEffects(self.unloadingEffects) |
522 | for _, effect in pairs(self.unloadingEffects) do |
523 | if effect.setUnloadingDistance ~= nil then |
524 | effect:setUnloadingDistance(self.currentRaycastDistance+self.unloadingEffectExtraDistance, g_currentMission.terrainRootNode) |
525 | end |
526 | end |
527 | end |
528 | else |
529 | if self.unloadingEffects ~= nil then |
530 | EffectManager:stopEffects(self.unloadingEffects); |
531 | end |
532 | end; |
533 | end; |
534 | |
535 | if self.isServer and self.deletePalletIfEmpty and self.fillWasNotZero then |
536 | if self.fillLevel < FillablePallet.fillLevelThresholdForDeletion then |
537 | self:delete(); |
538 | end |
539 | end |
540 | end |
getFillType
DescriptionGet fill type of palletDefinition
getFillType()Return Values
integer | fillType | current fill type id |
545 | function FillablePallet:getFillType() |
546 | return self.fillType; |
547 | end; |
setFillLevel
DescriptionSet fill level of palletDefinition
setFillLevel(integer fillLevel, boolean setDirty)Arguments
integer | fillLevel | fill level |
boolean | setDirty | set dirty |
553 | function FillablePallet:setFillLevel(fillLevel, setDirty) |
554 | fillLevel = Utils.clamp(fillLevel, 0, self.capacity); |
555 | if self.fillLevel ~= fillLevel then |
556 | self.fillLevel = fillLevel; |
557 | if self.isServer and (setDirty == nil or setDirty) then |
558 | self:raiseDirtyFlags(self.fillablePalletDirtyFlag); |
559 | end |
560 | if self.visibilityNodes ~= nil then |
561 | local numVisibilityNodes = getNumOfChildren(self.visibilityNodes); |
562 | local numVisible = math.ceil(numVisibilityNodes*self.fillLevel/self.capacity); |
563 | if self.visibilityNodesAdditive then |
564 | for i=1,numVisibilityNodes do |
565 | setVisibility(getChildAt(self.visibilityNodes, i-1), i <= numVisible); |
566 | end |
567 | else |
568 | for i=1,numVisibilityNodes do |
569 | setVisibility(getChildAt(self.visibilityNodes, i-1), i == numVisible); |
570 | end |
571 | end |
572 | end |
573 | if self.movingPlane ~= nil then |
574 | local x,y,z = getTranslation(self.movingPlane); |
575 | y = Utils.lerp(self.movingPlaneMinY, self.movingPlaneMaxY, self:getFillLevel()/self:getCapacity()); |
576 | setTranslation(self.movingPlane, x,y,z); |
577 | end; |
578 | |
579 | if self.fillLevel > 0 and self.iconNode ~= nil then |
580 | local desc = FillUtil.fillTypeIndexToDesc[self.fillType]; |
581 | if desc ~= nil then |
582 | if desc.iconMaterial ~= nil then |
583 | setMaterial(self.iconNode, desc.iconMaterial, 0); |
584 | setShaderParameter(self.iconNode, "iconColor", self.iconColor[1], self.iconColor[2], self.iconColor[3], self.iconColor[4], false); |
585 | end; |
586 | setVisibility(self.iconNode, desc.iconMaterial ~= nil); |
587 | end; |
588 | end; |
589 | |
590 | if self.fillLevel > 0 then |
591 | self.fillWasNotZero = true; |
592 | end |
593 | |
594 | self.updateUnloadingEffects = true; |
595 | end |
596 | |
597 | if self.isServer then |
598 | if self.baseMass ~= nil then |
599 | local fillLevelMass = 0; |
600 | local desc = FillUtil.fillTypeIndexToDesc[self.fillType]; |
601 | if desc ~= nil then |
602 | fillLevelMass = desc.massPerLiter * self.fillLevel; |
603 | end |
604 | local totalMass = self.baseMass + fillLevelMass; |
605 | setMass(self.nodeId, totalMass); |
606 | end |
607 | end |
608 | |
609 | |
610 | end; |
fillableObjectRaycastCallback
DescriptionRaycast callbackDefinition
fillableObjectRaycastCallback(integer transformId, float x, float y, float z, float distance)Arguments
integer | transformId | id raycasted object |
float | x | x raycast position |
float | y | y raycast position |
float | z | z raycast position |
float | distance | distance to raycast position |
619 | function FillablePallet:fillableObjectRaycastCallback(transformId, x, y, z, distance) |
620 | self.currentRaycastDistance = distance; |
621 | return true; |
622 | end |
getFillLevel
DescriptionGet fill level of palletDefinition
getFillLevel()Return Values
integer | fillLevel | current fill level |
627 | function FillablePallet:getFillLevel() |
628 | return self.fillLevel; |
629 | end; |
getCapacity
DescriptionGet capacity of palletDefinition
getCapacity()Return Values
integer | capacity | capacity |
634 | function FillablePallet:getCapacity() |
635 | return self.capacity; |
636 | end; |
getMeshNodes
DescriptionGet mesh nodesDefinition
getMeshNodes()Return Values
table | meshNodes | mesh nodes |
641 | function FillablePallet:getMeshNodes() |
642 | if not self.meshNodesAddVisibleChildren then |
643 | return self.meshNodes |
644 | else |
645 | local nodes = {} |
646 | for _, node in pairs(self.meshNodes) do |
647 | table.insert(nodes, node) |
648 | for i=0, getNumOfChildren(node)-1 do |
649 | if getVisibility(getChildAt(node, i)) then |
650 | table.insert(nodes, getChildAt(node, i)) |
651 | end |
652 | end |
653 | end |
654 | |
655 | return nodes |
656 | end |
657 | end |
fillableTriggerCallback
DescriptionTrigger callbackDefinition
fillableTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay, integer otherShapeId)Arguments
integer | triggerId | id of trigger |
integer | otherId | id of actor |
boolean | onEnter | on enter |
boolean | onLeave | on leave |
boolean | onStay | on stay |
integer | otherShapeId | id of other actor |
667 | function FillablePallet:fillableTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay, otherShapeId) |
668 | local fillable = g_currentMission.nodeToVehicle[otherId]; |
669 | if fillable ~= nil and fillable.setFillLevel ~= nil and (fillable.exactFillRootNode == otherShapeId or fillable.exactFillRootNode == nil) then |
670 | if onEnter then |
671 | self.fillableObjects[fillable] = Utils.getNoNil(self.fillableObjects[fillable], 0) + 1; |
672 | elseif onLeave then |
673 | if self.fillableObjects[fillable] ~= nil then |
674 | self.fillableObjects[fillable] = self.fillableObjects[fillable] - 1; |
675 | if self.fillableObjects[fillable] == 0 then |
676 | self.fillableObjects[fillable] = nil; |
677 | end |
678 | end |
679 | end |
680 | end |
681 | end; |