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
Bale
DescriptionClass for balesParent
MountableObjectFunctions
- new
- delete
- readUpdateStream
- writeUpdateStream
- readStream
- writeStream
- mount
- unmount
- setNodeId
- createNode
- load
- loadFromMemory
- loadFromAttributesAndNodes
- getSaveAttributesAndNodes
- getValue
- getFillType
- getFillLevel
- setFillLevel
- setWrappingState
- getMeshNodes
new
DescriptionCreating bale objectDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | customMt |
table | instance | Instance of object |
18 | function Bale:new(isServer, isClient, customMt) |
19 | local mt = customMt; |
20 | if mt == nil then |
21 | mt = Bale_mt; |
22 | end; |
23 | |
24 | local self = MountableObject:new(isServer, isClient, mt); |
25 | |
26 | self.forcedClipDistance = 150; |
27 | registerObjectClassName(self, "Bale"); |
28 | |
29 | self.fillType = FillUtil.FILLTYPE_STRAW; |
30 | self.fillLevel = 0; |
31 | self.wrappingState = 0; |
32 | self.baleValueScale = 1; |
33 | self.canBeSold = true |
34 | |
35 | g_currentMission:addLimitedObject(FSBaseMission.LIMITED_OBJECT_TYPE_BALE, self); |
36 | |
37 | return self; |
38 | end; |
delete
DescriptionDeleting bale objectDefinition
delete()Code
42 | function Bale:delete() |
43 | if self.i3dFilename ~= nil then |
44 | Utils.releaseSharedI3DFile(self.i3dFilename, nil, true); |
45 | end |
46 | g_currentMission:removeLimitedObject(FSBaseMission.LIMITED_OBJECT_TYPE_BALE, self); |
47 | unregisterObjectClassName(self); |
48 | g_currentMission:removeItemToSave(self); |
49 | Bale:superClass().delete(self); |
50 | 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 |
57 | function Bale:readUpdateStream(streamId, timestamp, connection) |
58 | if connection:getIsServer() then |
59 | if self.supportsWrapping then |
60 | self:setWrappingState(streamReadUInt8(streamId)/255); |
61 | end |
62 | end |
63 | Bale:superClass().readUpdateStream(self, streamId, timestamp, connection); |
64 | 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 |
71 | function Bale:writeUpdateStream(streamId, connection, dirtyMask) |
72 | if not connection:getIsServer() then |
73 | if self.supportsWrapping then |
74 | streamWriteUInt8(streamId, Utils.clamp(self.wrappingState*255, 0, 255)); |
75 | end |
76 | end |
77 | Bale:superClass().writeUpdateStream(self, streamId, connection, dirtyMask); |
78 | end; |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
84 | function Bale:readStream(streamId, connection) |
85 | local i3dFilename = Utils.convertFromNetworkFilename(streamReadString(streamId)); |
86 | if self.nodeId == 0 then |
87 | self:createNode(i3dFilename); |
88 | end; |
89 | self.fillLevel = streamReadFloat32(streamId); |
90 | Bale:superClass().readStream(self, streamId, connection); |
91 | g_currentMission:addItemToSave(self); |
92 | |
93 | self.baleValueScale = streamReadFloat32(streamId); |
94 | if self.supportsWrapping then |
95 | self:setWrappingState(streamReadUInt8(streamId)/255); |
96 | setShaderParameter(self.meshNode, "wrappingState", self.wrappingState, 0, 0, 0, false); |
97 | end |
98 | end; |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
104 | function Bale:writeStream(streamId, connection) |
105 | streamWriteString(streamId, Utils.convertToNetworkFilename(self.i3dFilename)); |
106 | streamWriteFloat32(streamId, self.fillLevel); |
107 | Bale:superClass().writeStream(self, streamId, connection); |
108 | |
109 | streamWriteFloat32(streamId, self.baleValueScale); |
110 | |
111 | if self.supportsWrapping then |
112 | streamWriteUInt8(streamId, Utils.clamp(self.wrappingState*255, 0, 255)); |
113 | end |
114 | end; |
mount
DescriptionMount bale 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 |
126 | function Bale:mount(object, node, x,y,z, rx,ry,rz) |
127 | g_currentMission:removeItemToSave(self); |
128 | Bale:superClass().mount(self, object, node, x,y,z, rx,ry,rz); |
129 | end; |
unmount
DescriptionUnmount baleDefinition
unmount()Code
133 | function Bale:unmount() |
134 | if Bale:superClass().unmount(self) then |
135 | g_currentMission:addItemToSave(self); |
136 | return true; |
137 | end |
138 | return false; |
139 | end; |
setNodeId
DescriptionSet node idDefinition
setNodeId(integer nodeId)Arguments
integer | nodeId | node Id |
144 | function Bale:setNodeId(nodeId) |
145 | Bale:superClass().setNodeId(self, nodeId); |
146 | |
147 | local isRoundbale = Utils.getNoNil(getUserAttribute(nodeId, "isRoundbale"), false); |
148 | local defaultFillLevel = 2100*2; |
149 | if isRoundbale then |
150 | defaultFillLevel = 2000*2; |
151 | end |
152 | if getUserAttribute(nodeId, "baleValue") ~= nil then |
153 | print("Warning: bale 'baleValue' is not supported anymore. Use 'baleValueScale' instead and adjust the creating vehicles."); |
154 | end |
155 | local meshIndex = Utils.getNoNil(getUserAttribute(nodeId, "baleMeshIndex"), "1|0"); |
156 | self.meshNode = Utils.indexToObject(nodeId, meshIndex); |
157 | |
158 | self.meshNodes = {self.meshNode} |
159 | |
160 | self.supportsWrapping = Utils.getNoNil(getUserAttribute(nodeId, "supportsWrapping"), false); |
161 | self.fillLevel = defaultFillLevel |
162 | self.baleValueScale = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "baleValueScale")), 1); |
163 | |
164 | self.fillType = FillUtil.FILLTYPE_STRAW; |
165 | local fillTypeStr = getUserAttribute(nodeId, "fillType"); |
166 | if fillTypeStr ~= nil then |
167 | local fillTypeInt = FillUtil.fillTypeNameToInt[fillTypeStr]; |
168 | if fillTypeInt ~= nil then |
169 | self.fillType = fillTypeInt; |
170 | end |
171 | elseif Utils.getNoNil(getUserAttribute(nodeId, "isHaybale"), false) then |
172 | self.fillType = FillUtil.FILLTYPE_DRYGRASS_WINDROW; |
173 | end |
174 | |
175 | local baleWidth = tonumber(getUserAttribute(nodeId, "baleWidth")); |
176 | local baleHeight = tonumber(getUserAttribute(nodeId, "baleHeight")); |
177 | local baleLength = tonumber(getUserAttribute(nodeId, "baleLength")); |
178 | local baleDiameter = tonumber(getUserAttribute(nodeId, "baleDiameter")); |
179 | if baleDiameter ~= nil and baleWidth ~= nil then |
180 | self.baleDiameter = baleDiameter; |
181 | self.baleWidth = baleWidth; |
182 | elseif baleHeight ~= nil and baleWidth ~= nil and baleLength ~= nil then |
183 | self.baleHeight = baleHeight; |
184 | self.baleWidth = baleWidth; |
185 | self.baleLength = baleLength; |
186 | else |
187 | local isRoundbale = Utils.getNoNil(getUserAttribute(nodeId, "isRoundbale"), false); |
188 | if isRoundbale then |
189 | self.baleDiameter = 1.8; |
190 | self.baleWidth = 1.2; |
191 | else |
192 | self.baleHeight = 0.8; |
193 | self.baleWidth = 1.2; |
194 | self.baleLength = 2.4; |
195 | end |
196 | end |
197 | end; |
createNode
DescriptionLoad node from i3d fileDefinition
createNode(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
202 | function Bale:createNode(i3dFilename) |
203 | self.i3dFilename = i3dFilename; |
204 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
205 | local baleRoot = Utils.loadSharedI3DFile(i3dFilename); |
206 | |
207 | local baleId = getChildAt(baleRoot, 0); |
208 | link(getRootNode(), baleId); |
209 | delete(baleRoot); |
210 | |
211 | self:setNodeId(baleId); |
212 | end; |
load
DescriptionLoad baleDefinition
load(string i3dFilename, float x, float y, float z, float rx, float ry, float rz, integer fillLevel)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 |
integer | fillLevel | fill level |
224 | function Bale:load(i3dFilename, x,y,z, rx,ry,rz, fillLevel) |
225 | self.i3dFilename = i3dFilename; |
226 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
227 | self:createNode(i3dFilename); |
228 | setTranslation(self.nodeId, x, y, z); |
229 | setRotation(self.nodeId, rx, ry, rz); |
230 | if fillLevel ~= nil then |
231 | self.fillLevel = fillLevel; |
232 | end |
233 | g_currentMission:addItemToSave(self); |
234 | end; |
loadFromMemory
DescriptionSetting node id and i3d file nameDefinition
loadFromMemory(integer nodeId, string i3dFilename)Arguments
integer | nodeId | node id |
string | i3dFilename | i3d file name |
240 | function Bale:loadFromMemory(nodeId, i3dFilename) |
241 | self.i3dFilename = i3dFilename; |
242 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
243 | self:setNodeId(nodeId); |
244 | 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 |
252 | function Bale:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) |
253 | |
254 | local x,y,z = Utils.getVectorFromString(getXMLString(xmlFile, key.."#position")); |
255 | local xRot,yRot,zRot = Utils.getVectorFromString(getXMLString(xmlFile, key.."#rotation")); |
256 | if x == nil or y == nil or z == nil or xRot == nil or yRot == nil or zRot == nil then |
257 | return false; |
258 | end; |
259 | local filename = getXMLString(xmlFile, key.."#filename"); |
260 | if filename == nil then |
261 | return false; |
262 | end; |
263 | filename = Utils.convertFromNetworkFilename(filename); |
264 | local rootNode = Utils.loadSharedI3DFile(filename); |
265 | if rootNode == 0 then |
266 | return false; |
267 | end; |
268 | |
269 | local ret = false; |
270 | local node = getChildAt(rootNode, 0); |
271 | if node ~= nil and node ~= 0 then |
272 | setTranslation(node, x,y,z); |
273 | setRotation(node, xRot,yRot,zRot); |
274 | link(getRootNode(), node); |
275 | ret = true; |
276 | end; |
277 | delete(rootNode); |
278 | if not ret then |
279 | return false; |
280 | end; |
281 | |
282 | self:loadFromMemory(node, filename); |
283 | |
284 | |
285 | local fillLevel = getXMLFloat(xmlFile, key.."#fillLevel"); |
286 | if fillLevel ~= nil then |
287 | self.fillLevel = fillLevel; |
288 | end; |
289 | |
290 | if self.supportsWrapping then |
291 | self.wrappingState = Utils.getNoNil(getXMLFloat(xmlFile, key.."#wrappingState"),0); |
292 | setShaderParameter(self.meshNode, "wrappingState", self.wrappingState, 0, 0, 0, false); |
293 | end; |
294 | |
295 | local baleValueScale = Utils.getNoNil(tonumber(getXMLString(xmlFile, key.."#baleValueScale")), 1); |
296 | if baleValueScale ~= nil then |
297 | self.baleValueScale = baleValueScale; |
298 | end |
299 | |
300 | return true; |
301 | end; |
getSaveAttributesAndNodes
DescriptionGet save attributes and nodesDefinition
getSaveAttributesAndNodes(string nodeIdent)Arguments
string | nodeIdent | node ident |
string | attributes | attributes |
string | nodes | nodes |
308 | function Bale:getSaveAttributesAndNodes(nodeIdent) |
309 | |
310 | local x,y,z = getTranslation(self.nodeId); |
311 | local xRot,yRot,zRot = getRotation(self.nodeId); |
312 | local wrapping = ""; |
313 | if self.supportsWrapping then |
314 | wrapping = ' wrappingState="'..tostring(self.wrappingState)..'"'; |
315 | end; |
316 | local attributes = 'filename="'.. Utils.encodeToHTML(Utils.convertToNetworkFilename(self.i3dFilename))..'" position="'..x..' '..y..' '..z..'" rotation="'..xRot..' '..yRot..' '..zRot..'" baleValueScale="'..self.baleValueScale..'" fillLevel="'..self.fillLevel..'"'..wrapping; |
317 | local nodes = ""; |
318 | return attributes, nodes; |
319 | end; |
getValue
DescriptionGet price value of baleDefinition
getValue()Code
323 | function Bale:getValue() |
324 | local pricePerLiter = g_currentMission.economyManager:getPricePerLiter(self.fillType); |
325 | return self.fillLevel * pricePerLiter * self.baleValueScale; |
326 | end; |
getFillType
DescriptionGet fill type of baleDefinition
getFillType()Return Values
integer | fillType | current fill type id |
331 | function Bale:getFillType() |
332 | return self.fillType; |
333 | end; |
getFillLevel
DescriptionGet fill level of baleDefinition
getFillLevel()Return Values
integer | fillLevel | current fill level |
338 | function Bale:getFillLevel() |
339 | return self.fillLevel; |
340 | end; |
setFillLevel
DescriptionSet fill level of baleDefinition
setFillLevel(integer fillLevel)Arguments
integer | fillLevel | fill level |
345 | function Bale:setFillLevel(fillLevel) |
346 | self.fillLevel = fillLevel; |
347 | end; |
setWrappingState
DescriptionSet wrapping state of baleDefinition
setWrappingState(boolean wrappingState)Arguments
boolean | wrappingState | new wrapping state |
360 | function Bale:setWrappingState(wrappingState) |
361 | if self.supportsWrapping then |
362 | if self.wrappingState ~= wrappingState then |
363 | self:raiseDirtyFlags(self.physicsObjectDirtyFlag); |
364 | end |
365 | self.wrappingState = wrappingState; |
366 | setShaderParameter(self.meshNode, "wrappingState", self.wrappingState, 0, 0, 0, false); |
367 | end |
368 | end |
getMeshNodes
DescriptionSet wrapping state of baleDefinition
getMeshNodes()Return Values
table | meshNodes | mesh nodes |
373 | function Bale:getMeshNodes() |
374 | return self.meshNodes |
375 | end; |