LUADOC - Farming Simulator 17

Printable Version

SaplingPallet

Description
Class for sapling pallets
Functions

new

Description
Creating sapling pallet
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustomMt
Return Values
tableinstanceInstance of object
Code
18function SaplingPallet:new(isServer, isClient, customMt)
19 local mt = customMt;
20 if mt == nil then
21 mt = SaplingPallet_mt;
22 end;
23
24 local self = FillablePallet:new(isServer, isClient, mt);
25
26 registerObjectClassName(self, "SaplingPallet");
27
28 self.fillType = FillUtil.FILLTYPE_TREESAPLINGS;
29 self.fillLevel = 0;
30 self.capacity = 20;
31 self.synchronizeFillLevel = false;
32
33 return self;
34end;

delete

Description
Deleting sapling pallet
Definition
delete()
Code
38function SaplingPallet:delete()
39 if self.saplingFilename ~= nil then
40 Utils.releaseSharedI3DFile(self.saplingFilename, nil, true);
41 end;
42 unregisterObjectClassName(self);
43 SaplingPallet:superClass().delete(self);
44end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
50function SaplingPallet:readStream(streamId, connection)
51 SaplingPallet:superClass().readStream(self, streamId, connection);
52 local fillLevel = streamReadUInt8(streamId);
53 self:setFillLevel(fillLevel, false);
54end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
60function SaplingPallet:writeStream(streamId, connection)
61 SaplingPallet:superClass().writeStream(self, streamId, connection);
62 streamWriteUInt8(streamId, self.fillLevel);
63end;

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
70function SaplingPallet:readUpdateStream(streamId, timestamp, connection)
71 SaplingPallet:superClass().readUpdateStream(self, streamId, timestamp, connection);
72 if connection:getIsServer() then
73 if not self.synchronizeFillLevel then
74 if streamReadBool(streamId) then
75 local fillLevel = streamReadUInt8(streamId);
76 self:setFillLevel(fillLevel, false);
77 end
78 end;
79 end
80end;

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
87function SaplingPallet:writeUpdateStream(streamId, connection, dirtyMask)
88 SaplingPallet:superClass().writeUpdateStream(self, streamId, connection, dirtyMask);
89 if not connection:getIsServer() then
90 if not self.synchronizeFillLevel then
91 if streamWriteBool(streamId, bitAND(dirtyMask, self.fillablePalletDirtyFlag) ~= 0) then
92 streamWriteUInt8(streamId, self.fillLevel);
93 end
94 end;
95 end
96end;

setNodeId

Description
Set node id
Definition
setNodeId(integer nodeId)
Arguments
integernodeIdnode Id
Code
101function SaplingPallet:setNodeId(nodeId)
102 SaplingPallet:superClass().setNodeId(self, nodeId);
103
104 self.capacity = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "capacity")), self.capacity);
105
106 self.saplingFilename = getUserAttribute(nodeId, "saplingFilename");
107 if self.saplingFilename ~= nil then
108 if self.visibilityNodes ~= nil then
109 self.saplingFilename = Utils.getFilename(self.saplingFilename, self.baseDirectory)
110 local i3dNode = Utils.loadSharedI3DFile(self.saplingFilename);
111 self.capacity = getNumOfChildren(self.visibilityNodes);
112 if i3dNode ~= 0 and self.capacity > 0 then
113 for i=0, self.capacity-1 do
114 local node = clone(i3dNode, false, false, false);
115 link(getChildAt(self.visibilityNodes, i), node);
116 if getUserAttribute(nodeId, "useRandomRot") then
117 setRotation(node, 0, math.random(0, 2*math.pi), 0);
118 end;
119 end;
120 self:setFillLevel(Utils.getNoNil(tonumber(getUserAttribute(nodeId, "startFillLevel")), 0), false);
121 end;
122 else
123 print("Warning: fillNodeFillename requires use of visibilityNodes");
124 end;
125 end;
126
127 local treeType = getUserAttribute(nodeId, "treeType");
128 if treeType ~= nil then
129 local tree = TreePlantUtil.treeTypes[treeType];
130 if tree == nil then
131 print("Warning: Invalid treeType '"..treeType.."'.");
132 tree = next(TreePlantUtil.treeTypes);
133 end;
134 self.treeType = tree.index;
135 else
136 self.treeType = next(TreePlantUtil.treeTypes).index;
137 print("Warning: Missing treetype!");
138 end;
139end;