LUADOC - Farming Simulator 17

Printable Version

FillablePallet

Description
Class for fillable pallets
Parent
MountableObject
Functions

new

Description
Creating fillable pallet
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustomMt
Return Values
tableinstanceInstance of object
Code
23function 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;
48end;

delete

Description
Delete fillable pallet
Definition
delete()
Code
52function 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);
70end;

getAllowsAutoDelete

Description
Get allows auto delete
Definition
getAllowsAutoDelete()
Return Values
booleanallowsAutoDeleteallows auto delete
Code
75function FillablePallet:getAllowsAutoDelete()
76 return not self.isReferenced and FillablePallet:superClass().getAllowsAutoDelete(self);
77end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
83function 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;
103end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
109function 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);
123end;

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
130function 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);
148end;

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
155function 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);
173end;

mount

Description
Mount pallet to object
Definition
mount(table object, integer node, float x, float y, float z, float rx, float ry, float rz)
Arguments
tableobjecttarget object
integernodetarget node id
floatxx position
floatyz position
floatzz position
floatrxrx rotation
floatryry rotation
floatrzrz rotation
Code
185function 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);
188end;

unmount

Description
Unmount pallet
Definition
unmount()
Return Values
booleansuccesssuccess
Code
193function FillablePallet:unmount()
194 if FillablePallet:superClass().unmount(self) then
195 g_currentMission:addItemToSave(self);
196 return true;
197 end
198 return false;
199end;

setNodeId

Description
Set node id
Definition
setNodeId(integer nodeId)
Arguments
integernodeIdnode Id
Code
204function 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;
290end;

createNode

Description
Load node from i3d file
Definition
createNode(string i3dFilename)
Arguments
stringi3dFilenamei3d file name
Code
295function 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;
321end;

load

Description
Load pallet
Definition
load(string i3dFilename, float x, float y, float z, float rx, float ry, float rz, string xmlFilename)
Arguments
stringi3dFilenamei3d file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
stringxmlFilenamexml file name
Return Values
booleansuccesssuccess
Code
334function 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;
343end;

loadObjectXML

Description
Load xml parameters
Definition
loadObjectXML(integer xmlFile)
Arguments
integerxmlFileid of xml object
Code
348function 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");
352end;

loadFromMemory

Description
Setting node id and i3d file name
Definition
loadFromMemory(integer nodeId, string i3dFilename)
Arguments
integernodeIdnode id
stringi3dFilenamei3d file name
Code
358function FillablePallet:loadFromMemory(nodeId, i3dFilename)
359 self.i3dFilename = i3dFilename;
360 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(Utils.getNoNil(self.xmlFilename, i3dFilename));
361 self:setNodeId(nodeId);
362end;

loadFromAttributesAndNodes

Description
Loading from attributes and nodes
Definition
loadFromAttributesAndNodes(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
370function 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;
438end;

getSaveAttributesAndNodes

Description
Get save attributes and nodes
Definition
getSaveAttributesAndNodes(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
445function 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;
460end;

getValue

Description
Get price value of pallet
Definition
getValue()
Return Values
integerpriceValueprice value
Code
465function FillablePallet:getValue()
466 local pricePerLiter = g_currentMission.economyManager:getPricePerLiter(self.fillType);
467 return self.fillLevel * pricePerLiter * self.fillablePalletValueScale;
468end;

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
473function FillablePallet:update(dt)
474 FillablePallet:superClass().update(self, dt);
475end

updateTick

Description
updateTick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
480function 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
540end

getFillType

Description
Get fill type of pallet
Definition
getFillType()
Return Values
integerfillTypecurrent fill type id
Code
545function FillablePallet:getFillType()
546 return self.fillType;
547end;

setFillLevel

Description
Set fill level of pallet
Definition
setFillLevel(integer fillLevel, boolean setDirty)
Arguments
integerfillLevelfill level
booleansetDirtyset dirty
Code
553function 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
610end;

fillableObjectRaycastCallback

Description
Raycast callback
Definition
fillableObjectRaycastCallback(integer transformId, float x, float y, float z, float distance)
Arguments
integertransformIdid raycasted object
floatxx raycast position
floatyy raycast position
floatzz raycast position
floatdistancedistance to raycast position
Code
619function FillablePallet:fillableObjectRaycastCallback(transformId, x, y, z, distance)
620 self.currentRaycastDistance = distance;
621 return true;
622end

getFillLevel

Description
Get fill level of pallet
Definition
getFillLevel()
Return Values
integerfillLevelcurrent fill level
Code
627function FillablePallet:getFillLevel()
628 return self.fillLevel;
629end;

getCapacity

Description
Get capacity of pallet
Definition
getCapacity()
Return Values
integercapacitycapacity
Code
634function FillablePallet:getCapacity()
635 return self.capacity;
636end;

getMeshNodes

Description
Get mesh nodes
Definition
getMeshNodes()
Return Values
tablemeshNodesmesh nodes
Code
641function 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
657end

fillableTriggerCallback

Description
Trigger callback
Definition
fillableTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay, integer otherShapeId)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
integerotherShapeIdid of other actor
Code
667function 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
681end;