Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- AnimatedMapObject
- AnimatedObject
- AnimatedObjectEvent
- Bale
- Basketball
- Bga
- BgaSellStation
- BunkerSilo
- BuyingStation
- DigitalDisplay
- DogBall
- HelpIcons
- LoadingStation
- NightIllumination
- Nightlight2
- NightlightFlicker
- PhysicsObject
- Rotator
- SellingStation
- SimParticleSystem
- Storage
- StorageSystem
- SunAdmirer
- TourIcons
- UnloadingStation
- VehicleSellingPoint
- WildlifeSpawner
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
Bale
DescriptionClass for balesParent
MountableObjectFunctions
- applyExtraAttributes
- createNode
- delete
- getCanBeSold
- getFillLevel
- getFillType
- getValue
- load
- loadExtraAttributesFromXMLFile
- loadFromMemory
- loadFromXMLFile
- mount
- new
- readStream
- readUpdateStream
- saveToXMLFile
- setCanBeSold
- setColor
- setFillLevel
- setNodeId
- setWrappingState
- unmount
- writeStream
- writeUpdateStream
applyExtraAttributes
DescriptionDefinitionapplyExtraAttributes()Code
327 | function Bale:applyExtraAttributes(attributes) |
328 | if self.supportsWrapping then |
329 | setShaderParameter(self.meshNode, "wrappingState", attributes.wrappingState, 0, 0, 0, false) |
330 | self.wrappingState = attributes.wrappingState |
331 | self:setColor(unpack(attributes.wrappingColor)) |
332 | end |
333 | |
334 | self.baleValueScale = attributes.baleValueScale |
335 | |
336 | return true; |
337 | end |
createNode
DescriptionLoad node from i3d fileDefinition
createNode(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
213 | function Bale:createNode(i3dFilename) |
214 | self.i3dFilename = i3dFilename; |
215 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
216 | local baleRoot = g_i3DManager:loadSharedI3DFile(i3dFilename); |
217 | |
218 | local baleId = getChildAt(baleRoot, 0); |
219 | link(getRootNode(), baleId); |
220 | delete(baleRoot); |
221 | |
222 | self:setNodeId(baleId); |
223 | end |
delete
DescriptionDeleting bale objectDefinition
delete()Code
41 | function Bale:delete() |
42 | if self.i3dFilename ~= nil then |
43 | g_i3DManager:releaseSharedI3DFile(self.i3dFilename, nil, true); |
44 | end |
45 | g_currentMission:removeLimitedObject(FSBaseMission.LIMITED_OBJECT_TYPE_BALE, self); |
46 | unregisterObjectClassName(self); |
47 | g_currentMission:removeItemToSave(self); |
48 | Bale:superClass().delete(self); |
49 | end |
getCanBeSold
DescriptionReturns if bale can be soldDefinition
getCanBeSold()Return Values
boolean | canBeSold | bale can be sold |
396 | function Bale:getCanBeSold() |
397 | return self.canBeSold |
398 | end |
getFillLevel
DescriptionGet fill level of baleDefinition
getFillLevel()Return Values
integer | fillLevel | current fill level |
375 | function Bale:getFillLevel() |
376 | return self.fillLevel; |
377 | end |
getFillType
DescriptionGet fill type of baleDefinition
getFillType()Return Values
integer | fillType | current fill type id |
368 | function Bale:getFillType() |
369 | return self.fillType; |
370 | end |
getValue
DescriptionGet price value of baleDefinition
getValue()Code
360 | function Bale:getValue() |
361 | local pricePerLiter = g_currentMission.economyManager:getPricePerLiter(self.fillType); |
362 | return self.fillLevel * pricePerLiter * self.baleValueScale; |
363 | 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 |
235 | function Bale:load(i3dFilename, x,y,z, rx,ry,rz, fillLevel) |
236 | self.i3dFilename = i3dFilename; |
237 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
238 | self:createNode(i3dFilename); |
239 | setTranslation(self.nodeId, x, y, z); |
240 | setRotation(self.nodeId, rx, ry, rz); |
241 | if fillLevel ~= nil then |
242 | self.fillLevel = fillLevel; |
243 | end |
244 | g_currentMission:addItemToSave(self); |
245 | end |
loadExtraAttributesFromXMLFile
DescriptionDefinitionloadExtraAttributesFromXMLFile()Code
316 | function Bale:loadExtraAttributesFromXMLFile(attributes, xmlFile, key, resetVehicles) |
317 | attributes.wrappingState = Utils.getNoNil(getXMLFloat(xmlFile, key.."#wrappingState"), 0) |
318 | attributes.wrappingColor = {StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#wrappingColor"))} |
319 | |
320 | attributes.baleValueScale = Utils.getNoNil(tonumber(getXMLString(xmlFile, key.."#valueScale")), 1) |
321 | |
322 | return true; |
323 | end |
loadFromMemory
DescriptionSetting node id and i3d file nameDefinition
loadFromMemory(integer nodeId, string i3dFilename)Arguments
integer | nodeId | node id |
string | i3dFilename | i3d file name |
251 | function Bale:loadFromMemory(nodeId, i3dFilename) |
252 | self.i3dFilename = i3dFilename; |
253 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
254 | self:setNodeId(nodeId); |
255 | end |
loadFromXMLFile
DescriptionLoading from attributes and nodesDefinition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)Arguments
integer | xmlFile | id of xml object |
string | key | key |
boolean | resetVehicles | reset vehicles |
boolean | success | success |
263 | function Bale:loadFromXMLFile(xmlFile, key, resetVehicles) |
264 | |
265 | local x,y,z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#position")); |
266 | local xRot,yRot,zRot = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotation")); |
267 | if x == nil or y == nil or z == nil or xRot == nil or yRot == nil or zRot == nil then |
268 | return false; |
269 | end; |
270 | xRot = math.rad(xRot) |
271 | yRot = math.rad(yRot) |
272 | zRot = math.rad(zRot) |
273 | |
274 | local filename = getXMLString(xmlFile, key.."#filename"); |
275 | if filename == nil then |
276 | return false; |
277 | end; |
278 | filename = NetworkUtil.convertFromNetworkFilename(filename); |
279 | local rootNode = g_i3DManager:loadSharedI3DFile(filename); |
280 | if rootNode == 0 then |
281 | return false; |
282 | end; |
283 | |
284 | local ret = false; |
285 | local node = getChildAt(rootNode, 0); |
286 | if node ~= nil and node ~= 0 then |
287 | setTranslation(node, x,y,z); |
288 | setRotation(node, xRot,yRot,zRot); |
289 | link(getRootNode(), node); |
290 | ret = true; |
291 | end; |
292 | delete(rootNode); |
293 | if not ret then |
294 | return false; |
295 | end; |
296 | |
297 | self:setOwnerFarmId(Utils.getNoNil(getXMLInt(xmlFile, key .. "#farmId"), AccessHandler.EVERYONE), true) |
298 | |
299 | self:loadFromMemory(node, filename); |
300 | |
301 | |
302 | local fillLevel = getXMLFloat(xmlFile, key.."#fillLevel"); |
303 | if fillLevel ~= nil then |
304 | self.fillLevel = fillLevel; |
305 | end; |
306 | |
307 | local attributes = {} |
308 | self:loadExtraAttributesFromXMLFile(attributes, xmlFile, key, resetVehicles) |
309 | self:applyExtraAttributes(attributes) |
310 | |
311 | return true; |
312 | 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 |
136 | function Bale:mount(object, node, x,y,z, rx,ry,rz) |
137 | g_currentMission:removeItemToSave(self); |
138 | Bale:superClass().mount(self, object, node, x,y,z, rx,ry,rz); |
139 | end |
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 |
17 | function Bale:new(isServer, isClient, customMt) |
18 | local mt = customMt; |
19 | if mt == nil then |
20 | mt = Bale_mt; |
21 | end; |
22 | |
23 | local self = MountableObject:new(isServer, isClient, mt); |
24 | |
25 | self.forcedClipDistance = 150; |
26 | registerObjectClassName(self, "Bale"); |
27 | |
28 | self.fillType = FillType.STRAW; |
29 | self.fillLevel = 0; |
30 | self.wrappingState = 0; |
31 | self.baleValueScale = 1; |
32 | self.canBeSold = true |
33 | |
34 | g_currentMission:addLimitedObject(FSBaseMission.LIMITED_OBJECT_TYPE_BALE, self); |
35 | |
36 | return self; |
37 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
83 | function Bale:readStream(streamId, connection) |
84 | local i3dFilename = NetworkUtil.convertFromNetworkFilename(streamReadString(streamId)); |
85 | if self.nodeId == 0 then |
86 | self:createNode(i3dFilename); |
87 | end; |
88 | self.fillLevel = streamReadFloat32(streamId); |
89 | Bale:superClass().readStream(self, streamId, connection); |
90 | g_currentMission:addItemToSave(self); |
91 | |
92 | self.baleValueScale = streamReadFloat32(streamId); |
93 | if self.supportsWrapping then |
94 | self:setWrappingState(streamReadUInt8(streamId)/255); |
95 | setShaderParameter(self.meshNode, "wrappingState", self.wrappingState, 0, 0, 0, false); |
96 | |
97 | local r = streamReadFloat32(streamId); |
98 | local g = streamReadFloat32(streamId); |
99 | local b = streamReadFloat32(streamId); |
100 | local a = streamReadFloat32(streamId); |
101 | self:setColor(r, g, b, a); |
102 | end; |
103 | 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 |
56 | function Bale:readUpdateStream(streamId, timestamp, connection) |
57 | if connection:getIsServer() then |
58 | if self.supportsWrapping then |
59 | self:setWrappingState(streamReadUInt8(streamId)/255); |
60 | end |
61 | end |
62 | Bale:superClass().readUpdateStream(self, streamId, timestamp, connection); |
63 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
341 | function Bale:saveToXMLFile(xmlFile, key) |
342 | local x,y,z = getTranslation(self.nodeId) |
343 | local xRot,yRot,zRot = getRotation(self.nodeId) |
344 | |
345 | setXMLString(xmlFile, key.."#filename", HTMLUtil.encodeToHTML(NetworkUtil.convertToNetworkFilename(self.i3dFilename))) |
346 | setXMLString(xmlFile, key.."#position", string.format("%.4f %.4f %.4f", x, y, z)) |
347 | setXMLString(xmlFile, key.."#rotation", string.format("%.4f %.4f %.4f", math.deg(xRot), math.deg(yRot), math.deg(zRot))) |
348 | setXMLFloat(xmlFile, key.."#valueScale", self.baleValueScale) |
349 | setXMLFloat(xmlFile, key.."#fillLevel", self.fillLevel) |
350 | setXMLInt(xmlFile, key.."#farmId", self:getOwnerFarmId()) |
351 | |
352 | if self.supportsWrapping then |
353 | setXMLFloat(xmlFile, key.."#wrappingState", self.wrappingState) |
354 | setXMLString(xmlFile, key.."#wrappingColor", string.format("%f %f %f %f", self.wrappingColor[1], self.wrappingColor[2], self.wrappingColor[3], self.wrappingColor[4])) |
355 | end |
356 | end |
setCanBeSold
DescriptionSet if bale can be soldDefinition
setCanBeSold(boolean canBeSold)Arguments
boolean | canBeSold | bale can be sold |
389 | function Bale:setCanBeSold(canBeSold) |
390 | self.canBeSold = canBeSold |
391 | end |
setColor
DescriptionSet color of baleDefinition
setColor(float r, float g, float b, float a)Arguments
float | r | red channel value |
float | g | green channel value |
float | b | blue channel value |
float | a | alpha channel value |
419 | function Bale:setColor(r, g, b, a) |
420 | r, g, b, a = Utils.getNoNil(r, 1), Utils.getNoNil(g, 1), Utils.getNoNil(b, 1), Utils.getNoNil(a, 1); |
421 | self.wrappingColor = {r, g, b, a}; |
422 | |
423 | if getHasShaderParameter(self.meshNode, "colorScale") then |
424 | setShaderParameter(self.meshNode, "colorScale", r, g, b, a, false); |
425 | end; |
426 | end |
setFillLevel
DescriptionSet fill level of baleDefinition
setFillLevel(integer fillLevel)Arguments
integer | fillLevel | fill level |
382 | function Bale:setFillLevel(fillLevel) |
383 | self.fillLevel = fillLevel; |
384 | end |
setNodeId
DescriptionSet node idDefinition
setNodeId(integer nodeId)Arguments
integer | nodeId | node Id |
154 | function Bale:setNodeId(nodeId) |
155 | Bale:superClass().setNodeId(self, nodeId); |
156 | |
157 | local isRoundbale = Utils.getNoNil(getUserAttribute(nodeId, "isRoundbale"), false); |
158 | local defaultFillLevel = 4000; |
159 | if getUserAttribute(nodeId, "baleValue") ~= nil then |
160 | print("Warning: bale 'baleValue' is not supported anymore. Use 'baleValueScale' instead and adjust the creating vehicles."); |
161 | end |
162 | local meshIndex = Utils.getNoNil(getUserAttribute(nodeId, "baleMeshIndex"), "1|0"); |
163 | self.meshNode = I3DUtil.indexToObject(nodeId, meshIndex); |
164 | |
165 | self.meshNodes = {self.meshNode} |
166 | |
167 | self.supportsWrapping = Utils.getNoNil(getUserAttribute(nodeId, "supportsWrapping"), false); |
168 | if self.supportsWrapping then |
169 | self.wrappingColor = {1,1,1,1}; |
170 | end |
171 | |
172 | self.fillLevel = defaultFillLevel |
173 | self.baleValueScale = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "baleValueScale")), 1); |
174 | |
175 | self.fillType = FillType.STRAW; |
176 | local fillTypeStr = getUserAttribute(nodeId, "fillType"); |
177 | if fillTypeStr ~= nil then |
178 | local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeStr) |
179 | if fillTypeIndex ~= nil then |
180 | self.fillType = fillTypeIndex; |
181 | end |
182 | elseif Utils.getNoNil(getUserAttribute(nodeId, "isHaybale"), false) then |
183 | self.fillType = FillType.DRYGRASS_WINDROW; |
184 | end |
185 | |
186 | local baleWidth = tonumber(getUserAttribute(nodeId, "baleWidth")); |
187 | local baleHeight = tonumber(getUserAttribute(nodeId, "baleHeight")); |
188 | local baleLength = tonumber(getUserAttribute(nodeId, "baleLength")); |
189 | local baleDiameter = tonumber(getUserAttribute(nodeId, "baleDiameter")); |
190 | if baleDiameter ~= nil and baleWidth ~= nil then |
191 | self.baleDiameter = baleDiameter; |
192 | self.baleWidth = baleWidth; |
193 | elseif baleHeight ~= nil and baleWidth ~= nil and baleLength ~= nil then |
194 | self.baleHeight = baleHeight; |
195 | self.baleWidth = baleWidth; |
196 | self.baleLength = baleLength; |
197 | else |
198 | local isRoundbale = Utils.getNoNil(getUserAttribute(nodeId, "isRoundbale"), false); |
199 | if isRoundbale then |
200 | self.baleDiameter = 1.8; |
201 | self.baleWidth = 1.2; |
202 | else |
203 | self.baleHeight = 0.8; |
204 | self.baleWidth = 1.2; |
205 | self.baleLength = 2.4; |
206 | end |
207 | end |
208 | end |
setWrappingState
DescriptionSet wrapping state of baleDefinition
setWrappingState(boolean wrappingState)Arguments
boolean | wrappingState | new wrapping state |
403 | function Bale:setWrappingState(wrappingState) |
404 | if self.supportsWrapping then |
405 | if self.wrappingState ~= wrappingState then |
406 | self:raiseDirtyFlags(self.physicsObjectDirtyFlag); |
407 | end |
408 | self.wrappingState = wrappingState; |
409 | setShaderParameter(self.meshNode, "wrappingState", self.wrappingState, 0, 0, 0, false); |
410 | end |
411 | end |
unmount
DescriptionUnmount baleDefinition
unmount()Code
143 | function Bale:unmount() |
144 | if Bale:superClass().unmount(self) then |
145 | g_currentMission:addItemToSave(self); |
146 | return true; |
147 | end |
148 | return false; |
149 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
109 | function Bale:writeStream(streamId, connection) |
110 | streamWriteString(streamId, NetworkUtil.convertToNetworkFilename(self.i3dFilename)); |
111 | streamWriteFloat32(streamId, self.fillLevel); |
112 | Bale:superClass().writeStream(self, streamId, connection); |
113 | |
114 | streamWriteFloat32(streamId, self.baleValueScale); |
115 | |
116 | if self.supportsWrapping then |
117 | streamWriteUInt8(streamId, MathUtil.clamp(self.wrappingState*255, 0, 255)); |
118 | |
119 | streamWriteFloat32(streamId, self.wrappingColor[1]); |
120 | streamWriteFloat32(streamId, self.wrappingColor[2]); |
121 | streamWriteFloat32(streamId, self.wrappingColor[3]); |
122 | streamWriteFloat32(streamId, self.wrappingColor[4]); |
123 | end |
124 | 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 |
70 | function Bale:writeUpdateStream(streamId, connection, dirtyMask) |
71 | if not connection:getIsServer() then |
72 | if self.supportsWrapping then |
73 | streamWriteUInt8(streamId, MathUtil.clamp(self.wrappingState*255, 0, 255)); |
74 | end |
75 | end |
76 | Bale:superClass().writeUpdateStream(self, streamId, connection, dirtyMask); |
77 | end |