LUADOC - Farming Simulator 17

Printable Version

AnimatedObjectPlaceable

Description
Class for placeable shed
Parent
Placeable
Functions

new

Description
Creating placeable shed
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
18function AnimatedObjectPlaceable:new(isServer, isClient, customMt)
19 local mt = customMt;
20 if mt == nil then
21 mt = AnimatedObjectPlaceable_mt;
22 end;
23
24 local self = Placeable:new(isServer, isClient, mt);
25
26 registerObjectClassName(self, "AnimatedObjectPlaceable");
27
28 return self;
29end;

delete

Description
Deleting placeable hay loft
Definition
delete()
Code
33function AnimatedObjectPlaceable:delete()
34 if self.animatedObjects ~= nil then
35 for i=1, #self.animatedObjects do
36 local animatedObject = self.animatedObjects[i]
37 animatedObject:unregister(true)
38 animatedObject:delete()
39 end
40 end
41
42 unregisterObjectClassName(self);
43 AnimatedObjectPlaceable:superClass().delete(self);
44end;

load

Description
Load hay loft
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
57function AnimatedObjectPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
58 if not AnimatedObjectPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
59 return false;
60 end;
61
62 local xmlFile = loadXMLFile("TempXML", xmlFilename);
63
64 self.animatedObjectNodes = {}
65 self.animatedObjects = {}
66
67 local i = 0
68 while true do
69 local key = string.format("placeable.animatedObjects.animatedObject(%d)", i)
70 if not hasXMLProperty(xmlFile, key) then
71 break
72 end
73
74 local node = Utils.indexToObject(self.nodeId, getXMLString(xmlFile, key.."#index"))
75 if node ~= nil then
76 table.insert(self.animatedObjectNodes, node)
77 end
78 i = i + 1
79 end
80
81 delete(xmlFile);
82
83 return true;
84end;

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
88function AnimatedObjectPlaceable:finalizePlacement()
89 AnimatedObjectPlaceable:superClass().finalizePlacement(self);
90
91 for _, node in pairs(self.animatedObjectNodes) do
92 local animatedObject = AnimatedObject:new(self.isServer, self.isClient)
93 animatedObject.baseDirectory = self.baseDirectory
94 animatedObject.customEnvironment = self.customEnvironment
95 if animatedObject:load(node) then
96 animatedObject:register(true)
97 table.insert(self.animatedObjects, animatedObject)
98 end
99 end
100end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
106function AnimatedObjectPlaceable:readStream(streamId, connection)
107 AnimatedObjectPlaceable:superClass().readStream(self, streamId, connection);
108 if connection:getIsServer() then
109 for i=1, #self.animatedObjects do
110 local animatedObject = self.animatedObjects[i]
111 local animatedObjectId = readNetworkNodeObjectId(streamId);
112 animatedObject:readStream(streamId, connection);
113 g_client:finishRegisterObject(animatedObject, animatedObjectId);
114 end
115 end
116end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
122function AnimatedObjectPlaceable:writeStream(streamId, connection)
123 AnimatedObjectPlaceable:superClass().writeStream(self, streamId, connection);
124 if not connection:getIsServer() then
125 for i=1, #self.animatedObjects do
126 local animatedObject = self.animatedObjects[i]
127 writeNetworkNodeObjectId(streamId, animatedObject.id)
128 animatedObject:writeStream(streamId, connection)
129 g_server:registerObjectInStream(connection, animatedObject)
130 end
131 end
132end

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
140function AnimatedObjectPlaceable:loadFromAttributesAndNodes(xmlFile, key, resetVehicles)
141 if not AnimatedObjectPlaceable:superClass().loadFromAttributesAndNodes(self, xmlFile, key, resetVehicles) then
142 return false;
143 end;
144
145 for i=1, #self.animatedObjects do
146 local animatedObject = self.animatedObjects[i]
147 if hasXMLProperty(xmlFile, key..".animatedObject("..(i-1)..")") then
148 animatedObject:loadFromAttributesAndNodes(xmlFile, key..".animatedObject("..(i-1)..")")
149 end
150 end
151
152 return true;
153end;

getSaveAttributesAndNodes

Description
Get save attributes and nodes
Definition
getSaveAttributesAndNodes(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
160function AnimatedObjectPlaceable:getSaveAttributesAndNodes(nodeIdent)
161 local attributes, nodes = AnimatedObjectPlaceable:superClass().getSaveAttributesAndNodes(self, nodeIdent);
162
163 for i=1, #self.animatedObjects do
164 local animatedObject = self.animatedObjects[i]
165 local a, _ = animatedObject:getSaveAttributesAndNodes(nodeIdent .. " ")
166 if i > 1 then
167 nodes = nodes.."\n";
168 end;
169 nodes = nodes..nodeIdent.."<animatedObject".." "..a.. "/>"
170 end
171
172 return attributes, nodes;
173end;