GIANTS Game Engine v7 Documentation



Table of Contents

  1. Chapter 01: Overview
    1. Enable development controls
    2. Runtime development key short-cuts
    3. Console Command Reference
  2. Chapter 02: Editor
    1. Viewport
    2. Scenegraph
    3. Attributes
    4. Toolbar
    5. Terrain
    6. User Attributes
    7. Scripting
    8. Terrain Editing
    9. Replace Dialog
    10. Interactive Placement
    11. Other functionality
    12. Key short-cuts
  3. Chapter 03: Scripting API Reference
    1. Script Reference(1.4.4.0)
      1. Handtools
      2. Events
      3. Objects
      4. Placeables
      5. Triggers
      6. Utils
      7. Vehicles
      8. Specializations
      Engine Reference(7.0.0.2)
      1. General
      2. Entity
      3. Node
      4. Scenegraph
      5. Lighting
      6. Camera
      7. Shape
      8. Particle System
      9. Physics
      10. Spline
      11. Animation
      12. Overlays
      13. Sound
      14. Input
      15. XML
      16. Network
      17. Callbacks
      18. Text Rendering
      19. Terrain Detail
      20. Tire Track
      21. Editor
      22. Rendering
      23. String
      24. Math
      25. I3D
      26. Fillplanes
    2. Foundation Reference
      1. Scenegraph
      2. Input
  4. Chapter 04: Tutorials
    1. Tutorial 1 - Load i3d files and basics
    2. Tutorial 2 - Light functions, global time and rendering text
    3. Tutorial 3 - User Attributes
    4. Tutorial 4 - Timers
    5. Tutorial 5 - Physics
    6. Tutorial 6 - Overlays
    7. Tutorial 7 - Audio
  5. Chapter 05: Exporter
    1. Autodesk Maya1 I3D Exporter
      1. Material Export Options
      2. Manual Installation
    2. Autodesk 3ds MAX2 I3D Exporter
      1. Manual Installation
    3. Blender I3D Exporter
  6. Chapter 06: Content Creation - Artwork Guide
    1. Autodesk Maya
    2. Autodesk 3DS MAX
    3. Texturing
  7. Chapter 07: I3D Format
    1. Introduction
    2. Features
    3. Overview
    4. Specification
      1. General Layout
      2. Materials
      3. Shapes
      4. Dynamics
      5. Scenegraph
      6. Animation


Overview



Enable development controls



Open the file game.xml and change the value of controls from false to true.

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<game>
  ...
  <development>
    <controls>true</controls>
  </development>
</game>


Runtime development key short-cuts


Key Function
~ or ` Toggle console
F2 Show frame rate
F3 Toggle frame rate limiter
F4 Wireframe mode
F5 Toggle debug rendering
F7 Toggle camera
F8 Toggle stats


Console command reference


help

Description
List all available commands

showFps

Description
Show frames per second

enableFramerateLimit

Description
Enable/disable frame per second limiter

framerateLimitFPS

Description
Frame per second limit attribute

listEntities

Description
Print detailed entity list

listResources

Description
Print detailed resource list

parallelRenderingAndPhysics

Description
Enable parallel rendering and physics

exit, quit or q

Description
Quits application






Editor

Table of Contents

  1. Viewport
  2. Scenegraph Panel
  3. Attributes Panel
  4. Toolbar
  5. Terrain Editing
  6. User Attributes
  7. Animation Panel
  8. Particle System Panel
  9. Spline Editing
  10. Scripting
  11. Replace Dialog
  12. Interactive Placement
  13. Other functionality
  14. Keyboard short-cuts



If you start up the Editor, you might not have all the panel windows open. To open other panel windows open the menu option window and enable the panel you want. You can adjust the width and height of the panels by dragging the outlines and if you want to close a window you can simply press the cross right of the panel name.


Viewport




Navigation

The navigation is quite like in Maya. If you have nothing open in your editor I suggest you quickly open a simple i3d file otherwise you won’t see much of an effect. If its to dark in your scene just create a light by going to Create–>Light.

Some shortcuts:
LMB = Left Mouse Button
RMB = Right Mouse Button
MMB = Middle Mouse Button
Alt + LMB = Press and hold the Alt-Key and the left mouse button.

Alt + LMB rotates the camera.
Alt + RMB moves the camera forward and backward.
Alt + MMB causes the camera to pan.

If you don’t have a middle mouse button, you can press LMB and RMB instead.

View Options

By simply right-clicking into the viewport panel you get the View Options. Sometimes it’s useful too use different cameras in a scene. You can create them once and then with the View Options you can choose the camera to view at your scene from different angles quickly.

You might notice that if you rotate, the camera is rotated. If you have a big level this behaviour is very useful, but if you want to look at one particular object this can be quite awkward. To change the rotation to Framed Rotate you first have to select your object either by clicking on it directly or by choosing it from the scene-graph and the framing the selected object by pressing the F key. Now you can simply click (RMB) on the screen to open the View Options and choose Framed Rotate. Now the camera is rotating around your last framed object.

You can select the visual appearance of the object with Shaded (solid surface) or Wireframe (only edges of the object are visible)

If you have large scenes, you can toggle the visibility of lights, audio sources, physics and the cameras by checking them on the show submenu.

You can also use the Selectable submenu to toggle whether you can select lights, audio sources or cameras.

Furthermore you can toggle the grid and the polycount on and off.

Profile gives you the ability to choose different hardware profiles adequate for your system.

Debug can be used to find errors (e.g. on your 3D model)


Scenegraph Panel

A very useful feature of the GIANTS Editor is the scenegraph. If you don’t have it on the screen, just go to menu window and hit scenegraph. It is basically the same you have in Maya. It shows all objects you have in your scene and also the parent-child relationship between your objects.



Let’s just make a little scene with some Transform Groups. The Transform Group is the basic building block of your scene. You can use a TransformGroup to move all the attached objects just by moving the Transform Group since the children inherit the transformations of the parent. To create a new Transform Group go to Create and hit TransformGroup. Now you can see it in the Scenegraph, its name is transform. To change the name just select it and go to the attributes panel. At the very top of the panel you can choose the name of your object. Make two TransformGroups and name them Parent and Child. If you move them around you see that their transformations are independent, the movement of the parent doesn’t affect the child. Now let’s make the appropriate relationship between the two. Select the child in the scenegraph panel and go to Edit->Cut. Now select your parent and hit Edit->Paste. Additionally by pressing MMB on the child, dragging it over parent and releasing MMB, the same as above will happen.

As you can see now, the child is now connected to the parent. If you now move around the parent, the transformation of the child is affected too whereas the child can be moved around without affecting the parent.




There can be 6 types of objects in your scene: Triangle Meshes, Splines, Cameras, Transform Groups, Lights, Terrains and Audio Sources.

It is also possible to use CTRL + C to copy objets, CTRL + X to cut objects and CTRL + V to paste objects. Notice that pasted objects are always children of the currently selected object. If you want to paste an object on the highest hierarchy level of the scenegraph be sure that nothing is selected in the scenegraph. This can be achieved by clicking at an empty space in the scenegraph panel.


Attributes Panel

If you don’t see the attributes panel go to Windows->Attributes then select an object in the scenegraph or the viewport. One important thing to notice is, that if the background color of an attribute turns red, you entered a value that isn’t allowed. (eg scale values other than 1 for a dynamic rigid body object) The background color of animated attributes is yellow.




Toolbar




The toolbar looks like this. If your pointing on the icons with your mouse, a text with the functionality of the tool is displayed.

Let’s quickly go through them from left to right.

File Operations
History
Physics
If you hit the play icon, the physics will simulate.

Toggle Local- World Mode
A handy tool is the toggle Local- World Mode, it changes the orientation of the viewport transform gizmo from the local space of your object to world space.

Grid Snapping
Use this option to snap objects to a predefined grid.

Terrain and Terrain Foliage
Texture Reload
Script Editor


Terrain Editing




To test the terrain sculpting, just open the terrain test scene. Now you have a terrain to play with. Open the terrain editing panel with window->Terrain Editing. (If the scenegraph panel is still open it might cut off a bit, just close it to get more space.)



If the terrain sculpt mode is active now, you can rise or lower the surface of your terrain by using RMB and LMB. MMB can be used to smooth and the value defines the force with which you pull or push. What happens here is, that you are painting a height map, that defines the height of each point of your terrain by giving it a grey-value. The attributes Opacity, Hardness and the Value are defining the "brush" you are painting the height map with. Just play around with the setting. You can change the radius of the brush with the shortcuts "V" and "B" and you can change the opacity value of the brush quickly with "N" and "M".

In the terrain texture paint mode next to the terrain sculpt icon you can colorize your terrain with different textures.
The used texture layers are defined in the i3d-file. (If you want to change the texture layers, you have to open the i3d with a text editor and change the layers there) Just choose your texture and paint onto your terrain. With the Chunk vis checkbox on, you can see exactly which texture layers you used in a chunk by what amout. You can use as many texture layers as you want, but you are limited to a maximum of four texture layers per chunk.

With the Terrain Foliage Paint Mode active, you can paint your foliage onto your terrain, it`s the same thing as if you would paint onto your terrain - not with a texture but with foliage. LMB adds foliage, RMB removes foliage.


User Attributes




The user attributes panel is typically not visible if you open the editor for the first time. So go to Windows->User Attributes. Select an object in the scenegraph to see its user attributes.

User Attributes can be defined in the editor and then be used in the engine (eg. within a script). This enables you to define object specific attributes for every object in the scene.


Animation Panel




You can preview animation sets with the animation panel.

Particle System Panel




The particle system panel allows you to edit particle systems with real time preview.

Spline Editing




You can edit splines by picking a control vertex (CV) of a spline an moving it around. Delete or insert new control vertices with the keys delete and insert.

Scripting

Here you can execute script snippets. With ENTER, you can add new lines. SHIFT+ENTER will execute the code in the text field.

Type in the following:

print("hello world from the GIANTS Editor");

Then hit SHIFT + ENTER and the string is printed out above.


The scripting can be useful for many things. For example you can run this script snippet to test the fog settings in an i3d scene:

setFog("exp2", 0.002, 0, 0.8, 0.81, 0.97);


Replace Dialog




If you want to replace an object in your scene, you can go to Edit->Replace to open the replace panel. Select the object you want to replace, then hit load. Do likewise with the object you want to replace with and choose whether you want to keep the User Attributes or not. Now you can replace one single object by hitting replace or you can replace all objects that are similar to the one you selected by hitting replace all.

Note: replace all does only work with single objects, but not with hierarchies of objects, however the single replace function works.
This feature is quite useful because you can use it to substitute an object reference feature within your i3d scene file.


Interactive Placement

This is a really nice feature of the editor, you should try it at least once!
To place an object on the surface of another object, you can simply select the object you want to place and then press CTRL + B + LMB, while pointing at your desired location. The selected object will then instantly be set to the location you’ve chosen.

Hint: you can do this with all your objects within your scenegraph and also with the camera or light sources. E.g. you can select the current camera and then place the camera at a location far away, allowing for fast relocation of the camera.

If you keep the LMB pressed and hit SHIFT or CRTL you can clone the selected object at the currect mouse position. SHIFT will just clone the object while CRTL will add a random rotation in the Y-axis. (Useful feature if you want to create a group with hundreds of randomly rotated objects like a forest)

Other functionality


Edit->Clear History: This clears the undo/redo history.

Edit->Move to Camera: Moves the selected object in front of the current camera

Navigation Speed: Moves the camera faster or slower. Use - and + to ajust the speed.


Keyboard short-cuts

Key Function
W A S D Navigation
Alt + LMB Rotate camera
Alt + MMB Pan camera
Alt + RMB Zoom camera
Alt + LMB + RMB Move camera up or down and left or right camera
F Frame selected object
- Decrease navigation speed
+ Increase navigation speed
4 Wireframe mode
6 Shaded mode
Ctrl-S Save
Ctrl-Z Undo
Ctrl-W Replace Dialog
Ctrl-X Cut
Ctrl-C Copy
Ctrl-V Paste
Ctrl-Shift-C Copy X,Y,Z components at once
Ctrl-Shift-V Paste X,Y,Z components at once (can also be copied from a text source in the format "x y z")
Delete Delete
Ctrl-D Duplicate
Ctrl-F Move to Camera
Ctrl-B Interactive placement (hold left mouse button to move around)
Shift Interactive placement paint
Ctrl Interactive placement paint with random rotation around y axis
Ctrl-H Hide object
Shift-H Show object
Ctrl-G Group objects
Ctrl-R Pick replace value in viewport (Terrain edit modes)
V Decrease brush radius
B Increase brush radius
N Decrease brush opacity
M Increase brush opacity
F8 Toggle stats
Shift + Enter Execute Script (Script Window)
X Absolute grid snapping
J Relative grid snapping
Delete Delete spline control vertex
Insert Insert new spline control vertex
Left Previous spline control vertex
Right Next spline control vertex
Up or Down First spline control vertex
S Stitch spline endpoints
O Toggle spline open/close
R Reverse spline
Ctrl-L Create light


Scripting API Reference

Script Version: 1.4.4.0

Chainsaw

Description
Class for chainsaws

new

Description
Creating chainsaw object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
17function Chainsaw:new(isServer, isClient, customMt)
18 local mt = customMt
19 if mt == nil then
20 mt = Chainsaw_mt
21 end
22
23 local self = HandTool:new(isServer, isClient, mt)
24 return self
25end

load

Description
Load chainsaw from xml file
Definition
load(string xmlFilename, table player)
Arguments
stringxmlFilenamexml file name
tableplayerplayer
Return Values
booleansuccesssuccess
Code
32function Chainsaw:load(xmlFilename, player)
33 if not Chainsaw:superClass().load(self, xmlFilename, player) then
34 return false
35 end
36
37 local xmlFile = loadXMLFile("TempXML", xmlFilename)
38
39 self.rotationZ = 0
40 self.rotationSpeedZ = 0.003
41 self.cutSizeY = 1.1
42 self.cutSizeZ = 1
43 self.isCutting = false
44 self.waitingForResetAfterCut = false
45 self.cutNode = getChildAt(self.rootNode, 0)
46 self.graphicsNode = getChildAt(self.cutNode, 0)
47 self.chainNode = getChildAt(self.graphicsNode, 0)
48 self.psNode = getChildAt(self.graphicsNode, 1)
49
50 self.pricePerSecond = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.chainsaw.pricePerMinute"), 50) / 1000
51
52 if self.isClient then
53 self.particleSystems = {}
54
55 local i = 0
56 while true do
57 local keyPS = string.format("handTool.chainsaw.particleSystems.emitterShape(%d)", i)
58 if not hasXMLProperty(xmlFile, keyPS) then
59 break
60 end
61 local emitterShape = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, keyPS.."#node"))
62 local particleType = getXMLString(xmlFile, keyPS.."#particleType")
63 if emitterShape ~= nil then
64 local fillType = FillUtil.FILLTYPE_WOODCHIPS
65 local particleSystem = MaterialUtil.getParticleSystem(fillType, particleType)
66 if particleSystem ~= nil then
67 table.insert(self.particleSystems, ParticleUtil.copyParticleSystem(xmlFile, keyPS, particleSystem, emitterShape))
68 end
69 end
70 i = i + 1
71 end
72
73 if #self.particleSystems == 0 then
74 self.particleSystems = nil
75 end
76
77 self.handNode = Utils.getNoNil(Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.chainsaw.handNode#index")), self.rootNode)
78 self.handNodeRotation = Utils.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.chainsaw.handNode#rotation"), "0 0 0"), 3)
79
80 self.equipmentUVs = Utils.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.chainsaw.equipment#uvs"), "0 0"), 2)
81
82 self.chain = Utils.loadScrollers(self.rootNode, xmlFile, "handTool.chainsaw.chain", {}, false)
83 table.getn(self.chain)
84
85 self.sampleStart = SoundUtil.loadSample(xmlFile, {}, "handTool.chainsaw.startSound", nil, self.baseDirectory)
86 self.sampleIdle = SoundUtil.loadSample(xmlFile, {}, "handTool.chainsaw.idleSound", nil, self.baseDirectory)
87 self.sampleWorkUp = SoundUtil.loadSample(xmlFile, {}, "handTool.chainsaw.workUpSound", nil, self.baseDirectory)
88 self.sampleWork = SoundUtil.loadSample(xmlFile, {}, "handTool.chainsaw.workSound", nil, self.baseDirectory)
89 self.sampleWorkDown = SoundUtil.loadSample(xmlFile, {}, "handTool.chainsaw.workDownSound", nil, self.baseDirectory)
90 self.sampleStop = SoundUtil.loadSample(xmlFile, {}, "handTool.chainsaw.stopSound", nil, self.baseDirectory)
91 self.sampleQuickTap = SoundUtil.loadSample(xmlFile, {}, "handTool.chainsaw.quickTapSound", nil, self.baseDirectory)
92
93 self.soundIdlePitchMax = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.chainsaw.idleSound#pitchMax"), 2.0)
94
95 self.samplesBranch = {}
96 local i=0
97 while true do
98 if not hasXMLProperty(xmlFile, string.format("handTool.chainsaw.branchSounds.branchSound(%d)#file",i)) then
99 break
100 end
101 local sampleBranch = SoundUtil.loadSample(xmlFile, {}, string.format("handTool.chainsaw.branchSounds.branchSound(%d)",i), nil, self.baseDirectory)
102 table.insert(self.samplesBranch, sampleBranch)
103 i = i + 1
104 end
105 self.samplesBranchCount = i
106 self.samplesBranchActiveTimer = 0
107
108 local filename = getXMLString(xmlFile, "handTool.chainsaw.ringSelector#file")
109 if filename ~= nil then
110 local i3dNode = Utils.loadSharedI3DFile(filename, self.baseDirectory, false, false, false)
111 if i3dNode ~= 0 then
112 self.ringSelectorFilename = filename
113 self.ringSelector = getChildAt(i3dNode, 0)
114 self.ringSelectorScaleOffset = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.chainsaw.ringSelector#scaleOffset"), 0.3)
115 setVisibility(self.ringSelector, false)
116 link(self.cutNode, self.ringSelector)
117 delete(i3dNode)
118 end
119 end
120 end
121
122 self.needGloves = true
123 self.needHelmet = true
124 self.lastWorkTime = 0
125 self.maxWorkTime = 300
126
127 self.speedFactor = 0
128
129 self.offsetY = 0
130 self.moveSpeedY = 0.0001
131 self.speedFactor = 0
132
133 self.startDuration = self.sampleStart.duration * 0.5 -- during the first half of the start sample the idle sample is faded in
134 self.startTime = 0
135
136 self.quickTapDuration = 0
137 self.quickTapDurationTime = 250 -- mouse/button presses shorter than this will play the quick tap sound
138 self.lastQuickTapTime = 0
139 self.quickTapMinDelay = 250 -- quick tap sound won't play again until after this amount of time
140
141 self.workUpStartTime = 0
142 self.workUpDuration = self.sampleWorkUp.duration - 20 -- shorter duration for transition between WorkUp & Work
143 self.workUpPlayed = false
144 self.workPlaying = false
145
146 self.isCutting = false
147 self.isHorizontalCut = false
148
149 self.currentHandNode = nil
150
151 delete(xmlFile)
152
153 return true
154end

delete

Description
Deleting chainsaw
Definition
delete()
Code
158function Chainsaw:delete()
159 Chainsaw:superClass().delete(self)
160 if self.isClient then
161 ParticleUtil.deleteParticleSystems(self.particleSystems)
162 SoundUtil.deleteSample(self.sampleStart)
163 SoundUtil.deleteSample(self.sampleIdle)
164 SoundUtil.deleteSample(self.sampleWorkUp)
165 SoundUtil.deleteSample(self.sampleWork)
166 SoundUtil.deleteSample(self.sampleWorkDown)
167 SoundUtil.deleteSample(self.sampleStop)
168 SoundUtil.deleteSample(self.sampleQuickTap)
169 for _,v in pairs(self.samplesBranch) do
170 SoundUtil.deleteSample(v)
171 end
172 if self.ringSelectorFilename ~= nil then
173 Utils.releaseSharedI3DFile(self.ringSelectorFilename, self.baseDirectory, true)
174 end
175 end
176end

update

Description
Update
Definition
update(float dt, boolean allowInput)
Arguments
floatdttime since last call in ms
booleanallowInputallow input
Code
182function Chainsaw:update(dt, allowInput)
183 Chainsaw:superClass().update(self, dt, allowInput)
184
185 Utils.updateScrollers(self.chain, dt*self.speedFactor, true)
186
187 if self.isServer then
188 local price = self.pricePerSecond * (dt / 1000)
189 g_currentMission.missionStats:updateStats("expenses", price)
190 g_currentMission:addSharedMoney(-price, "vehicleRunningCost")
191 end
192
193 self.shouldDelimb = false
194
195 local lockPlayerInput = false
196
197 if allowInput then
198 local isCutting = false
199
200 if not SoundUtil.isSamplePlaying(self.sampleStart, 1.5*dt) then
201 SoundUtil.playSample(self.sampleIdle, 0, 0, nil)
202 SoundUtil.playSample(self.sampleWork, 0, 0, 0)
203 SoundUtil.setSampleVolume(self.sampleIdle, self.sampleIdle.volume)
204 else
205 local idleVolume = Utils.clamp((g_currentMission.time - self.startTime) / self.startDuration, 0, self.sampleIdle.volume)
206 SoundUtil.setSampleVolume(self.sampleIdle, idleVolume) -- idle sound fades in during start sound
207 end
208
209 setRotation(self.graphicsNode, math.rad(math.random(-1, 1))*0.1, math.rad(math.random(-1, 1))*0.1, math.rad(-180))
210
211 if self.curSplitShape == nil then
212 local input = InputBinding.getDigitalInputAxis(InputBinding.AXIS_ROTATE_HANDTOOL)
213 if InputBinding.isAxisZero(input) then
214 input = InputBinding.getAnalogInputAxis(InputBinding.AXIS_ROTATE_HANDTOOL)
215 end
216 lockPlayerInput = input ~= 0
217
218 if input ~= 0 then
219 self.rotationZ = Utils.clamp(self.rotationZ + self.rotationSpeedZ*input*dt, -0.1, 1.57)
220 setRotation(self.rootNode, 0, 0, self.rotationZ)
221 self.player:setIKDirty()
222 end
223
224 self.offsetY = math.max(self.offsetY - 5*self.moveSpeedY*dt, 0)
225 setTranslation(self.graphicsNode, 0, self.offsetY, 0)
226 if self.offsetY ~= 0 then
227 self.player:setIKDirty()
228 end
229 end
230
231 local shape = 0
232 if not self.waitingForResetAfterCut then
233 local x,y,z = getWorldTranslation(self.cutNode)
234 local nx,ny,nz = localDirectionToWorld(self.cutNode, 1,0,0)
235 local yx,yy,yz = localDirectionToWorld(self.cutNode, 0,1,0)
236 if self.curSplitShape ~= nil or self.offsetY == 0 then
237 local minY,maxY, minZ,maxZ
238 if self.curSplitShape == nil or not entityExists(self.curSplitShape) then
239 self.curSplitShape = nil
240 shape, minY,maxY, minZ,maxZ = findSplitShape(x,y,z, nx,ny,nz, yx,yy,yz, self.cutSizeY, self.cutSizeZ)
241
242 if shape ~= nil and shape ~= 0 then
243 local cutTooLow = false
244 local _,y1,_ = localToLocal(self.cutNode, shape, 0,minY,minZ)
245 local _,y3,_ = localToLocal(self.cutNode, shape, 0,maxY,minZ)
246 local _,y4,_ = localToLocal(self.cutNode, shape, 0,maxY,maxZ)
247 cutTooLow = y1 < 0.01 or y1 < 0.01 or y3 < 0.03 or y4 < 0.01
248 if not cutTooLow then
249 local x1,y1,z1 = localToWorld(self.cutNode, 0,minY,minZ)
250 local x2,y2,z2 = localToWorld(self.cutNode, 0,minY,maxZ)
251 local x3,y3,z3 = localToWorld(self.cutNode, 0,maxY,minZ)
252 local x4,y4,z4 = localToWorld(self.cutNode, 0,maxY,maxZ)
253 local h1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,y1,z1)
254 local h2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,y2,z2)
255 local h3 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x3,y3,z3)
256 local h4 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x4,y4,z4)
257 cutTooLow = h1 < 0.01 or h2 < 0.01 or h3 < 0.03 or h4 < 0.01
258 end
259 if cutTooLow then
260 self.player.walkingIsLocked = false
261 self.curSplitShape = nil
262 shape, minY,maxY, minZ,maxZ = 0, nil,nil, nil,nil
263 end
264 end
265 end
266
267 self.curSplitShapeMinY = minY
268 self.curSplitShapeMaxY = maxY
269 self.curSplitShapeMinZ = minZ
270 self.curSplitShapeMaxZ = maxZ
271 end
272 end
273
274 if self.ringSelector ~= nil then
275 setVisibility(self.ringSelector, (self.curSplitShapeMinY ~= nil or self.curSplitShape ~= nil) and g_woodCuttingMarkerEnabled)
276 if g_woodCuttingMarkerEnabled then
277 self:updateRingSelector()
278 end
279 end
280
281 if InputBinding.isPressed(InputBinding.ACTIVATE_HANDTOOL) then
282 self.quickTapDuration = self.quickTapDuration + dt
283
284 self.speedFactor = math.min(self.speedFactor + dt/self.maxWorkTime, 1)
285
286 if self.quickTapDuration > self.quickTapDurationTime then
287 if not self.workUpPlayed then
288 self.workUpStartTime = g_currentMission.time
289 SoundUtil.playSample(self.sampleWorkUp, 1, 0, nil)
290 self.workUpPlayed = true
291 end
292
293 self.lastWorkTime = math.min(self.lastWorkTime+dt, self.maxWorkTime)
294
295 if g_currentMission.time - self.workUpStartTime >= self.workUpDuration then
296 if not SoundUtil.isSamplePlaying(self.sampleWorkUp, 1.5*dt) -- TEST THIS
297 and not self.workPlaying then
298 SoundUtil.setSampleVolume(self.sampleWork, 1)
299 self.workPlaying = true
300 end
301 end
302 end
303
304 if not self.waitingForResetAfterCut then
305 self.shouldDelimb = true
306
307 local x,y,z = getWorldTranslation(self.cutNode)
308 local nx,ny,nz = localDirectionToWorld(self.cutNode, 1,0,0)
309 local yx,yy,yz = localDirectionToWorld(self.cutNode, 0,1,0)
310
311 if self.curSplitShape ~= nil or self.offsetY == 0 then
312 if self.curSplitShape ~= nil and entityExists(self.curSplitShape) then
313 lockPlayerInput = true
314 local minY,maxY, minZ,maxZ = testSplitShape(self.curSplitShape, x,y,z, nx,ny,nz, yx,yy,yz, self.cutSizeY, self.cutSizeZ)
315 if minY == nil then
316 -- cancel cutting if shape can't be cut anymore from current position
317 self.player.walkingIsLocked = false
318 self.curSplitShape = nil
319 SoundUtil.setSamplePitch(self.sampleWork, 1)
320 else
321 local cutTooLow = false
322 local _,y1,_ = localToLocal(self.cutNode, self.curSplitShape, 0,minY,minZ)
323 local _,y3,_ = localToLocal(self.cutNode, self.curSplitShape, 0,maxY,minZ)
324 local _,y4,_ = localToLocal(self.cutNode, self.curSplitShape, 0,maxY,maxZ)
325 cutTooLow = y1 < 0.01 or y1 < 0.01 or y3 < 0.03 or y4 < 0.01
326 if not cutTooLow then
327 local x1,y1,z1 = localToWorld(self.cutNode, 0,minY,minZ)
328 local x2,y2,z2 = localToWorld(self.cutNode, 0,minY,maxZ)
329 local x3,y3,z3 = localToWorld(self.cutNode, 0,maxY,minZ)
330 local x4,y4,z4 = localToWorld(self.cutNode, 0,maxY,maxZ)
331 local h1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,y1,z1)
332 local h2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,y2,z2)
333 local h3 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x3,y3,z3)
334 local h4 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x4,y4,z4)
335 cutTooLow = h1 < 0.01 or h2 < 0.01 or h3 < 0.03 or h4 < 0.01
336 end
337 if cutTooLow then
338 self.player.walkingIsLocked = false
339 self.curSplitShape = nil
340 end
341 end
342 self.curSplitShapeMinY = minY
343 self.curSplitShapeMaxY = maxY
344 self.curSplitShapeMinZ = minZ
345 self.curSplitShapeMaxZ = maxZ
346 else
347 if shape ~= 0 then
348 self.player.walkingIsLocked = true
349 self.curSplitShape = shape
350 end
351 end
352
353 self:updateRingSelector()
354
355 if self.curSplitShape ~= nil then
356 isCutting = true
357 self.offsetY = self.offsetY + self.moveSpeedY*dt
358 setTranslation(self.graphicsNode, 0, self.offsetY, 0)
359 self.player:setIKDirty()
360
361 if self.offsetY > self.curSplitShapeMinY then
362 self.lastWorkTime = math.min(self.lastWorkTime, self.maxWorkTime*0.7)
363 SoundUtil.setSamplePitch(self.sampleWork, 0.96)
364 end
365
366 if self.offsetY > self.curSplitShapeMaxY then
367 if g_currentMission:getIsServer() then
368 ChainsawUtil.cutSplitShape(self.curSplitShape, x,y,z, nx,ny,nz, yx,yy,yz, self.cutSizeY, self.cutSizeZ)
369 else
370 g_client:getServerConnection():sendEvent(ChainsawCutEvent:new(self.curSplitShape, x,y,z, nx,ny,nz, yx,yy,yz, self.cutSizeY, self.cutSizeZ))
371 end
372 self.player.walkingIsLocked = false
373 self.waitingForResetAfterCut = true
374 self.curSplitShape = nil
375 self.curSplitShapeMinY = nil
376 SoundUtil.setSamplePitch(self.sampleWork, 1)
377 end
378 end
379 end
380 end
381 else
382 self.speedFactor = math.max(self.speedFactor - dt/self.maxWorkTime, 0)
383 self.waitingForResetAfterCut = false
384 self.player.walkingIsLocked = false
385 self.curSplitShape = nil
386 self.curSplitShapeMinY = nil
387 self.lastWorkTime = math.max(self.lastWorkTime - dt, 0)
388
389 if self.quickTapDuration > 0 then
390 if self.quickTapDuration < self.quickTapDurationTime then
391 if g_currentMission.time - self.lastQuickTapTime > self.quickTapMinDelay then
392 SoundUtil.playSample(self.sampleQuickTap, 1, 0, nil)
393 self.lastQuickTapTime = g_currentMission.time
394 end
395 else
396 SoundUtil.stopSample(self.sampleWorkUp, true)
397 SoundUtil.setSampleVolume(self.sampleWork, 0)
398 self.workPlaying = false
399 SoundUtil.setSamplePitch(self.sampleWork, 1)
400 SoundUtil.playSample(self.sampleWorkDown, 1, 0, nil)
401 end
402 end
403
404 self.workUpPlayed = false
405 self.quickTapDuration = 0
406 end
407
408 self.player:lockInput(lockPlayerInput)
409
410 if self.particleSystems ~= nil then
411 local active = false
412 if (self.samplesBranchActiveTimer > g_currentMission.time) or (self.curSplitShapeMinY ~= nil and self.curSplitShapeMaxY ~= nil and self.offsetY > self.curSplitShapeMinY and self.offsetY < self.curSplitShapeMaxY) then
413 active = true
414 end
415 for _, ps in pairs(self.particleSystems) do
416 ParticleUtil.setEmittingState(ps, active)
417 end
418 end
419
420 local idlePitch = Utils.lerp(self.sampleIdle.pitchOffset, self.soundIdlePitchMax, Utils.clamp(self.lastWorkTime/self.maxWorkTime, 0, 1))
421 SoundUtil.setSamplePitch(self.sampleIdle, idlePitch)
422
423 self:setCutting(isCutting, self.rotationZ > 0.7)
424 end
425end

updateRingSelector

Description
Update ring selector
Definition
updateRingSelector()
Code
429function Chainsaw:updateRingSelector()
430 if self.curSplitShape ~= nil then
431 setShaderParameter(self.ringSelector, "colorScale", 0.395, 0.925, 0.115, 1, false)
432 else
433 setShaderParameter(self.ringSelector, "colorScale", 0.098, 0.450, 0.960, 1, false)
434 end
435
436 if self.curSplitShapeMinY ~= nil then
437 local a,b,c = localToWorld(self.cutNode, 0, (self.curSplitShapeMinY+self.curSplitShapeMaxY)*0.5, (self.curSplitShapeMinZ+self.curSplitShapeMaxZ)*0.5)
438 local x, y, z = worldToLocal(getParent(self.ringSelector), a,b,c)
439 setTranslation(self.ringSelector, x,y,z)
440 local scale = math.max(self.curSplitShapeMaxY-self.curSplitShapeMinY + self.ringSelectorScaleOffset, self.curSplitShapeMaxZ-self.curSplitShapeMinZ + self.ringSelectorScaleOffset)
441 setScale(self.ringSelector, 1, scale, scale)
442 end
443end

updateTick

Description
Update tick
Definition
updateTick(float dt, boolean allowInput)
Arguments
floatdttime since last call in ms
booleanallowInputallow input
Code
449function Chainsaw:updateTick(dt, allowInput)
450 Chainsaw:superClass().updateTick(self, dt, allowInput)
451 if self.isClient then
452 if self.shouldDelimb then
453 local x,y,z = getWorldTranslation(self.cutNode)
454 local nx,ny,nz = localDirectionToWorld(self.cutNode, 1,0,0)
455 local yx,yy,yz = localDirectionToWorld(self.cutNode, 0,1,0)
456 if g_server == nil then
457 g_client:getServerConnection():sendEvent(ChainsawDelimbEvent:new(self.player, x,y,z, nx,ny,nz, yx,yy,yz, false))
458 else
459 local ret = findAndRemoveSplitShapeAttachments(x,y,z, nx,ny,nz, yx,yy,yz, 0.7, self.cutSizeY, self.cutSizeZ)
460 if ret then
461 self:setOnDelimb(true)
462 end
463 end
464 end
465 end
466end

setCutting

Description
Set cutting
Definition
setCutting(boolean isCutting, boolean isHorizontalCut, boolean noEventSend)
Arguments
booleanisCuttingis cutting
booleanisHorizontalCutis horizontal cut
booleannoEventSendno event send
Code
473function Chainsaw:setCutting(isCutting, isHorizontalCut, noEventSend)
474 ChainsawStateEvent.sendEvent(self.player, isCutting, isHorizontalCut, noEventSend)
475 self.isCutting = isCutting
476 self.isHorizontalCut = isHorizontalCut
477 if g_currentMission.player ~= self.player then
478 self.player:setCuttingAnim(isCutting, isHorizontalCut)
479 end
480end

setOnDelimb

Description
Set on delimb
Definition
setOnDelimb(boolean state)
Arguments
booleanstatenew state
Code
485function Chainsaw:setOnDelimb(state)
486 if state == true then
487 if not (self.samplesBranchActiveTimer > g_currentMission.time) then
488 local idx = math.floor(math.random(1, self.samplesBranchCount))
489 SoundUtil.playSample(self.samplesBranch[idx], 1, 0, nil)
490 self.samplesBranchActiveTimer = g_currentMission.time + self.samplesBranch[idx].duration
491
492 self.lastWorkTime = math.max(0, self.lastWorkTime - 160) --10*dt)
493 end
494 end
495end

setHandNode

Description
Set hand node
Definition
setHandNode(integer handNode)
Arguments
integerhandNodehand node id
Code
507function Chainsaw:setHandNode(handNode)
508 Chainsaw:superClass().setHandNode(self, handNode)
509 if self.currentHandNode ~= handNode then
510 if g_currentMission.player ~= self.player then
511 link(handNode, self.rootNode)
512 self.currentHandNode = handNode
513 setRotation(self.rootNode, unpack(self.handNodeRotation))
514 local x,y,z = getWorldTranslation(self.handNode)
515 x,y,z = worldToLocal(getParent(self.rootNode), x,y,z)
516 local a,b,c = getTranslation(self.rootNode)
517 setTranslation(self.rootNode, a-x,b-y,c-z)
518 end
519 end
520end

onActivate

Description
On activate
Definition
onActivate(boolean allowInput)
Arguments
booleanallowInputallow input
Code
525function Chainsaw:onActivate(allowInput)
526 Chainsaw:superClass().onActivate(self)
527 self.startTime = g_currentMission.time
528 self.player:setEquipmentUVs(self.equipmentUVs)
529 if self.isClient and allowInput then
530 SoundUtil.playSample(self.sampleStart, 1, 0, nil)
531 SoundUtil.playSample(self.sampleIdle, 0, 0, 0)
532 SoundUtil.playSample(self.sampleWork, 0, 0, 0)
533 end
534end

onDeactivate

Description
On deactivate
Definition
onDeactivate(boolean allowInput)
Arguments
booleanallowInputallow input
Code
539function Chainsaw:onDeactivate(allowInput)
540 Chainsaw:superClass().onDeactivate(self)
541 self.speedFactor = 0
542 self.curSplitShape = nil
543 self.player.walkingIsLocked = false
544 if self.isClient then
545 if allowInput then
546 SoundUtil.playSample(self.sampleStop, 1, 0, nil)
547 end
548 self.offsetY = 0
549 setTranslation(self.graphicsNode, 0, 0, 0)
550 if self.particleSystems ~= nil then
551 for _, ps in pairs(self.particleSystems) do
552 ParticleUtil.resetNumOfEmittedParticles(ps)
553 ParticleUtil.setEmittingState(ps, false)
554 end
555 end
556 SoundUtil.stopSample(self.sampleStart, true)
557 SoundUtil.stopSample(self.sampleIdle, true)
558 SoundUtil.stopSample(self.sampleWorkUp, true)
559 SoundUtil.stopSample(self.sampleWork, true)
560 SoundUtil.stopSample(self.sampleWorkDown, true)
561 SoundUtil.stopSample(self.sampleQuickTap, true)
562 end
563end

HandTool

Description
Class for handtools

registerHandTool

Description
Register handtool type
Definition
registerHandTool(string typeName, table classObject)
Arguments
stringtypeNamename of new type
tableclassObjectclass object

new

Description
Creating handtool object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
30function HandTool:new(isServer, isClient, customMt)
31 local mt = customMt;
32 if mt == nil then
33 mt = HandTool_mt;
34 end;
35
36 local self = Object:new(isServer, isClient, mt);
37 self.static = true;
38 self.owner = nil;
39 self.price = 0;
40 self.age = 0;
41 return self;
42end;

load

Description
Load chainsaw from xml file
Definition
load(string xmlFilename, table player)
Arguments
stringxmlFilenamexml file name
tableplayerplayer
Return Values
booleansuccesssuccess
Code
49function HandTool:load(xmlFilename, player)
50 self.configFileName = xmlFilename;
51
52 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(xmlFilename);
53
54 local xmlFile = loadXMLFile("TempXML", xmlFilename);
55 if xmlFile == 0 then
56 return false;
57 end;
58 local i3dFilename = getXMLString(xmlFile, "handTool.filename");
59 self.position = Utils.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.position#value"), "0 0 0"), 3);
60 self.rotation = Utils.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.rotation#value"), "0 0 0"), 3);
61
62 if i3dFilename == nil then
63 delete(xmlFile);
64 return false;
65 end;
66 self.i3dFilename = Utils.getFilename(i3dFilename, self.baseDirectory);
67
68 local node = Utils.loadSharedI3DFile(self.i3dFilename);
69 self.rootNode = getChildAt(node, 0);
70 self.player = player;
71
72 local storeItem = StoreItemsUtil.storeItemsByXMLFilename[self.configFileName:lower()]
73 if self.price == 0 or self.price == nil then
74 self.price = StoreItemsUtil.getDefaultPrice(storeItem);
75 end
76
77 if g_currentMission ~= nil and storeItem.canBeSold then
78 g_currentMission.environment:addDayChangeListener(self)
79 end
80
81 self.targets = {};
82 IKUtil.loadIKChainTargets(xmlFile, "handTool.targets", self.rootNode, self.targets);
83
84 link(player.toolsRootNode, self.rootNode);
85 setTranslation(self.rootNode, self.position[1], self.position[2], self.position[3]);
86 setRotation(self.rootNode, self.rotation[1], self.rotation[2], self.rotation[3]);
87
88 delete(node);
89 delete(xmlFile);
90 setVisibility(self.rootNode, false);
91
92 if player.isOwner then
93 g_currentMission:addHandTool(self);
94 end;
95
96 return true;
97end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection, table player)
Arguments
integerstreamIdstream ID
tableconnectionconnection
tableplayerplayer
Code
107function HandTool:readStream(streamId, connection, player)
108 local filename = Utils.convertFromNetworkFilename(streamReadString(streamId));
109 self:load(filename, player);
110 self.age = streamReadUInt16(streamId);
111 self.price = streamReadUInt16(streamId);
112end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
118function HandTool:writeStream(streamId, connection)
119 streamWriteString(streamId, Utils.convertToNetworkFilename(self.configFileName));
120 streamWriteUInt16(streamId, self.age);
121 streamWriteUInt16(streamId, self.price);
122end;

delete

Description
Deleting handtool
Definition
delete()
Code
126function HandTool:delete()
127 if g_currentMission ~= nil then
128 g_currentMission.environment:removeDayChangeListener(self)
129 end
130 if self.player.isOwner then
131 g_currentMission:removeHandTool(self);
132 end;
133 if self.rootNode ~= nil and self.rootNode ~= 0 then
134 Utils.releaseSharedI3DFile(self.i3dFilename, nil, true);
135 delete(self.rootNode);
136 end;
137end;

onActivate

Description
On activate
Definition
onActivate(boolean allowInput)
Arguments
booleanallowInputallow input
Code
151function HandTool:onActivate(allowInput)
152 setVisibility(self.rootNode, true);
153end;

onDeactivate

Description
On deactivate
Definition
onDeactivate(boolean allowInput)
Arguments
booleanallowInputallow input
Code
158function HandTool:onDeactivate(allowInput)
159 setVisibility(self.rootNode, false);
160end;

getDailyUpKeep

Description
Get daily up keep
Definition
getDailyUpKeep()
Return Values
floatdailyUpKeepdaily up keep
Code
175function HandTool:getDailyUpKeep()
176 local storeItem = StoreItemsUtil.storeItemsByXMLFilename[self.configFileName:lower()]
177 local multiplier = 1
178 if storeItem.lifetime ~= nil and storeItem.lifetime ~= 0 then
179 local ageMultiplier = math.min(self.age/storeItem.lifetime, 1)
180 multiplier = EconomyManager.MAX_DAILYUPKEEP_MULTIPLIER * ageMultiplier
181 end
182 return StoreItemsUtil.getDailyUpkeep(storeItem, nil) * multiplier
183end

getSellPrice

Description
Get sell price
Definition
getSellPrice()
Return Values
floatsellPricesell price
Code
188function HandTool:getSellPrice()
189 local priceMultiplier = 0.5
190 local maxVehicleAge = StoreItemsUtil.storeItemsByXMLFilename[self.configFileName:lower()].lifetime;
191
192 if maxVehicleAge ~= nil and maxVehicleAge ~= 0 then
193 priceMultiplier = priceMultiplier * math.exp(-3.5 * math.min(self.age/maxVehicleAge, 1))
194 end
195
196 return math.floor(self.price * math.max(priceMultiplier, 0.05));
197end

dayChanged

Description
Called if day changed
Definition
dayChanged()
Code
201function HandTool:dayChanged()
202 self.age = self.age + 1;
203end

AIVehicleRotateLeftEvent

Description
Event for ai rotate left

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AIVehicleRotateLeftEvent:emptyNew()
16 local self = Event:new(AIVehicleRotateLeftEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object)
Arguments
tableobjectobject
Code
23function AIVehicleRotateLeftEvent:new(object)
24 local self = AIVehicleRotateLeftEvent:emptyNew()
25 self.object = object;
26 return self;
27end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
33function AIVehicleRotateLeftEvent:readStream(streamId, connection)
34 self.object = readNetworkNodeObject(streamId);
35 self:run(connection);
36end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function AIVehicleRotateLeftEvent:writeStream(streamId, connection)
43 writeNetworkNodeObject(streamId, self.object);
44end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
49function AIVehicleRotateLeftEvent:run(connection)
50 AIVehicle.aiRotateLeft(self.object);
51end;

AIVehicleRotateRightEvent

Description
Event for ai rotate right

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AIVehicleRotateRightEvent:emptyNew()
16 local self = Event:new(AIVehicleRotateRightEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object)
Arguments
tableobjectobject
Code
23function AIVehicleRotateRightEvent:new(object)
24 local self = AIVehicleRotateRightEvent:emptyNew()
25 self.object = object;
26 return self;
27end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
33function AIVehicleRotateRightEvent:readStream(streamId, connection)
34 self.object = readNetworkNodeObject(streamId);
35 self:run(connection);
36end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function AIVehicleRotateRightEvent:writeStream(streamId, connection)
43 writeNetworkNodeObject(streamId, self.object);
44end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
49function AIVehicleRotateRightEvent:run(connection)
50 AIVehicle.aiRotateRight(self.object);
51end;

AIVehicleSetConveyorBeltAngleEvent

Description
Event for conveyor belt angle

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AIVehicleSetConveyorBeltAngleEvent:emptyNew()
16 local self = Event:new(AIVehicleSetConveyorBeltAngleEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle, integer currentAngle)
Arguments
tablevehiclevehicle
integercurrentAnglecurrent angle
Code
24function AIVehicleSetConveyorBeltAngleEvent:new(vehicle, currentAngle)
25 local self = AIVehicleSetConveyorBeltAngleEvent:emptyNew()
26 self.currentAngle = currentAngle;
27 self.vehicle = vehicle;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function AIVehicleSetConveyorBeltAngleEvent:readStream(streamId, connection)
36 self.vehicle = readNetworkNodeObject(streamId);
37 self.currentAngle = streamReadInt8(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function AIVehicleSetConveyorBeltAngleEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.vehicle);
47 streamWriteInt8(streamId, self.currentAngle);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function AIVehicleSetConveyorBeltAngleEvent:run(connection)
54 self.vehicle:setAIConveyorBeltAngle(self.currentAngle, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(AIVehicleSetConveyorBeltAngleEvent:new(self.vehicle, self.currentAngle), nil, connection, self.vehicle);
57 end;
58end;

AIVehicleSetStartedEvent

Description
Event for ai start

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AIVehicleSetStartedEvent:emptyNew()
16 local self = Event:new(AIVehicleSetStartedEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer reason, boolean isStarted, integer helper)
Arguments
tableobjectobject
integerreasonreason
booleanisStartedis started
integerhelperhelper id
Code
26function AIVehicleSetStartedEvent:new(object, reason, isStarted, helper)
27 local self = AIVehicleSetStartedEvent:emptyNew()
28 self.object = object;
29 self.isStarted = isStarted;
30 self.reason = reason
31 if helper ~= nil then
32 self.helperIndex = helper.index
33 end
34 return self;
35end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
41function AIVehicleSetStartedEvent:readStream(streamId, connection)
42 self.object = readNetworkNodeObject(streamId);
43 self.isStarted = streamReadBool(streamId);
44 if not self.isStarted then
45 self.reason = streamReadUIntN(streamId, AIVehicle.NUM_BITS_REASONS)
46 else
47 self.helperIndex = streamReadUInt8(streamId)
48 end
49 self:run(connection);
50end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
56function AIVehicleSetStartedEvent:writeStream(streamId, connection)
57 writeNetworkNodeObject(streamId, self.object);
58 streamWriteBool(streamId, self.isStarted);
59 if not self.isStarted then
60 streamWriteUIntN(streamId, self.reason, AIVehicle.NUM_BITS_REASONS)
61 else
62 streamWriteUInt8(streamId, self.helperIndex)
63 end
64end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
69function AIVehicleSetStartedEvent:run(connection)
70 if self.isStarted then
71 self.object:startAIVehicle(self.helperIndex, true);
72 else
73 self.object:stopAIVehicle(self.reason, true);
74 end;
75 if not connection:getIsServer() then
76 for _, v in pairs(g_server.clientConnections) do
77 if v ~= connection and not v:getIsLocal() then
78 v:sendEvent(AIVehicleSetStartedEvent:new(self.object, self.reason, self.isStarted, HelperUtil.helperIndexToDesc[self.helperIndex]));
79 end;
80 end;
81 end;
82end;

AnimatedVehicleStartEvent

Description
Event for animation start

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AnimatedVehicleStartEvent:emptyNew()
16 local self = Event:new(AnimatedVehicleStartEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, string name, float speed, float animTime)
Arguments
tableobjectobject
stringnamename of animation
floatspeedspeed of animation
floatanimTimetime of animation
Code
26function AnimatedVehicleStartEvent:new(object, name, speed, animTime)
27 local self = AnimatedVehicleStartEvent:emptyNew()
28 self.name = name;
29 self.speed = speed;
30 self.animTime = animTime;
31 self.object = object;
32 return self;
33end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
39function AnimatedVehicleStartEvent:readStream(streamId, connection)
40 self.object = readNetworkNodeObject(streamId);
41 self.name = streamReadString(streamId);
42 self.speed = streamReadFloat32(streamId);
43 self.animTime = streamReadFloat32(streamId);
44
45 self.object:playAnimation(self.name, self.speed, self.animTime, true);
46 if not connection:getIsServer() then
47 g_server:broadcastEvent(AnimatedVehicleStartEvent:new(self.object, self.name, self.speed, self.animTime), nil, connection, self.object);
48 end;
49end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
55function AnimatedVehicleStartEvent:writeStream(streamId, connection)
56 writeNetworkNodeObject(streamId, self.object);
57 streamWriteString(streamId, self.name);
58 streamWriteFloat32(streamId, self.speed);
59 streamWriteFloat32(streamId, self.animTime);
60end;

AnimatedVehicleStopEvent

Description
Event for animation stop

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AnimatedVehicleStopEvent:emptyNew()
16 local self = Event:new(AnimatedVehicleStopEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, string name)
Arguments
tableobjectobject
stringnamename
Code
24function AnimatedVehicleStopEvent:new(object, name)
25 local self = AnimatedVehicleStopEvent:emptyNew()
26 self.name = name;
27 self.object = object;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function AnimatedVehicleStopEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.name = streamReadString(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function AnimatedVehicleStopEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteString(streamId, self.name);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function AnimatedVehicleStopEvent:run(connection)
54 AnimatedVehicle.stopAnimation(self.object, self.name, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(AnimatedVehicleStopEvent:new(self.object, self.name), nil, connection, self.object);
57 end;
58end;

BaleLoaderStateEvent

Description
Event for bale loader state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function BaleLoaderStateEvent:emptyNew()
16 local self = Event:new(BaleLoaderStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer stateId, integer nearestBaleServerId)
Arguments
tableobjectobject
integerstateIdstateId
integernearestBaleServerIdnearestBaleServerId
Code
25function BaleLoaderStateEvent:new(object, stateId, nearestBaleServerId)
26 local self = BaleLoaderStateEvent:emptyNew()
27 self.object = object;
28 self.stateId = stateId;
29 assert(nearestBaleServerId ~= nil or self.stateId ~= BaleLoader.CHANGE_GRAB_BALE);
30 self.nearestBaleServerId = nearestBaleServerId;
31 return self;
32end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
38function BaleLoaderStateEvent:readStream(streamId, connection)
39 self.object = readNetworkNodeObject(streamId);
40
41 self.stateId = streamReadInt8(streamId);
42 if self.stateId == BaleLoader.CHANGE_GRAB_BALE then
43 self.nearestBaleServerId = readNetworkNodeObjectId(streamId);
44 end;
45 self:run(connection);
46end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
52function BaleLoaderStateEvent:writeStream(streamId, connection)
53 writeNetworkNodeObject(streamId, self.object);
54 streamWriteInt8(streamId, self.stateId);
55 if self.stateId == BaleLoader.CHANGE_GRAB_BALE then
56 writeNetworkNodeObjectId(streamId, self.nearestBaleServerId);
57 end;
58end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
63function BaleLoaderStateEvent:run(connection)
64 self.object:doStateChange(self.stateId, self.nearestBaleServerId);
65end;

BalerCreateBaleEvent

Description

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function BalerCreateBaleEvent:emptyNew()
15 local self = Event:new(BalerCreateBaleEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table object, integer baleFillType, float baleTime)
Arguments
tableobjectobject
integerbaleFillTypebale fill type
floatbaleTimebale time
Code
24function BalerCreateBaleEvent:new(object, baleFillType, baleTime)
25 local self = BalerCreateBaleEvent:emptyNew()
26 self.baleFillType = baleFillType;
27 self.baleTime = baleTime;
28 self.object = object;
29 return self;
30end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function BalerCreateBaleEvent:readStream(streamId, connection)
37 self.object = readNetworkNodeObject(streamId);
38 self.baleTime = streamReadFloat32(streamId);
39 self.baleFillType = streamReadUIntN(streamId, FillUtil.sendNumBits);
40 self:run(connection);
41end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
47function BalerCreateBaleEvent:writeStream(streamId, connection)
48 writeNetworkNodeObject(streamId, self.object);
49 streamWriteFloat32(streamId, self.baleTime);
50 streamWriteUIntN(streamId, self.baleFillType, FillUtil.sendNumBits);
51end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
56function BalerCreateBaleEvent:run(connection)
57 self.object:createBale(self.baleFillType);
58 self.object:setBaleTime(table.getn(self.object.baler.bales), self.baleTime);
59end;

BalerSetBaleTimeEvent

Description

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function BalerSetBaleTimeEvent:emptyNew()
15 local self = Event:new(BalerSetBaleTimeEvent_mt);
16 return self;
17end;

BalerSetBaleTimeEvent:new

Description
Create new instance of event
Definition
BalerSetBaleTimeEvent:new(table object, integer bale, float baleTime)
Arguments
tableobjectobject
integerbalebale id
floatbaleTimebale time
Code
24function BalerSetBaleTimeEvent:new(object, bale, baleTime)
25 local self = BalerSetBaleTimeEvent:emptyNew()
26 self.object = object;
27 self.bale = bale;
28 self.baleTime = baleTime;
29 return self;
30end;

BalerSetBaleTimeEvent:readStream

Description
Called on client side on join
Definition
BalerSetBaleTimeEvent:readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function BalerSetBaleTimeEvent:readStream(streamId, connection)
37 self.object = readNetworkNodeObject(streamId);
38 self.bale = streamReadInt32(streamId);
39 self.baleTime = streamReadFloat32(streamId);
40 self:run(connection);
41end;

BalerSetBaleTimeEvent:writeStream

Description
Called on server side on join
Definition
BalerSetBaleTimeEvent:writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
47function BalerSetBaleTimeEvent:writeStream(streamId, connection)
48 writeNetworkNodeObject(streamId, self.object);
49 streamWriteInt32(streamId, self.bale);
50 streamWriteFloat32(streamId, self.baleTime);
51end;

BalerSetBaleTimeEvent:run

Description
Run action on receiving side
Definition
BalerSetBaleTimeEvent:run(integer connection)
Arguments
integerconnectionconnection
Code
56function BalerSetBaleTimeEvent:run(connection)
57 self.object:setBaleTime(self.bale, self.baleTime);
58end;

BalerSetIsUnloadingBaleEvent

Description
Event for baler is unloading state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function BalerSetIsUnloadingBaleEvent:emptyNew()
16 local self = Event:new(BalerSetIsUnloadingBaleEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isUnloadingBale)
Arguments
tableobjectobject
booleanisUnloadingBaleis unloading bale
Code
24function BalerSetIsUnloadingBaleEvent:new(object, isUnloadingBale)
25 local self = BalerSetIsUnloadingBaleEvent:emptyNew()
26 self.object = object;
27 self.isUnloadingBale = isUnloadingBale;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function BalerSetIsUnloadingBaleEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.isUnloadingBale = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function BalerSetIsUnloadingBaleEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isUnloadingBale);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function BalerSetIsUnloadingBaleEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 self.object:setIsUnloadingBale(self.isUnloadingBale, true);
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean isUnloadingBale, boolean noEventSend)
Arguments
tableobjectobject
booleanisUnloadingBaleisUnloadingBale
booleannoEventSendno event send
Code
65function BalerSetIsUnloadingBaleEvent.sendEvent(object, isUnloadingBale, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(BalerSetIsUnloadingBaleEvent:new(object, isUnloadingBale), nil, nil, object);
69 else
70 g_client:getServerConnection():sendEvent(BalerSetIsUnloadingBaleEvent:new(object, isUnloadingBale));
71 end;
72 end;
73end;

BaleWrapperStateEvent

Description
Event for bale wrapper state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function BaleWrapperStateEvent:emptyNew()
16 local self = Event:new(BaleWrapperStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer stateId, integer nearestBaleServerId)
Arguments
tableobjectobject
integerstateIdstate id
integernearestBaleServerIdserver id of nearest bale
Code
25function BaleWrapperStateEvent:new(object, stateId, nearestBaleServerId)
26 local self = BaleWrapperStateEvent:emptyNew()
27 self.object = object;
28 self.stateId = stateId;
29 assert(nearestBaleServerId ~= nil or self.stateId ~= BaleWrapper.CHANGE_GRAB_BALE);
30 self.nearestBaleServerId = nearestBaleServerId;
31 return self;
32end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
38function BaleWrapperStateEvent:readStream(streamId, connection)
39 self.object = readNetworkNodeObject(streamId);
40 self.stateId = streamReadInt8(streamId);
41 if self.stateId == BaleWrapper.CHANGE_GRAB_BALE then
42 self.nearestBaleServerId = readNetworkNodeObjectId(streamId);
43 end;
44 self:run(connection);
45end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
51function BaleWrapperStateEvent:writeStream(streamId, connection)
52 writeNetworkNodeObject(streamId, self.object);
53 streamWriteInt8(streamId, self.stateId);
54 if self.stateId == BaleWrapper.CHANGE_GRAB_BALE then
55 writeNetworkNodeObjectId(streamId, self.nearestBaleServerId);
56 end;
57end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
62function BaleWrapperStateEvent:run(connection)
63 self.object:doStateChange(self.stateId, self.nearestBaleServerId);
64end;

BunkerSiloCloseEvent

Description
Event for bunker silo close

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
13function BunkerSiloCloseEvent:emptyNew()
14 local self = Event:new(BunkerSiloCloseEvent_mt);
15 return self;
16end;

new

Description
Create new instance of event
Definition
new(table bunkerSilo)
Arguments
tablebunkerSilobunkerSilo
Return Values
tableinstanceinstance of event
Code
22function BunkerSiloCloseEvent:new(bunkerSilo)
23 local self = BunkerSiloCloseEvent:emptyNew()
24 self.bunkerSilo = bunkerSilo;
25 return self;
26end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
32function BunkerSiloCloseEvent:readStream(streamId, connection)
33 if not connection:getIsServer() then
34 self.bunkerSilo = readNetworkNodeObject(streamId);
35 end;
36 self:run(connection);
37end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
43function BunkerSiloCloseEvent:writeStream(streamId, connection)
44 if connection:getIsServer() then
45 writeNetworkNodeObject(streamId, self.bunkerSilo);
46 end;
47end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
52function BunkerSiloCloseEvent:run(connection)
53 if not connection:getIsServer() then
54 self.bunkerSilo:setState(BunkerSilo.STATE_CLOSED);
55 end;
56end;

BunkerSiloOpenEvent

Description
Event for bunker silo open

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
13function BunkerSiloOpenEvent:emptyNew()
14 local self = Event:new(BunkerSiloOpenEvent_mt);
15 return self;
16end;

new

Description
Create new instance of event
Definition
new(table bunkerSilo, float x, float y, float z)
Arguments
tablebunkerSilobunkerSilo
floatxx opening position
floatyy opening position
floatzz opening position
Return Values
tableinstanceinstance of event
Code
25function BunkerSiloOpenEvent:new(bunkerSilo, x,y,z)
26 local self = BunkerSiloOpenEvent:emptyNew()
27 self.bunkerSilo = bunkerSilo;
28 self.x = x;
29 self.y = y;
30 self.z = z;
31 return self;
32end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
38function BunkerSiloOpenEvent:readStream(streamId, connection)
39 if not connection:getIsServer() then
40 self.bunkerSilo = readNetworkNodeObject(streamId);
41 self.x = streamReadFloat32(streamId);
42 self.y = streamReadFloat32(streamId);
43 self.z = streamReadFloat32(streamId);
44 end;
45 self:run(connection);
46end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
52function BunkerSiloOpenEvent:writeStream(streamId, connection)
53 if connection:getIsServer() then
54 writeNetworkNodeObject(streamId, self.bunkerSilo);
55 streamWriteFloat32(streamId, self.x);
56 streamWriteFloat32(streamId, self.y);
57 streamWriteFloat32(streamId, self.z);
58 end;
59end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
64function BunkerSiloOpenEvent:run(connection)
65 if not connection:getIsServer() then
66 self.bunkerSilo:openSilo(self.x, self.y, self.z);
67 end;
68end;

ChainsawCutEvent

Description
Event for cutting

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function ChainsawCutEvent:emptyNew()
15 local self = Event:new(ChainsawCutEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(integer splitShapeId, float x, float y, float z, float nx, float ny, float nz, float yx, float yy, float yz, float cutSizeY, float cutSizeZ)
Arguments
integersplitShapeIdid of split shape
floatxx
floatyy
floatzz
floatnxnx
floatnyny
floatnznz
floatyxyx
floatyyyy
floatyzyz
floatcutSizeYy cut size
floatcutSizeZz cut size
Return Values
tableinstanceinstance of event
Code
34function ChainsawCutEvent:new(splitShapeId, x,y,z, nx,ny,nz, yx,yy,yz, cutSizeY, cutSizeZ)
35 local self = ChainsawCutEvent:emptyNew()
36 self.splitShapeId = splitShapeId;
37 self.x,self.y,self.z = x,y,z;
38 self.nx,self.ny,self.nz = nx,ny,nz;
39 self.yx,self.yy,self.yz = yx,yy,yz;
40 self.cutSizeY,self.cutSizeZ = cutSizeY,cutSizeZ;
41 return self;
42end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
48function ChainsawCutEvent:readStream(streamId, connection)
49 if not connection:getIsServer() then
50 local splitShapeId = readSplitShapeIdFromStream(streamId);
51 local x = streamReadFloat32(streamId);
52 local y = streamReadFloat32(streamId);
53 local z = streamReadFloat32(streamId);
54 local nx = streamReadFloat32(streamId);
55 local ny = streamReadFloat32(streamId);
56 local nz = streamReadFloat32(streamId);
57 local yx = streamReadFloat32(streamId);
58 local yy = streamReadFloat32(streamId);
59 local yz = streamReadFloat32(streamId);
60 local cutSizeY = streamReadFloat32(streamId);
61 local cutSizeZ = streamReadFloat32(streamId);
62 if splitShapeId ~= 0 then
63 ChainsawUtil.cutSplitShape(splitShapeId, x,y,z, nx,ny,nz, yx,yy,yz, cutSizeY, cutSizeZ);
64 end
65 end
66end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
72function ChainsawCutEvent:writeStream(streamId, connection)
73 if connection:getIsServer() then
74 writeSplitShapeIdToStream(streamId, self.splitShapeId);
75 streamWriteFloat32(streamId, self.x);
76 streamWriteFloat32(streamId, self.y);
77 streamWriteFloat32(streamId, self.z);
78 streamWriteFloat32(streamId, self.nx);
79 streamWriteFloat32(streamId, self.ny);
80 streamWriteFloat32(streamId, self.nz);
81 streamWriteFloat32(streamId, self.yx);
82 streamWriteFloat32(streamId, self.yy);
83 streamWriteFloat32(streamId, self.yz);
84 streamWriteFloat32(streamId, self.cutSizeY);
85 streamWriteFloat32(streamId, self.cutSizeZ);
86 end
87end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
92function ChainsawCutEvent:run(connection)
93 print("Error: ChainsawCutEvent is not allowed to be executed on a local client");
94end;

ChainsawDelimbEvent

Description
Event for delimb

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function ChainsawDelimbEvent:emptyNew()
15 local self = Event:new(ChainsawDelimbEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table player, float x, float y, float z, float nx, float ny, float nz, float yx, float yy, float yz, boolean onDelimb)
Arguments
tableplayerplayer
floatxx
floatyy
floatzz
floatnxnx
floatnyny
floatnznz
floatyxyx
floatyyyy
floatyzyz
booleanonDelimbon delimb
Return Values
tableinstanceinstance of event
Code
33function ChainsawDelimbEvent:new(player, x,y,z, nx,ny,nz, yx,yy,yz, onDelimb)
34 local self = ChainsawDelimbEvent:emptyNew()
35 self.player = player;
36 self.x, self.y, self.z = x, y, z;
37 self.nx, self.ny, self.nz = nx, ny, nz;
38 self.yx, self.yy, self.yz = yx, yy, yz;
39 self.onDelimb = onDelimb;
40 return self;
41end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
47function ChainsawDelimbEvent:readStream(streamId, connection)
48 if not connection:getIsServer() then -- server side
49 self.player = readNetworkNodeObject(streamId);
50 self.x = streamReadFloat32(streamId);
51 self.y = streamReadFloat32(streamId);
52 self.z = streamReadFloat32(streamId);
53 self.nx = streamReadFloat32(streamId);
54 self.ny = streamReadFloat32(streamId);
55 self.nz = streamReadFloat32(streamId);
56 self.yx = streamReadFloat32(streamId);
57 self.yy = streamReadFloat32(streamId);
58 self.yz = streamReadFloat32(streamId);
59 self.onDelimb = false;
60 if self.player ~= nil then
61 local chainsaw = self.player.currentTool;
62 if chainsaw ~= nil then
63 local ret = findAndRemoveSplitShapeAttachments(self.x,self.y,self.z, self.nx,self.ny,self.nz, self.yx,self.yy,self.yz, 0.7, chainsaw.cutSizeY, chainsaw.cutSizeZ);
64 if ret then
65 self.onDelimb = true;
66 connection:sendEvent(self);
67 end;
68 end;
69 end;
70 else -- client side
71 self.player = readNetworkNodeObject(streamId);
72 self.onDelimb = streamReadBool(streamId);
73 if self.player ~= nil and self.player.currentTool ~= nil then
74 if self.player.currentTool.setOnDelimb ~= nil then
75 self.player.currentTool:setOnDelimb(self.onDelimb);
76 end;
77 end;
78 end
79end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
85function ChainsawDelimbEvent:writeStream(streamId, connection)
86 if connection:getIsServer() then -- client
87 writeNetworkNodeObject(streamId, self.player);
88 streamWriteFloat32(streamId, self.x);
89 streamWriteFloat32(streamId, self.y);
90 streamWriteFloat32(streamId, self.z);
91 streamWriteFloat32(streamId, self.nx);
92 streamWriteFloat32(streamId, self.ny);
93 streamWriteFloat32(streamId, self.nz);
94 streamWriteFloat32(streamId, self.yx);
95 streamWriteFloat32(streamId, self.yy);
96 streamWriteFloat32(streamId, self.yz);
97 else
98 writeNetworkNodeObject(streamId, self.player);
99 streamWriteBool(streamId, self.onDelimb);
100 end
101end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
106function ChainsawDelimbEvent:run(connection)
107 print("Error: ChainsawDelimbEvent is not allowed to be executed on a local client");
108end;

ChainsawStateEvent

Description
Event for chainsaw state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function ChainsawStateEvent:emptyNew()
15 local self = Event:new(ChainsawStateEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table player, boolean isCutting, boolean isHorizontalCut)
Arguments
tableplayerplayer
booleanisCuttingis cutting
booleanisHorizontalCutis horizontal cutting
Return Values
tableinstanceinstance of event
Code
25function ChainsawStateEvent:new(player, isCutting, isHorizontalCut)
26 local self = ChainsawStateEvent:emptyNew()
27 self.player = player;
28 self.isCutting = isCutting;
29 self.isHorizontalCut = isHorizontalCut;
30 return self;
31end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
37function ChainsawStateEvent:readStream(streamId, connection)
38 self.player = readNetworkNodeObject(streamId);
39 self.isCutting = streamReadBool(streamId);
40 self.isHorizontalCut = streamReadBool(streamId);
41 self:run(connection);
42end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
48function ChainsawStateEvent:writeStream(streamId, connection)
49 writeNetworkNodeObject(streamId, self.player);
50 streamWriteBool(streamId, self.isCutting);
51 streamWriteBool(streamId, self.isHorizontalCut);
52end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
57function ChainsawStateEvent:run(connection)
58 if not connection:getIsServer() then
59 g_server:broadcastEvent(self, false, connection, self.player);
60 end;
61
62 local currentTool = self.player.currentTool;
63 if currentTool ~= nil and currentTool.setCutting ~= nil then
64 currentTool:setCutting(self.isCutting, self.isHorizontalCut, true);
65 end;
66end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table player, boolean isCutting, boolean isHorizontalCut, boolean noEventSend)
Arguments
tableplayerplayer
booleanisCuttingis cutting
booleanisHorizontalCutis horizontal cutting
booleannoEventSendno event send
Code
74function ChainsawStateEvent.sendEvent(player, isCutting, isHorizontalCut, noEventSend)
75 local currentTool = player.currentTool;
76 if currentTool ~= nil and currentTool.setCutting ~= nil and currentTool.isCutting ~= isCutting then
77 if noEventSend == nil or noEventSend == false then
78 if g_server ~= nil then
79 g_server:broadcastEvent(ChainsawStateEvent:new(player, isCutting, isHorizontalCut), nil, nil, player);
80 else
81 g_client:getServerConnection():sendEvent(ChainsawStateEvent:new(player, isCutting, isHorizontalCut));
82 end;
83 end;
84 end;
85end;

CombineStrawEnableEvent

Description
Event for straw enable state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function CombineStrawEnableEvent:emptyNew()
16 local self = Event:new(CombineStrawEnableEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle, boolean isStrawEnabled)
Arguments
tablevehiclevehicle
booleanisStrawEnabledis straw enabled
Code
24function CombineStrawEnableEvent:new(vehicle, isStrawEnabled)
25 local self = CombineStrawEnableEvent:emptyNew()
26 self.vehicle = vehicle;
27 self.isStrawEnabled = isStrawEnabled;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function CombineStrawEnableEvent:readStream(streamId, connection)
36 self.vehicle = readNetworkNodeObject(streamId);
37 self.isStrawEnabled = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function CombineStrawEnableEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.vehicle);
47 streamWriteBool(streamId, self.isStrawEnabled);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function CombineStrawEnableEvent:run(connection)
54 self.vehicle:setIsStrawEnabled(self.isStrawEnabled, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(CombineStrawEnableEvent:new(self.vehicle, self.isStrawEnabled), nil, connection, self.vehicle);
57 end;
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isStrawEnabled, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisStrawEnabledis straw enabled
booleannoEventSendno event send
Code
65function CombineStrawEnableEvent.sendEvent(vehicle, isStrawEnabled, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(CombineStrawEnableEvent:new(vehicle, isStrawEnabled), nil, nil, vehicle);
69 else
70 g_client:getServerConnection():sendEvent(CombineStrawEnableEvent:new(vehicle, isStrawEnabled));
71 end;
72 end;
73end;

DrivableToggleLowerAllEvent

Description
Event for toggle lower all

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function DrivableToggleLowerAllEvent:emptyNew()
16 local self = Event:new(DrivableToggleLowerAllEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle)
Arguments
tablevehiclevehicle
Code
23function DrivableToggleLowerAllEvent:new(vehicle)
24 local self = DrivableToggleLowerAllEvent:emptyNew()
25 self.vehicle = vehicle;
26 return self;
27end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
33function DrivableToggleLowerAllEvent:readStream(streamId, connection)
34 self.vehicle = readNetworkNodeObject(streamId);
35 self:run(connection);
36end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function DrivableToggleLowerAllEvent:writeStream(streamId, connection)
43 writeNetworkNodeObject(streamId, self.vehicle);
44end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
49function DrivableToggleLowerAllEvent:run(connection)
50 self.vehicle:toggleLowerAllImplements(true);
51 if not connection:getIsServer() then
52 g_server:broadcastEvent(DrivableToggleLowerAllEvent:new(self.vehicle), nil, connection, self.object);
53 end;
54end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean noEventSend)
Arguments
tablevehiclevehicle
booleannoEventSendno event send
Code
60function DrivableToggleLowerAllEvent.sendEvent(vehicle, noEventSend)
61 if noEventSend == nil or noEventSend == false then
62 if g_server ~= nil then
63 g_server:broadcastEvent(DrivableToggleLowerAllEvent:new(vehicle), nil, nil, vehicle);
64 else
65 g_client:getServerConnection():sendEvent(DrivableToggleLowerAllEvent:new(vehicle));
66 end;
67 end;
68end;

FoldableSetFoldDirectionEvent

Description
Event for set folding direction

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function FoldableSetFoldDirectionEvent:emptyNew()
16 local self = Event:new(FoldableSetFoldDirectionEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer direction, boolean moveToMiddle)
Arguments
tableobjectobject
integerdirectiondirection
booleanmoveToMiddlemove to middle
Code
25function FoldableSetFoldDirectionEvent:new(object, direction, moveToMiddle)
26 local self = FoldableSetFoldDirectionEvent:emptyNew()
27 self.object = object;
28 self.direction = Utils.sign(direction);
29 self.moveToMiddle = moveToMiddle;
30 return self;
31end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
37function FoldableSetFoldDirectionEvent:readStream(streamId, connection)
38 self.object = readNetworkNodeObject(streamId);
39 self.direction = streamReadUIntN(streamId, 2)-1;
40 self.moveToMiddle = streamReadBool(streamId);
41 self:run(connection);
42end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
48function FoldableSetFoldDirectionEvent:writeStream(streamId, connection)
49 writeNetworkNodeObject(streamId, self.object);
50 streamWriteUIntN(streamId, self.direction+1, 2);
51 streamWriteBool(streamId, self.moveToMiddle);
52end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
57function FoldableSetFoldDirectionEvent:run(connection)
58 if self.object ~= nil then
59 self.object:setFoldState(self.direction, self.moveToMiddle, true);
60 end;
61 if not connection:getIsServer() then
62 g_server:broadcastEvent(FoldableSetFoldDirectionEvent:new(self.object, self.direction, self.moveToMiddle), nil, connection, self.object);
63 end;
64end;

GreenhouseSetIsWaterTankFillingEvent

Description
Event for greenhouse tank filling state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function GreenhouseSetIsWaterTankFillingEvent:emptyNew()
16 local self = Event:new(GreenhouseSetIsWaterTankFillingEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isFilling, table trailer)
Arguments
tableobjectobject
booleanisFillingis filling
tabletrailertrailer
Return Values
tableinstanceinstance of event
Code
26function GreenhouseSetIsWaterTankFillingEvent:new(object, isFilling, trailer)
27 local self = GreenhouseSetIsWaterTankFillingEvent:emptyNew()
28 self.object = object;
29 self.isFilling = isFilling;
30 self.trailer = trailer;
31 return self;
32end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
38function GreenhouseSetIsWaterTankFillingEvent:readStream(streamId, connection)
39 self.object = readNetworkNodeObject(streamId);
40 self.isFilling = streamReadBool(streamId);
41 if self.isFilling and not connection:getIsServer() then
42 self.trailer = readNetworkNodeObject(streamId);
43 end;
44 self:run(connection);
45end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
51function GreenhouseSetIsWaterTankFillingEvent:writeStream(streamId, connection)
52 writeNetworkNodeObject(streamId, self.object);
53 streamWriteBool(streamId, self.isFilling);
54 if self.isFilling and connection:getIsServer() then
55 writeNetworkNodeObject(streamId, self.trailer);
56 end;
57end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
62function GreenhouseSetIsWaterTankFillingEvent:run(connection)
63 if not connection:getIsServer() then
64 g_server:broadcastEvent(self, false, connection, self.object);
65 end;
66 self.object:setIsWaterTankFilling(self.isFilling, self.trailer, true);
67end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean isFilling, table trailer, boolean noEventSend)
Arguments
tableobjectobject
booleanisFillingis filling
tabletrailertrailer
booleannoEventSendno event send
Code
75function GreenhouseSetIsWaterTankFillingEvent.sendEvent(object, isFilling, trailer, noEventSend)
76 if isFilling ~= object.isWaterTankFilling then
77 if noEventSend == nil or noEventSend == false then
78 if g_server ~= nil then
79 g_server:broadcastEvent(GreenhouseSetIsWaterTankFillingEvent:new(object, isFilling, trailer), nil, nil, object);
80 else
81 assert(not isFilling or (trailer ~= nil));
82 g_client:getServerConnection():sendEvent(GreenhouseSetIsWaterTankFillingEvent:new(object, isFilling, trailer));
83 end;
84 end;
85 end;
86end;

HonkEvent

Description
Event for honking

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function HonkEvent:emptyNew()
16 local self = Event:new(HonkEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isPlaying)
Arguments
tableobjectobject
booleanisPlayinghonk is playing
Code
24function HonkEvent:new(object, isPlaying)
25 local self = HonkEvent:emptyNew()
26 self.object = object;
27 self.isPlaying = isPlaying;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function HonkEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.isPlaying = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function HonkEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isPlaying);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function HonkEvent:run(connection)
54 self.object:playHonk(self.isPlaying, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(HonkEvent:new(self.object, self.isPlaying), nil, connection, self.object);
57 end;
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isPlaying, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisPlayinghonk is playing
booleannoEventSendno event send
Code
65function HonkEvent.sendEvent(vehicle, isPlaying, noEventSend)
66 if isPlaying ~= vehicle.honkPlaying then
67 if noEventSend == nil or noEventSend == false then
68 if g_server ~= nil then
69 g_server:broadcastEvent(HonkEvent:new(vehicle, isPlaying), nil, nil, vehicle);
70 else
71 g_client:getServerConnection():sendEvent(HonkEvent:new(vehicle, isPlaying));
72 end;
73 end;
74 end;
75end;

HPWPlaceableStateEvent

Description
Event for hpw state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function HPWPlaceableStateEvent:emptyNew()
16 local self = Event:new(HPWPlaceableStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean doWashing)
Arguments
tableobjectobject
booleandoWashingdo washing
Return Values
tableinstanceinstance of event
Code
25function HPWPlaceableStateEvent:new(object, doWashing)
26 local self = HPWPlaceableStateEvent:emptyNew()
27 self.object = object;
28 self.doWashing = doWashing;
29
30 return self;
31end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
37function HPWPlaceableStateEvent:readStream(streamId, connection)
38 self.object = readNetworkNodeObject(streamId);
39 self.doWashing = streamReadBool(streamId);
40 self:run(connection);
41end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
47function HPWPlaceableStateEvent:writeStream(streamId, connection)
48 writeNetworkNodeObject(streamId, self.object);
49 streamWriteBool(streamId, self.doWashing);
50end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
55function HPWPlaceableStateEvent:run(connection)
56 if not connection:getIsServer() then
57 g_server:broadcastEvent(self, false, connection, self.object);
58 end;
59 self.object:setIsWashing(self.doWashing, false, true);
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean doWashing, boolean noEventSend)
Arguments
tableobjectobject
booleandoWashingdo washing
booleannoEventSendno event send
Code
67function HPWPlaceableStateEvent.sendEvent(object, doWashing, noEventSend)
68 if doWashing ~= object.doWashing then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(HPWPlaceableStateEvent:new(object, doWashing), nil, nil, object);
72 else
73 g_client:getServerConnection():sendEvent(HPWPlaceableStateEvent:new(object, doWashing));
74 end;
75 end;
76 end;
77end;

HPWPlaceableTurnOnEvent

Description
Event for hpw turn on state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function HPWPlaceableTurnOnEvent:emptyNew()
16 local self = Event:new(HPWPlaceableTurnOnEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isTurnedOn, table player)
Arguments
tableobjectobject
booleanisTurnedOnis turned on
tableplayerplayer
Return Values
tableinstanceinstance of event
Code
26function HPWPlaceableTurnOnEvent:new(object, isTurnedOn, player)
27 local self = HPWPlaceableTurnOnEvent:emptyNew()
28 self.object = object;
29 self.isTurnedOn = isTurnedOn;
30 self.player = player;
31
32 return self;
33end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
39function HPWPlaceableTurnOnEvent:readStream(streamId, connection)
40 self.object = readNetworkNodeObject(streamId);
41 self.isTurnedOn = streamReadBool(streamId);
42 if self.isTurnedOn then
43 self.player = readNetworkNodeObject(streamId);
44 end;
45 self:run(connection);
46end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
52function HPWPlaceableTurnOnEvent:writeStream(streamId, connection)
53 writeNetworkNodeObject(streamId, self.object);
54 streamWriteBool(streamId, self.isTurnedOn);
55 if self.isTurnedOn then
56 writeNetworkNodeObject(streamId, self.player);
57 end;
58end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
63function HPWPlaceableTurnOnEvent:run(connection)
64 if not connection:getIsServer() then
65 g_server:broadcastEvent(self, false, connection, self.object);
66 end;
67 self.object:setIsTurnedOn(self.isTurnedOn, self.player, true);
68end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean isTurnedOn, table player, boolean noEventSend)
Arguments
tableobjectobject
booleanisTurnedOnis turned on
tableplayerplayer
booleannoEventSendno event send
Code
76function HPWPlaceableTurnOnEvent.sendEvent(object, isTurnedOn, player, noEventSend)
77 if isTurnedOn ~= object.isTurnedOn then
78 if noEventSend == nil or noEventSend == false then
79 if g_server ~= nil then
80 g_server:broadcastEvent(HPWPlaceableTurnOnEvent:new(object, isTurnedOn, player), nil, nil, object);
81 else
82 g_client:getServerConnection():sendEvent(HPWPlaceableTurnOnEvent:new(object, isTurnedOn, player));
83 end;
84 end;
85 end;
86end;

MixerWagonBaleNotAcceptedEvent

Description
Event for honking

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function MixerWagonBaleNotAcceptedEvent:emptyNew()
16 local self = Event:new(MixerWagonBaleNotAcceptedEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object)
Arguments
tableobjectobject
Code
23function MixerWagonBaleNotAcceptedEvent:new(object)
24 local self = MixerWagonBaleNotAcceptedEvent:emptyNew()
25 self.object = object;
26 self.isPlaying = isPlaying;
27 return self;
28end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
34function MixerWagonBaleNotAcceptedEvent:readStream(streamId, connection)
35 self.object = readNetworkNodeObject(streamId);
36 --self:run(connection);
37 g_currentMission:addIngameNotification(FSBaseMission.INGAME_NOTIFICATION_CRITICAL, g_i18n:getText("warning_baleNotSupported"));
38end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
44function MixerWagonBaleNotAcceptedEvent:writeStream(streamId, connection)
45 writeNetworkNodeObject(streamId, self.object);
46end;

MowerToggleWindrowDropEvent

Description
Event for mower toggle drop

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function MowerToggleWindrowDropEvent:emptyNew()
16 local self = Event:new(MowerToggleWindrowDropEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean useMowerWindrowDropAreas)
Arguments
tableobjectobject
booleanuseMowerWindrowDropAreasuse mower windrow drop areas
Code
24function MowerToggleWindrowDropEvent:new(object, useMowerWindrowDropAreas)
25 local self = MowerToggleWindrowDropEvent:emptyNew()
26 self.object = object;
27 self.useMowerWindrowDropAreas = useMowerWindrowDropAreas;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function MowerToggleWindrowDropEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.useMowerWindrowDropAreas = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function MowerToggleWindrowDropEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.useMowerWindrowDropAreas);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function MowerToggleWindrowDropEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 if self.object ~= nil then
58 self.object:setUseMowerWindrowDropAreas(self.useMowerWindrowDropAreas, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean useMowerWindrowDropAreas, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanuseMowerWindrowDropAreasuse mower windrow drop areas
booleannoEventSendno event send
Code
67function MowerToggleWindrowDropEvent.sendEvent(vehicle, useMowerWindrowDropAreas, noEventSend)
68 if useMowerWindrowDropAreas ~= vehicle.useMowerWindrowDropAreas then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(MowerToggleWindrowDropEvent:new(vehicle, useMowerWindrowDropAreas), nil, nil, vehicle);
72 else
73 g_client:getServerConnection():sendEvent(MowerToggleWindrowDropEvent:new(vehicle, useMowerWindrowDropAreas));
74 end;
75 end;
76 end;
77end;

OverloadingToggleUnloadEvent

Description
Event for toggle overloading

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function OverloadingToggleUnloadEvent:emptyNew()
16 local self = Event:new(OverloadingToggleUnloadEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isActive)
Arguments
tableobjectobject
booleanisActiveis active
Code
24function OverloadingToggleUnloadEvent:new(vehicle, isActive)
25 local self = OverloadingToggleUnloadEvent:emptyNew()
26 self.vehicle = vehicle;
27 self.isActive = isActive;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function OverloadingToggleUnloadEvent:readStream(streamId, connection)
36 self.vehicle = readNetworkNodeObject(streamId);
37 self.isActive = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function OverloadingToggleUnloadEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.vehicle);
47 streamWriteBool(streamId, self.isActive);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function OverloadingToggleUnloadEvent:run(connection)
54 self.vehicle:setOverloadingActive(self.isActive, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(OverloadingToggleUnloadEvent:new(self.vehicle, self.isActive), nil, connection, self.vehicle);
57 end;
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isActive, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisActiveis active
booleannoEventSendno event send
Code
65function OverloadingToggleUnloadEvent.sendEvent(vehicle, isActive, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(OverloadingToggleUnloadEvent:new(vehicle, isActive), nil, nil, vehicle);
69 else
70 g_client:getServerConnection():sendEvent(OverloadingToggleUnloadEvent:new(vehicle, isActive));
71 end;
72 end;
73end;

PickupSetStateEvent

Description
Event for lower and lift pickup

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function PickupSetStateEvent:emptyNew()
16 local self = Event:new(PickupSetStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isPickupLowered)
Arguments
tableobjectobject
booleanisPickupLoweredis pickup lowered
Code
24function PickupSetStateEvent:new(object, isPickupLowered)
25 local self = PickupSetStateEvent:emptyNew()
26 self.object = object;
27 self.isPickupLowered = isPickupLowered;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function PickupSetStateEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.isPickupLowered = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function PickupSetStateEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isPickupLowered);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function PickupSetStateEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 if self.object ~= nil then
58 self.object:setPickupState(self.isPickupLowered, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isPickupLowered, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisPickupLoweredis pickup lowered
booleannoEventSendno event send
Code
67function PickupSetStateEvent.sendEvent(vehicle, isPickupLowered, noEventSend)
68 if isPickupLowered ~= vehicle.isPickupLowered then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(PickupSetStateEvent:new(vehicle, isPickupLowered), nil, nil, vehicle);
72 else
73 g_client:getServerConnection():sendEvent(PickupSetStateEvent:new(vehicle, isPickupLowered));
74 end;
75 end;
76 end;
77end;

PlantLimitToFieldEvent

Description
Event for limit to field state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function PlantLimitToFieldEvent:emptyNew()
16 local self = Event:new(PlantLimitToFieldEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean plantLimitToField)
Arguments
tableobjectobject
booleanplantLimitToFieldplant is limited to field
Code
24function PlantLimitToFieldEvent:new(object, plantLimitToField)
25 local self = PlantLimitToFieldEvent:emptyNew()
26 self.object = object;
27 self.plantLimitToField = plantLimitToField;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function PlantLimitToFieldEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.plantLimitToField = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function PlantLimitToFieldEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.plantLimitToField);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function PlantLimitToFieldEvent:run(connection)
54 self.object:setPlantLimitToField(self.plantLimitToField, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(PlantLimitToFieldEvent:new(self.object, self.plantLimitToField), nil, connection, self.object);
57 end;
58end;

PloughLimitToFieldEvent

Description
Event for limit to field state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function PloughLimitToFieldEvent:emptyNew()
16 local self = Event:new(PloughLimitToFieldEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean ploughLimitToField)
Arguments
tableobjectobject
booleanploughLimitToFieldplough is limited to field
Code
24function PloughLimitToFieldEvent:new(object, ploughLimitToField)
25 local self = PloughLimitToFieldEvent:emptyNew()
26 self.object = object;
27 self.ploughLimitToField = ploughLimitToField;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function PloughLimitToFieldEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.ploughLimitToField = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function PloughLimitToFieldEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.ploughLimitToField);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function PloughLimitToFieldEvent:run(connection)
54 self.object:setPloughLimitToField(self.ploughLimitToField, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(PloughLimitToFieldEvent:new(self.object, self.ploughLimitToField), nil, connection, self.object);
57 end;
58end;

PloughRotationEvent

Description
Event for plough rotation

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function PloughRotationEvent:emptyNew()
16 local self = Event:new(PloughRotationEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean rotationMax)
Arguments
tableobjectobject
booleanrotationMaxrotation max
Code
24function PloughRotationEvent:new(object, rotationMax)
25 local self = PloughRotationEvent:emptyNew()
26 self.object = object;
27 self.rotationMax = rotationMax;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function PloughRotationEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.rotationMax = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function PloughRotationEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.rotationMax);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function PloughRotationEvent:run(connection)
54 self.object:setRotationMax(self.rotationMax, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(PloughRotationEvent:new(self.object, self.rotationMax), nil, connection, self.object);
57 end;
58end;

ReceivingHopperSetCreateBoxesEvent

Description
Event for toggle box creation

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function ReceivingHopperSetCreateBoxesEvent:emptyNew()
16 local self = Event:new(ReceivingHopperSetCreateBoxesEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean state)
Arguments
tableobjectobject
booleanstatestate
Code
24function ReceivingHopperSetCreateBoxesEvent:new(object, state)
25 local self = ReceivingHopperSetCreateBoxesEvent:emptyNew()
26 self.object = object;
27 self.state = state;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function ReceivingHopperSetCreateBoxesEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.state = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function ReceivingHopperSetCreateBoxesEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.state);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function ReceivingHopperSetCreateBoxesEvent:run(connection)
54 self.object:setCreateBoxes(self.state, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(ReceivingHopperSetCreateBoxesEvent:new(self.object, self.state), nil, connection, self.object);
57 end;
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean state, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanstatestate
booleannoEventSendno event send
Code
65function ReceivingHopperSetCreateBoxesEvent.sendEvent(vehicle, state, noEventSend)
66 if state ~= vehicle.state then
67 if noEventSend == nil or noEventSend == false then
68 if g_server ~= nil then
69 g_server:broadcastEvent(ReceivingHopperSetCreateBoxesEvent:new(vehicle, state), nil, nil, vehicle);
70 else
71 g_client:getServerConnection():sendEvent(ReceivingHopperSetCreateBoxesEvent:new(vehicle, state));
72 end;
73 end;
74 end;
75end;

ReverseDrivingSetStateEvent

Description
Event for reverse driving state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function ReverseDrivingSetStateEvent:emptyNew()
16 local self = Event:new(ReverseDrivingSetStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle, boolean isReverseDriving)
Arguments
tablevehiclevehicle
booleanisReverseDrivingis reverse driving
Code
24function ReverseDrivingSetStateEvent:new(vehicle, isReverseDriving)
25 local self = ReverseDrivingSetStateEvent:emptyNew()
26 self.vehicle = vehicle;
27 self.isReverseDriving = isReverseDriving;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function ReverseDrivingSetStateEvent:readStream(streamId, connection)
36 self.vehicle = readNetworkNodeObject(streamId);
37 self.isReverseDriving = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function ReverseDrivingSetStateEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.vehicle);
47 streamWriteBool(streamId, self.isReverseDriving);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function ReverseDrivingSetStateEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.vehicle);
56 end;
57 if self.vehicle ~= nil then
58 self.vehicle:setIsReverseDriving(self.isReverseDriving, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isReverseDriving, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisReverseDrivingis reverse driving
booleannoEventSendno event send
Code
67function ReverseDrivingSetStateEvent.sendEvent(vehicle, isReverseDriving, noEventSend)
68 if isReverseDriving ~= vehicle.isReverseDriving then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(ReverseDrivingSetStateEvent:new(vehicle, isReverseDriving), nil, nil, vehicle);
72 else
73 g_client:getServerConnection():sendEvent(ReverseDrivingSetStateEvent:new(vehicle, isReverseDriving));
74 end;
75 end;
76 end;
77end;

RidgeMarkerSetStateEvent

Description
Event for ridge marker state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function RidgeMarkerSetStateEvent:emptyNew()
16 local self = Event:new(RidgeMarkerSetStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean state)
Arguments
tableobjectobject
booleanstatestate
Code
24function RidgeMarkerSetStateEvent:new(object, state)
25 local self = RidgeMarkerSetStateEvent:emptyNew()
26 self.object = object;
27 self.state = state;
28 assert(state >= 0 and state < RidgeMarker.numMaxStates);
29 return self;
30end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function RidgeMarkerSetStateEvent:readStream(streamId, connection)
37 self.object = readNetworkNodeObject(streamId);
38 self.state = streamReadUIntN(streamId, RidgeMarker.sendNumBits);
39 self:run(connection);
40end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
46function RidgeMarkerSetStateEvent:writeStream(streamId, connection)
47 writeNetworkNodeObject(streamId, self.object);
48 streamWriteUIntN(streamId, self.state, RidgeMarker.sendNumBits);
49end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
54function RidgeMarkerSetStateEvent:run(connection)
55 self.object:setRidgeMarkerState(self.state, true);
56 if not connection:getIsServer() then
57 g_server:broadcastEvent(RidgeMarkerSetStateEvent:new(self.object, self.state), nil, connection, self.object);
58 end;
59end;

SetCoverStateEvent

Description
Event for cover state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetCoverStateEvent:emptyNew()
16 local self = Event:new(SetCoverStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isOpen)
Arguments
tableobjectobject
booleanisOpencover is open
Code
24function SetCoverStateEvent:new(object, isOpen)
25 local self = SetCoverStateEvent:emptyNew()
26 self.object = object;
27 self.isOpen = isOpen;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetCoverStateEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.isOpen = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetCoverStateEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isOpen);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetCoverStateEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 if self.object ~= nil then
58 self.object:setCoverState(self.isOpen, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isOpen, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisOpencover is open
booleannoEventSendno event send
Code
67function SetCoverStateEvent.sendEvent(vehicle, isOpen, noEventSend)
68 if vehicle.isCoverOpen ~= isOpen then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(SetCoverStateEvent:new(vehicle, isOpen), nil, nil, vehicle);
72 else
73 g_client:getServerConnection():sendEvent(SetCoverStateEvent:new(vehicle, isOpen));
74 end;
75 end;
76 end;
77end;

SetCrabSteeringEvent

Description
Event for steering mode

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetCrabSteeringEvent:emptyNew()
16 local self = Event:new(SetCrabSteeringEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer state)
Arguments
tableobjectobject
integerstatestate
Code
24function SetCrabSteeringEvent:new(vehicle, state)
25 local self = SetCrabSteeringEvent:emptyNew()
26 self.vehicle = vehicle;
27 self.state = state;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetCrabSteeringEvent:readStream(streamId, connection)
36 self.vehicle = readNetworkNodeObject(streamId);
37 self.state = streamReadUIntN(streamId, CrabSteering.STEERING_SEND_NUM_BITS);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetCrabSteeringEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.vehicle);
47 streamWriteUIntN(streamId, self.state, CrabSteering.STEERING_SEND_NUM_BITS);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetCrabSteeringEvent:run(connection)
54 self.vehicle:setCrabSteering(self.state, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(SetCrabSteeringEvent:new(self.vehicle, self.state), nil, connection, self.object);
57 end;
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, integer state, boolean noEventSend)
Arguments
tablevehiclevehicle
integerstatestate
booleannoEventSendno event send
Code
65function SetCrabSteeringEvent.sendEvent(vehicle, state, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(SetCrabSteeringEvent:new(vehicle, state), nil, nil, vehicle);
69 else
70 g_client:getServerConnection():sendEvent(SetCrabSteeringEvent:new(vehicle, state));
71 end;
72 end;
73end;

SetCruiseControlSpeedEvent

Description
Event for cruise control speed

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetCruiseControlSpeedEvent:emptyNew()
16 local self = Event:new(SetCruiseControlSpeedEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle, float speed)
Arguments
tablevehiclevehicle
floatspeedspeed
Code
24function SetCruiseControlSpeedEvent:new(vehicle, speed)
25 local self = SetCruiseControlSpeedEvent:emptyNew()
26 self.speed = speed;
27 self.vehicle = vehicle;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetCruiseControlSpeedEvent:readStream(streamId, connection)
36 self.vehicle = readNetworkNodeObject(streamId);
37 self.speed = streamReadUInt8(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetCruiseControlSpeedEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.vehicle);
47 streamWriteUInt8(streamId, self.speed);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetCruiseControlSpeedEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.vehicle);
56 end;
57 self.vehicle:setCruiseControlMaxSpeed(self.speed);
58end;

SetCruiseControlStateEvent

Description
Event for cruise control state event

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetCruiseControlStateEvent:emptyNew()
16 local self = Event:new(SetCruiseControlStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle, integer state)
Arguments
tablevehiclevehicle
integerstatestate
Code
24function SetCruiseControlStateEvent:new(vehicle, state)
25 local self = SetCruiseControlStateEvent:emptyNew()
26 self.state = state;
27 self.vehicle = vehicle;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetCruiseControlStateEvent:readStream(streamId, connection)
36 self.vehicle = readNetworkNodeObject(streamId);
37 self.state = streamReadUIntN(streamId, 2);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetCruiseControlStateEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.vehicle);
47 streamWriteUIntN(streamId, self.state, 2);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetCruiseControlStateEvent:run(connection)
54 self.vehicle:setCruiseControlState(self.state, true);
55end;

SetDischargeToGroundEvent

Description
Event for discharge to ground state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetDischargeToGroundEvent:emptyNew()
16 local self = Event:new(SetDischargeToGroundEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean dischargeToGround)
Arguments
tableobjectobject
booleandischargeToGrounddischarge to ground
Code
24function SetDischargeToGroundEvent:new(object, dischargeToGround)
25 local self = SetDischargeToGroundEvent:emptyNew()
26 self.object = object;
27 self.dischargeToGround = dischargeToGround;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetDischargeToGroundEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.dischargeToGround = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetDischargeToGroundEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.dischargeToGround);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetDischargeToGroundEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 if self.object ~= nil then
58 self.object:setDischargeToGround(self.dischargeToGround, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean dischargeToGround, boolean noEventSend)
Arguments
tablevehiclevehicle
booleandischargeToGrounddischarge to ground
booleannoEventSendno event send
Code
67function SetDischargeToGroundEvent.sendEvent(vehicle, dischargeToGround, noEventSend)
68 if vehicle.dischargeToGround ~= dischargeToGround then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(SetDischargeToGroundEvent:new(vehicle, dischargeToGround), nil, nil, vehicle);
72 else
73 g_client:getServerConnection():sendEvent(SetDischargeToGroundEvent:new(vehicle, dischargeToGround));
74 end;
75 end;
76 end;
77end;

SetIsFillingEvent

Description
Event for set is filling state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetIsFillingEvent:emptyNew()
16 local self = Event:new(SetIsFillingEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isFilling)
Arguments
tableobjectobject
booleanisFillingis filling
Code
24function SetIsFillingEvent:new(object, isFilling)
25 local self = SetIsFillingEvent:emptyNew()
26 self.object = object;
27 self.isFilling = isFilling;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetIsFillingEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.isFilling = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetIsFillingEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isFilling);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetIsFillingEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 self.object:setIsFilling(self.isFilling, true);
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean isFilling, boolean noEventSend)
Arguments
tableobjectobject
booleanisFillingis filling
booleannoEventSendno event send
Code
65function SetIsFillingEvent.sendEvent(object, isFilling, noEventSend)
66 if isFilling ~= object.isFilling then
67 if noEventSend == nil or noEventSend == false then
68 if g_server ~= nil then
69 g_server:broadcastEvent(SetIsFillingEvent:new(object, isFilling), nil, nil, object);
70 else
71 g_client:getServerConnection():sendEvent(SetIsFillingEvent:new(object, isFilling));
72 end;
73 end;
74 end;
75end;

SetMotorTurnedOnEvent

Description
Event for motor turned on state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetMotorTurnedOnEvent:emptyNew()
16 local self = Event:new(SetMotorTurnedOnEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean turnedOn)
Arguments
tableobjectobject
booleanturnedOnis turned on
Code
24function SetMotorTurnedOnEvent:new(object, turnedOn)
25 local self = SetMotorTurnedOnEvent:emptyNew()
26 self.object = object;
27 self.turnedOn = turnedOn;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetMotorTurnedOnEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.turnedOn = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetMotorTurnedOnEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.turnedOn);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetMotorTurnedOnEvent:run(connection)
54 if self.turnedOn then
55 self.object:startMotor(true);
56 else
57 self.object:stopMotor(true);
58 end;
59 if not connection:getIsServer() then
60 g_server:broadcastEvent(SetMotorTurnedOnEvent:new(self.object, self.turnedOn), nil, connection, self.object);
61 end;
62end;

SetPipeStateEvent

Description
Event for pipe state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetPipeStateEvent:emptyNew()
16 local self = Event:new(SetPipeStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer pipeState)
Arguments
tableobjectobject
integerpipeStatepipe state
Code
24function SetPipeStateEvent:new(object, pipeState)
25 local self = SetPipeStateEvent:emptyNew()
26 self.object = object;
27 self.pipeState = pipeState;
28 assert(self.pipeState >= 0 and self.pipeState < 8);
29 return self;
30end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function SetPipeStateEvent:readStream(streamId, connection)
37 self.object = readNetworkNodeObject(streamId);
38 self.pipeState = streamReadUIntN(streamId, 3);
39 self:run(connection);
40end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
46function SetPipeStateEvent:writeStream(streamId, connection)
47 writeNetworkNodeObject(streamId, self.object);
48 streamWriteUIntN(streamId, self.pipeState, 3);
49end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
54function SetPipeStateEvent:run(connection)
55 self.object:setPipeState(self.pipeState, true);
56 if not connection:getIsServer() then
57 g_server:broadcastEvent(SetPipeStateEvent:new(self.object, self.pipeState), nil, connection, self.object);
58 end;
59end;

SetTurnedOnEvent

Description
Event for turned on state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetTurnedOnEvent:emptyNew()
16 local self = Event:new(SetTurnedOnEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isTurnedOn)
Arguments
tableobjectobject
booleanisTurnedOnis turned on state
Code
24function SetTurnedOnEvent:new(object, isTurnedOn)
25 local self = SetTurnedOnEvent:emptyNew()
26 self.object = object;
27 self.isTurnedOn = isTurnedOn;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetTurnedOnEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.isTurnedOn = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetTurnedOnEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isTurnedOn);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetTurnedOnEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 if self.object ~= nil then
58 self.object:setIsTurnedOn(self.isTurnedOn, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean isTurnedOn, boolean noEventSend)
Arguments
tableobjectobject
booleanisTurnedOnis turned on state
booleannoEventSendno event send
Code
67function SetTurnedOnEvent.sendEvent(vehicle, isTurnedOn, noEventSend)
68 if isTurnedOn ~= vehicle.turnOnVehicle.isTurnedOn then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(SetTurnedOnEvent:new(vehicle, isTurnedOn), nil, nil, vehicle);
72 else
73 g_client:getServerConnection():sendEvent(SetTurnedOnEvent:new(vehicle, isTurnedOn));
74 end;
75 end;
76 end;
77end;

SowingMachineSetSeedIndex

Description
Set seed index event

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SowingMachineSetSeedIndex:emptyNew()
16 local self = Event:new(SowingMachineSetSeedIndex_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer seedIndex)
Arguments
tableobjectobject
integerseedIndexindex of seed
Code
24function SowingMachineSetSeedIndex:new(object, seedIndex)
25 local self = SowingMachineSetSeedIndex:emptyNew()
26 self.object = object;
27 self.seedIndex = seedIndex;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SowingMachineSetSeedIndex:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.seedIndex = streamReadUInt8(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SowingMachineSetSeedIndex:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteUInt8(streamId, self.seedIndex);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SowingMachineSetSeedIndex:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 self.object:setSeedIndex(self.seedIndex, true);
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, integer seedIndex, boolean noEventSend)
Arguments
tableobjectobject
integerseedIndexindex of seed
booleannoEventSendno event send
Code
65function SowingMachineSetSeedIndex.sendEvent(object, seedIndex, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(SowingMachineSetSeedIndex:new(object, seedIndex), nil, nil, object);
69 else
70 g_client:getServerConnection():sendEvent(SowingMachineSetSeedIndex:new(object, seedIndex));
71 end;
72 end;
73end;

SteerableToggleRefuelEvent

Description
Event for toggle refueling

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SteerableToggleRefuelEvent:emptyNew()
16 local self = Event:new(SteerableToggleRefuelEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isRefueling)
Arguments
tableobjectobject
booleanisRefuelingis refueling state
Code
24function SteerableToggleRefuelEvent:new(object, isRefueling)
25 local self = SteerableToggleRefuelEvent:emptyNew()
26 self.object = object;
27 self.isRefueling = isRefueling;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SteerableToggleRefuelEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.isRefueling = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SteerableToggleRefuelEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isRefueling);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SteerableToggleRefuelEvent:run(connection)
54 self.object:setIsFuelFilling(self.isRefueling, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(SteerableToggleRefuelEvent:new(self.object, self.isRefueling), nil, connection, self.object);
57 end;
58end;

StrawBlowerDoorOpenEvent

Description
Event for straw blower door state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function StrawBlowerDoorOpenEvent:emptyNew()
16 local self = Event:new(StrawBlowerDoorOpenEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isStrawBlowerDoorOpen)
Arguments
tableobjectobject
booleanisStrawBlowerDoorOpenstraw blower door state
Code
24function StrawBlowerDoorOpenEvent:new(object, isStrawBlowerDoorOpen)
25 local self = StrawBlowerDoorOpenEvent:emptyNew()
26 self.object = object;
27 self.isStrawBlowerDoorOpen = isStrawBlowerDoorOpen;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function StrawBlowerDoorOpenEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.isStrawBlowerDoorOpen = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function StrawBlowerDoorOpenEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isStrawBlowerDoorOpen);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function StrawBlowerDoorOpenEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 if self.object ~= nil then
58 self.object:setIsStrawBlowerDoorOpen(self.isStrawBlowerDoorOpen, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isStrawBlowerDoorOpen, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisStrawBlowerDoorOpenstraw blower door state
booleannoEventSendno event send
Code
67function StrawBlowerDoorOpenEvent.sendEvent(vehicle, isStrawBlowerDoorOpen, noEventSend)
68 if isStrawBlowerDoorOpen ~= vehicle.isStrawBlowerDoorOpen then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(StrawBlowerDoorOpenEvent:new(vehicle, isStrawBlowerDoorOpen), nil, nil, vehicle);
72 else
73 g_client:getServerConnection():sendEvent(StrawBlowerDoorOpenEvent:new(vehicle, isStrawBlowerDoorOpen));
74 end;
75 end;
76 end;
77end;

TensionBeltsEvent

Description
Event for tension belts state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function TensionBeltsEvent:emptyNew()
16 local self = Event:new(TensionBeltsEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, boolean isActive, integer beltId)
Arguments
tableobjectobject
booleanisActivebelt is active
integerbeltIdid of belt
Code
25function TensionBeltsEvent:new(object, isActive, beltId)
26 local self = TensionBeltsEvent:emptyNew()
27 self.object = object
28 self.isActive = isActive
29 self.beltId = beltId
30 return self
31end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
37function TensionBeltsEvent:readStream(streamId, connection)
38 self.object = readNetworkNodeObject(streamId);
39 if not streamReadBool(streamId) then
40 self.beltId = streamReadUIntN(streamId, TensionBelts.NUM_SEND_BITS)+1
41 end
42 self.isActive = streamReadBool(streamId)
43 self:run(connection)
44end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
50function TensionBeltsEvent:writeStream(streamId, connection)
51 writeNetworkNodeObject(streamId, self.object)
52 streamWriteBool(streamId, self.beltId == nil)
53 if self.beltId ~= nil then
54 streamWriteUIntN(streamId, self.beltId-1, TensionBelts.NUM_SEND_BITS)
55 end
56 streamWriteBool(streamId, self.isActive)
57end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
62function TensionBeltsEvent:run(connection)
63 if not connection:getIsServer() then
64 g_server:broadcastEvent(self, false, connection, self.object)
65 end
66 self.object:setTensionBeltsActive(self.isActive, self.beltId, true)
67end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isActive, integer beltId, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisActivebelt is active
integerbeltIdid of belt
booleannoEventSendno event send
Code
75function TensionBeltsEvent.sendEvent(vehicle, isActive, beltId, noEventSend)
76 if noEventSend == nil or noEventSend == false then
77 if g_server ~= nil then
78 g_server:broadcastEvent(TensionBeltsEvent:new(vehicle, isActive, beltId), nil, nil, vehicle)
79 else
80 g_client:getServerConnection():sendEvent(TensionBeltsEvent:new(vehicle, isActive, beltId))
81 end
82 end
83end

TensionBeltsRefreshEvent

Description
Event for tension belts state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function TensionBeltsRefreshEvent:emptyNew()
16 local self = Event:new(TensionBeltsRefreshEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, boolean isActive, integer beltId)
Arguments
tableobjectobject
booleanisActivebelt is active
integerbeltIdid of belt
Code
25function TensionBeltsRefreshEvent:new(object)
26 local self = TensionBeltsRefreshEvent:emptyNew()
27 self.object = object
28 return self
29end

readStream

Description
Called on client side
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function TensionBeltsRefreshEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self:run(connection)
38end

writeStream

Description
Called on server side
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
44function TensionBeltsRefreshEvent:writeStream(streamId, connection)
45 writeNetworkNodeObject(streamId, self.object)
46end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
51function TensionBeltsRefreshEvent:run(connection)
52 if not connection:getIsServer() then
53 g_server:broadcastEvent(self, false, connection, self.object)
54 end
55 self.object:refreshTensionBelts()
56end

TrailerToggleTipEvent

Description
Event for toggle trailer tipping

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function TrailerToggleTipEvent:emptyNew()
16 local self = Event:new(TrailerToggleTipEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isStart, table tipTrigger, integer tipReferencePointIndex)
Arguments
tableobjectobject
booleanisStartis start
tabletipTriggertip trigger
integertipReferencePointIndexindex of tip reference point
Code
26function TrailerToggleTipEvent:new(object, isStart, tipTrigger, tipReferencePointIndex)
27 local self = TrailerToggleTipEvent:emptyNew()
28 self.isStart = isStart;
29 self.tipTrigger = tipTrigger;
30 self.tipReferencePointIndex = Utils.getNoNil(tipReferencePointIndex, 1);
31 assert(self.tipReferencePointIndex <= 15);
32 self.object = object;
33 return self;
34end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
40function TrailerToggleTipEvent:readStream(streamId, connection)
41 self.object = readNetworkNodeObject(streamId);
42 self.isStart = streamReadBool(streamId);
43 if self.isStart then
44 self.tipTrigger = readNetworkNodeObject(streamId);
45 self.tipReferencePointIndex = streamReadUIntN(streamId, 4);
46 end;
47 self:run(connection);
48end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
54function TrailerToggleTipEvent:writeStream(streamId, connection)
55 writeNetworkNodeObject(streamId, self.object);
56 streamWriteBool(streamId, self.isStart);
57 if self.isStart then
58 writeNetworkNodeObject(streamId, self.tipTrigger);
59 streamWriteUIntN(streamId, self.tipReferencePointIndex, 4);
60 end;
61end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
66function TrailerToggleTipEvent:run(connection)
67 if not connection:getIsServer() then
68 g_server:broadcastEvent(self, false, connection, self.object);
69 end;
70
71 if self.isStart then
72 self.object:onStartTip(self.tipTrigger, self.tipReferencePointIndex, true);
73 else
74 self.object:onEndTip(true);
75 end;
76end;

TreePlanterLoadPalletEvent

Description
Event for loading of pallet on tree planter

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function TreePlanterLoadPalletEvent:emptyNew()
16 local self = Event:new(TreePlanterLoadPalletEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer palletObjectId)
Arguments
tableobjectobject
integerpalletObjectIdobject id of pallet
Code
24function TreePlanterLoadPalletEvent:new(object, palletObjectId)
25 local self = TreePlanterLoadPalletEvent:emptyNew()
26 self.object = object;
27 self.palletObjectId = palletObjectId;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function TreePlanterLoadPalletEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.palletObjectId = readNetworkNodeObjectId(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function TreePlanterLoadPalletEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 writeNetworkNodeObjectId(streamId, self.palletObjectId);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function TreePlanterLoadPalletEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 self.object:loadPallet(self.palletObjectId, true);
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, integer palletObjectId, boolean noEventSend)
Arguments
tableobjectobject
integerpalletObjectIdobject id of pallet
booleannoEventSendno event send
Code
65function TreePlanterLoadPalletEvent.sendEvent(object, palletObjectId, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(TreePlanterLoadPalletEvent:new(object, palletObjectId), nil, nil, object);
69 else
70 g_client:getServerConnection():sendEvent(TreePlanterLoadPalletEvent:new(object, palletObjectId));
71 end;
72 end;
73end;

VehicleAttachEvent

Description
Event for attaching

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleAttachEvent:emptyNew()
15 local self = Event:new(VehicleAttachEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table vehicle, table implement, integer inputJointIndex, integer jointIndex, boolean startLowered)
Arguments
tablevehiclevehicle
tableimplementimplement
integerinputJointIndexindex of input attacher joint
integerjointIndexindex of attacher joint
booleanstartLoweredstart in lowered state
Return Values
tableinstanceinstance of event
Code
27function VehicleAttachEvent:new(vehicle, implement, inputJointIndex, jointIndex, startLowered)
28 local self = VehicleAttachEvent:emptyNew()
29 self.jointIndex = jointIndex;
30 self.inputJointIndex = inputJointIndex;
31 self.vehicle = vehicle;
32 self.implement = implement;
33 self.startLowered = startLowered;
34 assert(self.jointIndex >= 0 and self.jointIndex < 127)
35 return self;
36end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function VehicleAttachEvent:readStream(streamId, connection)
43 self.vehicle = readNetworkNodeObject(streamId);
44 self.implement = readNetworkNodeObject(streamId);
45 self.jointIndex = streamReadUIntN(streamId, 7);
46 self.inputJointIndex = streamReadUIntN(streamId, 7);
47 self.startLowered = streamReadBool(streamId);
48 self:run(connection);
49end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
55function VehicleAttachEvent:writeStream(streamId, connection)
56 writeNetworkNodeObject(streamId, self.vehicle);
57 writeNetworkNodeObject(streamId, self.implement);
58 streamWriteUIntN(streamId, self.jointIndex, 7);
59 streamWriteUIntN(streamId, self.inputJointIndex, 7);
60 streamWriteBool(streamId, self.startLowered);
61end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
66function VehicleAttachEvent:run(connection)
67 self.vehicle:attachImplement(self.implement, self.inputJointIndex, self.jointIndex, true, nil, self.startLowered);
68 if not connection:getIsServer() then
69 g_server:broadcastEvent(self, nil, connection, self.object);
70 end;
71end;

VehicleBundleAttachEvent

Description
Event for bundle attaching

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleBundleAttachEvent:emptyNew()
15 local self = Event:new(VehicleBundleAttachEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table bundles)
Arguments
tablebundlesbundles
Return Values
tableinstanceinstance of event
Code
23function VehicleBundleAttachEvent:new(bundles)
24 local self = VehicleBundleAttachEvent:emptyNew()
25 self.bundles = bundles;
26 return self;
27end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
33function VehicleBundleAttachEvent:readStream(streamId, connection)
34 local numBundles = streamReadUInt8(streamId)
35 for i=1, numBundles do
36 local v1 = readNetworkNodeObjectId(streamId)
37 local v2 = readNetworkNodeObjectId(streamId)
38 local inputJointIndex = streamReadUIntN(streamId, 7);
39 local jointIndex = streamReadUIntN(streamId, 7);
40 table.insert(g_currentMission.vehiclesToAttach, {v1id=v1, v2id=v2, inputJointIndex=inputJointIndex, jointIndex=jointIndex})
41 end
42end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
48function VehicleBundleAttachEvent:writeStream(streamId, connection)
49 streamWriteUInt8(streamId, #self.bundles)
50 for i=1, #self.bundles do
51 local bundle = self.bundles[i]
52 writeNetworkNodeObjectId(streamId, networkGetObjectId(bundle.v1));
53 writeNetworkNodeObjectId(streamId, networkGetObjectId(bundle.v2));
54 streamWriteUIntN(streamId, bundle.input, 7);
55 streamWriteUIntN(streamId, bundle.attacher, 7);
56 end
57end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
62function VehicleBundleAttachEvent:run(connection)
63 self.vehicle:attachImplement(self.implement, self.inputJointIndex, self.jointIndex, true, nil, self.startLowered);
64 if not connection:getIsServer() then
65 g_server:broadcastEvent(self, nil, connection, self.object);
66 end;
67end;

VehicleDetachEvent

Description
Event for detaching

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleDetachEvent:emptyNew()
15 local self = Event:new(VehicleDetachEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table vehicle, table implement)
Arguments
tablevehiclevehicle
tableimplementimplement
Return Values
tableinstanceinstance of event
Code
24function VehicleDetachEvent:new(vehicle, implement)
25 local self = VehicleDetachEvent:emptyNew()
26 self.implement = implement;
27 self.vehicle = vehicle;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function VehicleDetachEvent:readStream(streamId, connection)
36 self.vehicle = readNetworkNodeObject(streamId);
37 self.implement = readNetworkNodeObject(streamId);
38 if connection:getIsServer() then
39 self.vehicle:detachImplementByObject(self.implement, true);
40 else
41 self.vehicle:detachImplementByObject(self.implement);
42 end;
43end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
49function VehicleDetachEvent:writeStream(streamId, connection)
50 writeNetworkNodeObject(streamId, self.vehicle);
51 writeNetworkNodeObject(streamId, self.implement);
52end;

VehicleEnterRequestEvent

Description
Event for enter request

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleEnterRequestEvent:emptyNew()
15 local self = Event:new(VehicleEnterRequestEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table object, string controllerName, integer playerIndex, integer playerColorIndex)
Arguments
tableobjectobject
stringcontrollerNamename of controller
integerplayerIndexindex of player
integerplayerColorIndexindex of player color
Return Values
tableinstanceinstance of event
Code
26function VehicleEnterRequestEvent:new(object, controllerName, playerIndex, playerColorIndex)
27 local self = VehicleEnterRequestEvent:emptyNew()
28 self.object = object;
29 self.objectId = networkGetObjectId(self.object);
30 self.controllerName = controllerName;
31 self.playerIndex = playerIndex
32 self.playerColorIndex = playerColorIndex
33 return self;
34end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
40function VehicleEnterRequestEvent:readStream(streamId, connection)
41 self.objectId = readNetworkNodeObjectId(streamId);
42 self.controllerName = streamReadString(streamId);
43 self.playerIndex = streamReadUIntN(streamId, PlayerUtil.sendNumBits)
44 self.playerColorIndex = streamReadUInt8(streamId)
45 self.object = networkGetObject(self.objectId);
46 self:run(connection)
47end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
53function VehicleEnterRequestEvent:writeStream(streamId, connection)
54 writeNetworkNodeObjectId(streamId, self.objectId);
55 streamWriteString(streamId, self.controllerName);
56 streamWriteUIntN(streamId, self.playerIndex, PlayerUtil.sendNumBits)
57 streamWriteUInt8(streamId, self.playerColorIndex)
58end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
63function VehicleEnterRequestEvent:run(connection)
64 if self.object.isControlled == false then
65 self.object:setOwner(connection);
66 g_server:broadcastEvent(VehicleEnterResponseEvent:new(self.objectId, false, self.controllerName, self.playerIndex, self.playerColorIndex), true, connection, self.object);
67 connection:sendEvent(VehicleEnterResponseEvent:new(self.objectId, true, self.controllerName, self.playerIndex, self.playerColorIndex));
68 end;
69end;

VehicleEnterResponseEvent

Description
Event for enter response

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleEnterResponseEvent:emptyNew()
15 local self = Event:new(VehicleEnterResponseEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table id, boolean isOwner, string controllerName, integer playerIndex, integer playerColorIndex)
Arguments
tableidid
booleanisOwneris owner
stringcontrollerNamename of controller
integerplayerIndexindex of player
integerplayerColorIndexindex of player color
Return Values
tableinstanceinstance of event
Code
27function VehicleEnterResponseEvent:new(id, isOwner, controllerName, playerIndex, playerColorIndex)
28 local self = VehicleEnterResponseEvent:emptyNew()
29 self.id = id;
30 self.isOwner = isOwner;
31 self.controllerName = controllerName;
32 self.playerIndex = playerIndex
33 self.playerColorIndex = playerColorIndex
34 return self;
35end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
41function VehicleEnterResponseEvent:readStream(streamId, connection)
42 self.id = readNetworkNodeObjectId(streamId);
43 self.isOwner = streamReadBool(streamId);
44 self.playerIndex = streamReadUIntN(streamId, PlayerUtil.sendNumBits)
45 self.playerColorIndex = streamReadUInt8(streamId)
46 if not self.isOwner then
47 self.controllerName = streamReadString(streamId);
48 end;
49 self:run(connection);
50end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
56function VehicleEnterResponseEvent:writeStream(streamId, connection)
57 writeNetworkNodeObjectId(streamId, self.id);
58 streamWriteBool(streamId, self.isOwner);
59 streamWriteUIntN(streamId, self.playerIndex, PlayerUtil.sendNumBits)
60 streamWriteUInt8(streamId, self.playerColorIndex)
61 if not self.isOwner then
62 streamWriteString(streamId, self.controllerName);
63 end;
64end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
69function VehicleEnterResponseEvent:run(connection)
70 local object = networkGetObject(self.id);
71 if self.isOwner then
72 g_currentMission:onEnterVehicle(object, self.playerIndex, self.playerColorIndex);
73 else
74 object.controllerName = self.controllerName;
75 if not object.isEntered then
76 object:enterVehicle(false, self.playerIndex, self.playerColorIndex);
77 end;
78 end;
79end;

VehicleLeaveEvent

Description
Event for leaving

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleLeaveEvent:emptyNew()
15 local self = Event:new(VehicleLeaveEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table object)
Arguments
tableobjectobject
Return Values
tableinstanceinstance of event
Code
23function VehicleLeaveEvent:new(object)
24 local self = VehicleLeaveEvent:emptyNew()
25 self.object = object;
26 return self;
27end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
33function VehicleLeaveEvent:readStream(streamId, connection)
34 self.object = readNetworkNodeObject(streamId);
35 self:run(connection);
36end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function VehicleLeaveEvent:writeStream(streamId, connection)
43 writeNetworkNodeObject(streamId, self.object);
44end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
49function VehicleLeaveEvent:run(connection)
50 if not connection:getIsServer() then
51 if self.object.owner ~= nil then
52 self.object:setOwner(nil);
53 end;
54 g_server:broadcastEvent(VehicleLeaveEvent:new(self.object), nil, connection, self.object);
55 end;
56 self.object:leaveVehicle();
57end;

VehicleLowerImplementEvent

Description
Event for lowering implement

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleLowerImplementEvent:emptyNew()
15 local self = Event:new(VehicleLowerImplementEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table vehicle, integer jointIndex, boolean moveDown)
Arguments
tablevehiclevehicle
integerjointIndexindex of joint
booleanmoveDownmove down
Return Values
tableinstanceinstance of event
Code
25function VehicleLowerImplementEvent:new(vehicle, jointIndex, moveDown)
26 local self = VehicleLowerImplementEvent:emptyNew()
27 self.jointIndex = jointIndex;
28 self.vehicle = vehicle;
29 self.moveDown = moveDown;
30 return self;
31end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
37function VehicleLowerImplementEvent:readStream(streamId, connection)
38 self.vehicle = readNetworkNodeObject(streamId);
39 self.jointIndex = streamReadInt8(streamId);
40 self.moveDown = streamReadBool(streamId);
41 self:run(connection);
42end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
48function VehicleLowerImplementEvent:writeStream(streamId, connection)
49 writeNetworkNodeObject(streamId, self.vehicle);
50 streamWriteInt8(streamId, self.jointIndex);
51 streamWriteBool(streamId, self.moveDown);
52end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
57function VehicleLowerImplementEvent:run(connection)
58 self.vehicle:setJointMoveDown(self.jointIndex, self.moveDown, true);
59 if not connection:getIsServer() then
60 g_server:broadcastEvent(VehicleLowerImplementEvent:new(self.vehicle, self.jointIndex, self.moveDown), nil, connection, self.object);
61 end;
62end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, integer jointIndex, boolean moveDown, boolean noEventSend)
Arguments
tablevehiclevehicle
integerjointIndexindex of joint
booleanmoveDownmove down
booleannoEventSendno event send
Code
70function VehicleLowerImplementEvent.sendEvent(vehicle, jointIndex, moveDown, noEventSend)
71 if noEventSend == nil or noEventSend == false then
72 if g_server ~= nil then
73 g_server:broadcastEvent(VehicleLowerImplementEvent:new(vehicle, jointIndex, moveDown), nil, nil, vehicle);
74 else
75 g_client:getServerConnection():sendEvent(VehicleLowerImplementEvent:new(vehicle, jointIndex, moveDown));
76 end;
77 end;
78end;

VehicleSetBeaconLightEvent

Description
Event for beacon light state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function VehicleSetBeaconLightEvent:emptyNew()
16 local self = Event:new(VehicleSetBeaconLightEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean active)
Arguments
tableobjectobject
booleanactiveactive
Code
24function VehicleSetBeaconLightEvent:new(object, active)
25 local self = VehicleSetBeaconLightEvent:emptyNew()
26 self.active = active;
27 self.object = object;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function VehicleSetBeaconLightEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.active = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function VehicleSetBeaconLightEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.active);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function VehicleSetBeaconLightEvent:run(connection)
54 self.object:setBeaconLightsVisibility(self.active, true, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(VehicleSetBeaconLightEvent:new(self.object, self.active), nil, connection, self.object);
57 end;
58end;

VehicleSetLightEvent

Description
Event for light state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function VehicleSetLightEvent:emptyNew()
16 local self = Event:new(VehicleSetLightEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer lightsTypesMask)
Arguments
tableobjectobject
integerlightsTypesMasklight types mask
Code
24function VehicleSetLightEvent:new(object, lightsTypesMask)
25 local self = VehicleSetLightEvent:emptyNew()
26 self.lightsTypesMask = lightsTypesMask;
27 self.object = object;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function VehicleSetLightEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.lightsTypesMask = streamReadInt32(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function VehicleSetLightEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteInt32(streamId, self.lightsTypesMask);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function VehicleSetLightEvent:run(connection)
54 self.object:setLightsTypesMask(self.lightsTypesMask, true, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(VehicleSetLightEvent:new(self.object, self.lightsTypesMask), nil, connection, self.object);
57 end;
58end;

VehicleSetTurnLightEvent

Description
Event for turn light state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function VehicleSetTurnLightEvent:emptyNew()
16 local self = Event:new(VehicleSetTurnLightEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer state)
Arguments
tableobjectobject
integerstatestate
Code
24function VehicleSetTurnLightEvent:new(object, state)
25 local self = VehicleSetTurnLightEvent:emptyNew()
26 self.object = object;
27 self.state = state;
28 assert(state >= 0 and state <= Lights.TURNLIGHT_HAZARD);
29 return self;
30end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function VehicleSetTurnLightEvent:readStream(streamId, connection)
37 self.object = readNetworkNodeObject(streamId);
38 self.state = streamReadUIntN(streamId, Lights.turnLightSendNumBits);
39 self:run(connection);
40end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
46function VehicleSetTurnLightEvent:writeStream(streamId, connection)
47 writeNetworkNodeObject(streamId, self.object);
48 streamWriteUIntN(streamId, self.state, Lights.turnLightSendNumBits);
49end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
54function VehicleSetTurnLightEvent:run(connection)
55 self.object:setTurnLightState(self.state, true, true);
56 if not connection:getIsServer() then
57 g_server:broadcastEvent(VehicleSetTurnLightEvent:new(self.object, self.state), nil, connection, self.object);
58 end;
59end;

WaterTrailerSetIsFillingEvent

Description
Event for water trailer filling

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function WaterTrailerSetIsFillingEvent:emptyNew()
16 local self = Event:new(WaterTrailerSetIsFillingEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isFilling)
Arguments
tableobjectobject
booleanisFillingis filling
Code
24function WaterTrailerSetIsFillingEvent:new(object, isFilling)
25 local self = WaterTrailerSetIsFillingEvent:emptyNew()
26 self.object = object;
27 self.isFilling = isFilling;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function WaterTrailerSetIsFillingEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.isFilling = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function WaterTrailerSetIsFillingEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isFilling);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function WaterTrailerSetIsFillingEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 self.object:setIsWaterTrailerFilling(self.isFilling, true);
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean isFilling, boolean noEventSend)
Arguments
tableobjectobject
booleanisFillingis filling
booleannoEventSendno event send
Code
65function WaterTrailerSetIsFillingEvent.sendEvent(object, isFilling, noEventSend)
66 if isFilling ~= object.isWaterTrailerFilling then
67 if noEventSend == nil or noEventSend == false then
68 if g_server ~= nil then
69 g_server:broadcastEvent(WaterTrailerSetIsFillingEvent:new(object, isFilling), nil, nil, object);
70 else
71 g_client:getServerConnection():sendEvent(WaterTrailerSetIsFillingEvent:new(object, isFilling));
72 end;
73 end;
74 end;
75end;

WoodHarvesterCutTreeEvent

Description
Event for cut tree

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function WoodHarvesterCutTreeEvent:emptyNew()
16 local self = Event:new(WoodHarvesterCutTreeEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, float length)
Arguments
tableobjectobject
floatlengthlength
Code
24function WoodHarvesterCutTreeEvent:new(object, length)
25 local self = WoodHarvesterCutTreeEvent:emptyNew()
26 self.object = object;
27 self.length = length;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function WoodHarvesterCutTreeEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.length = streamReadFloat32(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function WoodHarvesterCutTreeEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteFloat32(streamId, self.length);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function WoodHarvesterCutTreeEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(WoodHarvesterCutTreeEvent:new(self.object, self.length), nil, connection, self.object);
56 end;
57 self.object:cutTree(self.length, true);
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, float length, boolean noEventSend)
Arguments
tableobjectobject
floatlengthlength
booleannoEventSendno event send
Code
65function WoodHarvesterCutTreeEvent.sendEvent(object, length, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(WoodHarvesterCutTreeEvent:new(object, length), nil, nil, object);
69 else
70 g_client:getServerConnection():sendEvent(WoodHarvesterCutTreeEvent:new(object, length));
71 end;
72 end;
73end;

WoodHarvesterOnCutTreeEvent

Description
Event for on cut tree

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function WoodHarvesterOnCutTreeEvent:emptyNew()
16 local self = Event:new(WoodHarvesterOnCutTreeEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, float radius)
Arguments
tableobjectobject
floatradiusradius
Code
24function WoodHarvesterOnCutTreeEvent:new(object, radius)
25 local self = WoodHarvesterOnCutTreeEvent:emptyNew()
26 self.object = object;
27 self.radius = radius;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function WoodHarvesterOnCutTreeEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.radius = streamReadFloat32(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function WoodHarvesterOnCutTreeEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteFloat32(streamId, self.radius);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function WoodHarvesterOnCutTreeEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(WoodHarvesterOnCutTreeEvent:new(self.object, self.radius), nil, connection, self.object);
56 end;
57 self.object:onCutTree(self.radius);
58end;

WoodHarvesterOnDelimbTreeEvent

Description
Event for delimb tree state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function WoodHarvesterOnDelimbTreeEvent:emptyNew()
16 local self = Event:new(WoodHarvesterOnDelimbTreeEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean state)
Arguments
tableobjectobject
booleanstatestate
Code
24function WoodHarvesterOnDelimbTreeEvent:new(object, state)
25 local self = WoodHarvesterOnDelimbTreeEvent:emptyNew()
26 self.object = object;
27 self.state = state;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function WoodHarvesterOnDelimbTreeEvent:readStream(streamId, connection)
36 self.object = readNetworkNodeObject(streamId);
37 self.state = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function WoodHarvesterOnDelimbTreeEvent:writeStream(streamId, connection)
46 writeNetworkNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.state);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function WoodHarvesterOnDelimbTreeEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(WoodHarvesterOnDelimbTreeEvent:new(self.object, self.state), nil, connection, self.object);
56 end;
57 self.object:onDelimbTree(self.state);
58end;

AnimatedObject

Description
Class for animated map objects

onCreate

Description
Creating animated object
Definition
onCreate(integer id)
Arguments
integeridnode id
Code
19function AnimatedObject:onCreate(id)
20 local object = AnimatedObject:new(g_server ~= nil, g_client ~= nil)
21 if object:load(id) then
22 g_currentMission:addOnCreateLoadedObject(object)
23 g_currentMission:addOnCreateLoadedObjectToSave(object)
24 object:register(true)
25 else
26 object:delete()
27 end
28end

new

Description
Creating new instance of animated object class
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableselfnew instance of object
Code
36function AnimatedObject:new(isServer, isClient, customMt)
37 local mt = customMt
38 if mt == nil then
39 mt = AnimatedObject_mt
40 end
41
42 local self = Object:new(isServer, isClient, mt)
43 self.nodeId = 0
44 self.isMoving = false
45 self.sendIsMoving = false
46 self.wasPressed = false
47 self.baseDirectory = nil
48 self.customEnvironment = g_currentMission.loadingMapModName;
49
50 return self
51end

load

Description
Load animated object attributes from object
Definition
load(integer nodeId)
Arguments
integernodeIdid of object to load from
Return Values
booleansuccesssuccess
Code
57function AnimatedObject:load(nodeId)
58 self.nodeId = nodeId
59
60 local xmlFilename = getUserAttribute(nodeId, "xmlFilename")
61
62 if xmlFilename == nil then
63 print("Error: Missing 'xmlFilename' user attribute for AnimatedObject node '"..getName(nodeId).."'!")
64 return false
65 end
66
67 local baseDir = g_currentMission.loadingMapBaseDirectory
68 if baseDir == "" then
69 baseDir = Utils.getNoNil(self.baseDirectory, baseDir)
70 end
71
72 local i18n = g_i18n;
73 if self.customEnvironment ~= nil then
74 i18n = _G[self.customEnvironment].g_i18n;
75 end
76
77 self.xmlFilename = Utils.getFilename(xmlFilename, baseDir)
78 local success = true
79 local xmlFile = loadXMLFile("AnimatedObject", self.xmlFilename)
80 if xmlFile ~= 0 then
81 local index = getUserAttribute(nodeId, "index")
82 if index ~= nil then
83 local key = nil
84 local i = 0
85 while true do
86 local objectKey = string.format("animatedObjects.animatedObject(%d)", i)
87 if not hasXMLProperty(xmlFile, objectKey) then
88 break
89 end
90
91 local configIndex = getXMLString(xmlFile, objectKey.."#index")
92 if configIndex == index then
93 key = objectKey
94 break
95 end
96 i = i + 1
97 end
98
99 if key ~= nil then
100 self.saveId = getXMLString(xmlFile, key.."#saveId");
101 if self.saveId == nil then
102 self.saveId = "AnimatedObject_"..getName(nodeId)
103 end
104
105 local animKey = key .. ".animation"
106
107 self.animation = {}
108 self.animation.parts = {}
109 self.animation.duration = Utils.getNoNil(getXMLFloat(xmlFile, animKey.."#duration"), 3) * 1000
110 if self.animation.duration == 0 then
111 self.animation.duration = 1000
112 end
113 self.animation.time = 0
114 self.animation.direction = 0
115
116 local i = 0
117 while true do
118 local partKey = string.format("%s.part(%d)", animKey, i)
119 if not hasXMLProperty(xmlFile, partKey) then
120 break
121 end
122
123 local node = Utils.indexToObject(self.nodeId, getXMLString(xmlFile, partKey.."#node"))
124 if node ~= nil then
125 local part = {}
126 part.node = node
127 part.animCurve = AnimCurve:new(linearInterpolatorN)
128 local hasFrames = false
129 local j = 0
130 while true do
131 local frameKey = string.format("%s.keyFrame(%d)", partKey, j)
132 if not hasXMLProperty(xmlFile, frameKey) then
133 break
134 end
135
136 local keyTime = getXMLFloat(xmlFile, frameKey.."#time")
137 local values = {self:loadFrameValues(xmlFile, frameKey, node)}
138 part.animCurve:addKeyframe({ v=values, time = keyTime})
139 hasFrames = true
140
141 j = j + 1
142 end
143
144 if hasFrames then
145 table.insert(self.animation.parts, part)
146 end
147 end
148 i = i + 1
149 end
150
151 local initialTime = Utils.getNoNil(getXMLFloat(xmlFile, animKey.."#initialTime"), 0)*1000
152 self:setAnimTime(initialTime/self.animation.duration)
153
154 local startTime = getXMLFloat(xmlFile, key..".openingHours#startTime")
155 local endTime = getXMLFloat(xmlFile, key..".openingHours#endTime")
156 if startTime ~= nil and endTime ~= nil then
157 local disableIfClosed = Utils.getNoNil(getXMLBool(xmlFile, key..".openingHours#disableIfClosed"), false)
158 local closedText = getXMLString(xmlFile, key..".openingHours#closedText")
159 if closedText ~= nil then
160 if i18n:hasText(closedText) then
161 closedText = i18n:getText(closedText)
162 end
163 end
164 self.openingHours = {startTime=startTime, endTime=endTime, disableIfClosed=disableIfClosed, closedText=closedText}
165 g_currentMission.environment:addHourChangeListener(self)
166 end
167
168 self.isEnabled = true
169
170
171 local triggerId = Utils.indexToObject(self.nodeId, getXMLString(xmlFile, key..".controls#triggerNode"))
172 if triggerId ~= nil then
173 self.controls = {}
174 self.controls.triggerId = triggerId
175
176 addTrigger(self.controls.triggerId, "triggerCallback", self)
177 for i=0, getNumOfChildren(self.controls.triggerId)-1 do
178 addTrigger(getChildAt(self.controls.triggerId, i), "triggerCallback", self)
179 end
180
181 local posKey = getXMLString(xmlFile, key..".controls#posKey")
182 if posKey ~= nil then
183 if InputBinding[posKey] ~= nil then
184 self.controls.posKey = InputBinding[posKey]
185 local posText = getXMLString(xmlFile, key..".controls#posText")
186 if posText ~= nil then
187 if i18n:hasText(posText) then
188 posText = i18n:getText(posText)
189 end
190 self.controls.posText = posText
191 end
192 local negText = getXMLString(xmlFile, key..".controls#negText")
193 if negText ~= nil then
194 if i18n:hasText(negText) then
195 negText = i18n:getText(negText)
196 end
197 self.controls.negText = negText
198 end
199
200 local negKey = getXMLString(xmlFile, key..".controls#negKey")
201 if negKey ~= nil then
202 if InputBinding[negKey] ~= nil then
203 self.controls.negKey = InputBinding[negKey]
204 else
205 print("Warning: Negative direction key '"..negKey.."' not defined!")
206 end
207 end
208 else
209 print("Warning: Positive direction key '"..posKey.."' not defined!")
210 end
211 end
212 end
213
214 if g_client ~= nil then
215 self.sampleMoving = SoundUtil.loadSample(xmlFile, {}, key..".sound", nil, baseDir, self.nodeId)
216 end
217 else
218 success = false
219 print("Error: index '"..index.."' not found in AnimatedObject xml '"..self.xmlFilename.."'!")
220 end
221 else
222 success = false
223 print("Error: Missing 'index' user attribute for AnimatedObject node '"..getName(nodeId).."'!")
224 end
225
226 delete(xmlFile)
227 end
228
229 self.animatedObjectDirtyFlag = self:getNextDirtyFlag();
230
231
232 return success
233end

loadFrameValues

Description
Load frame values from xml
Definition
loadFrameValues(integer fileId, string key, integer node)
Arguments
integerfileIdxml file id
stringkeykey
integernodenode id
Return Values
floatxx translation
floatyy translation
floatzz translation
floatrxx rotation
floatryy rotation
floatrzz rotation
floatsxx scale
floatsyy scale
floatszz scale
integervisibilityvisibility
Code
250function AnimatedObject:loadFrameValues(xmlFile, key, node)
251 local rx,ry,rz = Utils.getVectorFromString(getXMLString(xmlFile, key.."#rotation"))
252 local x,y,z = Utils.getVectorFromString(getXMLString(xmlFile, key.."#translation"))
253 local sx,sy,sz = Utils.getVectorFromString(getXMLString(xmlFile, key.."#scale"))
254 local isVisible = Utils.getNoNil(getXMLBool(xmlFile, key.."#visibility"), true)
255
256 local drx,dry,drz = getRotation(node)
257 rx = Utils.getNoNilRad(rx, drx)
258 ry = Utils.getNoNilRad(ry, dry)
259 rz = Utils.getNoNilRad(rz, drz)
260 local dx,dy,dz = getTranslation(node)
261 x = Utils.getNoNil(x, dx)
262 y = Utils.getNoNil(y, dy)
263 z = Utils.getNoNil(z, dz)
264 local dsx,dsy,dsz = getScale(node)
265 sx = Utils.getNoNil(sx, dsx)
266 sy = Utils.getNoNil(sy, dsy)
267 sz = Utils.getNoNil(sz, dsz)
268
269 local visibility = 1
270 if not isVisible then
271 visibility = 0
272 end
273
274 return x, y, z, rx, ry, rz, sx, sy, sz, visibility
275end

delete

Description
Delete animated object
Definition
delete()
Code
279function AnimatedObject:delete()
280 g_currentMission:removeOnCreateLoadedObjectToSave(self)
281 if self.controls.triggerId ~= nil then
282 removeTrigger(self.controls.triggerId)
283 for i=0, getNumOfChildren(self.controls.triggerId)-1 do
284 removeTrigger(getChildAt(self.controls.triggerId, i))
285 end
286 end
287 if self.sampleMoving ~= nil then
288 SoundUtil.deleteSample(self.sampleMoving)
289 end
290
291 g_currentMission.environment:removeHourChangeListener(self)
292
293 AnimatedObject:superClass().delete(self)
294end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
300function AnimatedObject:readStream(streamId, connection)
301 AnimatedObject:superClass().readStream(self, streamId, connection)
302 if connection:getIsServer() then
303 local animTime = streamReadFloat32(streamId)
304 self:setAnimTime(animTime)
305 end
306end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
312function AnimatedObject:writeStream(streamId, connection)
313 AnimatedObject:superClass().writeStream(self, streamId, connection)
314 if not connection:getIsServer() then
315 streamWriteFloat32(streamId, self.animation.time)
316 end
317end

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
324function AnimatedObject:readUpdateStream(streamId, timestamp, connection)
325 AnimatedObject:superClass().readUpdateStream(self, streamId, timestamp, connection)
326 if connection:getIsServer() then
327 self.isMoving = streamReadBool(streamId)
328 if self.isMoving then
329 local animTime = streamReadFloat32(streamId)
330 self:setAnimTime(animTime)
331 end
332 end
333end

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
340function AnimatedObject:writeUpdateStream(streamId, connection, dirtyMask)
341 AnimatedObject:superClass().writeUpdateStream(self, streamId, connection, dirtyMask)
342 if not connection:getIsServer() then
343 streamWriteBool(streamId, self.isMoving)
344
345 if self.isMoving then
346 streamWriteFloat32(streamId, self.animation.time)
347 end
348
349 self.sendIsMoving = self.isMoving;
350 end
351end

loadFromAttributesAndNodes

Description
Loading from attributes and nodes
Definition
loadFromAttributesAndNodes(integer xmlFile, string key)
Arguments
integerxmlFileid of xml object
stringkeykey
Return Values
booleansuccesssuccess
Code
358function AnimatedObject:loadFromAttributesAndNodes(xmlFile, key)
359 local animTime = getXMLFloat(xmlFile, key .. "#animTime")
360 if animTime ~= nil then
361 self.animation.direction = Utils.getNoNil(getXMLInt(xmlFile, key.."#direction"), 0)
362 self:setAnimTime(animTime)
363 end
364
365 AnimatedObject.hourChanged(self)
366
367 return true
368end

getSaveAttributesAndNodes

Description
Get save attributes and nodes
Definition
getSaveAttributesAndNodes()
Return Values
stringattributesattributes
Code
373function AnimatedObject:getSaveAttributesAndNodes()
374 local attributes = 'animTime="' .. tostring(self.animation.time) .. '" direction="'..tostring(self.animation.direction)..'"'
375 return attributes
376end

update

Description
Called on update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
381function AnimatedObject:update(dt)
382 AnimatedObject:superClass().update(self, dt)
383
384 if self.playerInRange then
385 if self.isEnabled then
386 if self.controls.posKey ~= nil and g_gui.currentGui == nil and not g_currentMission.isPlayerFrozen then
387 if self.controls.negKey == nil then
388 -- event based action
389 if InputBinding.hasEvent(self.controls.posKey) then
390 self.animation.direction = self.animation.direction * -1
391 if self.animation.direction == 0 then
392 if self.animation.time > 0 then
393 self.animation.direction = -1
394 else
395 self.animation.direction = 1
396 end
397 end
398 if g_server == nil then
399 g_client:getServerConnection():sendEvent(AnimatedObjectEvent:new(self, self.animation.direction))
400 end
401 end
402
403 local text = nil
404 if self.animation.direction == 0 then
405 if self.animation.time > 0 then
406 text = self.controls.negText
407 else
408 text = self.controls.posText
409 end
410 else
411 if self.animation.direction == 1 then
412 text = self.controls.negText
413 else
414 text = self.controls.posText
415 end
416 end
417
418 if text ~= nil then
419 g_currentMission:addHelpButtonText(text, self.controls.posKey, nil, GS_PRIO_VERY_HIGH);
420 end
421 else
422 -- move if key is pressed action
423 local changed = false
424 if InputBinding.isPressed(self.controls.posKey) then
425 self.wasPressed = true
426 if self.animation.direction ~= 1 and self.animation.time ~= 1 then
427 self.animation.direction = 1
428 changed = true
429 end
430 elseif InputBinding.isPressed(self.controls.negKey) then
431 self.wasPressed = true
432 if self.animation.direction ~= -1 and self.animation.time ~= 0 then
433 self.animation.direction = -1
434 changed = true
435 end
436 else
437 if self.animation.direction ~= 0 and self.wasPressed then
438 self.animation.direction = 0
439 changed = true
440 end
441 end;
442
443 if g_server == nil and changed then
444 g_client:getServerConnection():sendEvent(AnimatedObjectEvent:new(self, self.animation.direction))
445 end
446
447 if self.controls.posText ~= nil then
448 g_currentMission:addHelpButtonText(self.controls.posText, self.controls.posKey, nil, GS_PRIO_VERY_HIGH);
449 end;
450 if self.controls.negText ~= nil then
451 g_currentMission:addHelpButtonText(self.controls.negText, self.controls.negKey, nil, GS_PRIO_VERY_HIGH);
452 end;
453 end
454 end
455 else
456 if self.openingHours ~= nil and self.openingHours.closedText ~= nil then
457 g_currentMission:addExtraPrintText(self.openingHours.closedText)
458 end
459 end
460 end
461end

updateTick

Description
Called on update tick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
466function AnimatedObject:updateTick(dt)
467 AnimatedObject:superClass().updateTick(self, dt)
468
469 if self.isServer then
470 if self.animation.direction ~= 0 then
471 local newAnimTime = Utils.clamp(self.animation.time + (self.animation.direction*dt)/self.animation.duration, 0, 1)
472 self:setAnimTime(newAnimTime)
473 if newAnimTime == 0 or newAnimTime == 1 then
474 self.animation.direction = 0
475 end
476
477 self:raiseDirtyFlags(self.animatedObjectDirtyFlag);
478 end
479
480 self.isMoving = self.animation.direction ~= 0;
481
482 if self.sendIsMoving ~= self.isMoving then
483 self:raiseDirtyFlags(self.animatedObjectDirtyFlag);
484 end;
485 end
486
487 if self.isClient and self.sampleMoving ~= nil then
488 if self.isMoving then
489 if not self.sampleMoving.isPlaying then
490 SoundUtil.play3DSample(self.sampleMoving)
491 self.sampleMoving.isPlaying = true
492 end
493 else
494 if self.sampleMoving.isPlaying then
495 SoundUtil.stop3DSample(self.sampleMoving)
496 self.sampleMoving.isPlaying = false
497 end
498 end
499 end
500end

setAnimTime

Description
Set animation time
Definition
setAnimTime(float t)
Arguments
floatttime
Code
505function AnimatedObject:setAnimTime(t)
506 t = Utils.clamp(t, 0, 1)
507 for _, part in pairs(self.animation.parts) do
508 local v = part.animCurve:get(t)
509 self:setFrameValues(part.node, v)
510 end
511 self.animation.time = t
512end

setFrameValues

Description
Set frame values
Definition
setFrameValues(integer node, table v)
Arguments
integernodenode id
tablevvalues
Code
518function AnimatedObject:setFrameValues(node, v)
519 setTranslation(node, v[1], v[2], v[3])
520 setRotation(node, v[4], v[5], v[6])
521 setScale(node, v[7], v[8], v[9])
522 setVisibility(node, v[10] == 1)
523end

hourChanged

Description
Called on hour change
Definition
hourChanged()
Code
527function AnimatedObject:hourChanged()
528 if self.isServer then
529 local currentHour = g_currentMission.environment.currentHour
530 if self.openingHours ~= nil then
531 if currentHour >= self.openingHours.startTime and currentHour < self.openingHours.endTime then
532 if not self.openingHours.isOpen then
533 if self.isServer then
534 self.animation.direction = 1
535 end
536 self.openingHours.isOpen = true
537 end
538 if self.openingHours.disableIfClosed then
539 self.isEnabled = true
540 end
541 else
542 if self.openingHours.isOpen then
543 if self.isServer then
544 self.animation.direction = -1
545 end
546 self.openingHours.isOpen = false
547 end
548 if self.openingHours.disableIfClosed then
549 self.isEnabled = false
550 end
551 end
552 end;
553 end
554end

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of object that calls callback
booleanonEntercalled on enter
booleanonLeavecalled on leave
booleanonStaycalled on stay
Code
563function AnimatedObject:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
564 if g_currentMission.missionInfo:isa(FSCareerMissionInfo) then
565 if onEnter or onLeave then
566 if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then
567 if onEnter then
568 self.playerInRange = g_currentMission.player
569 else
570 self.playerInRange = nil
571 end
572 end
573 end
574 end
575end

Bale

Description
Class for bales
Parent
MountableObject

new

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

delete

Description
Deleting bale object
Definition
delete()
Code
42function 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);
50end;

readUpdateStream

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

writeUpdateStream

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

readStream

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

writeStream

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

mount

Description
Mount bale 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
126function 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);
129end;

unmount

Description
Unmount bale
Definition
unmount()
Code
133function Bale:unmount()
134 if Bale:superClass().unmount(self) then
135 g_currentMission:addItemToSave(self);
136 return true;
137 end
138 return false;
139end;

setNodeId

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

createNode

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

load

Description
Load bale
Definition
load(string i3dFilename, float x, float y, float z, float rx, float ry, float rz, integer fillLevel)
Arguments
stringi3dFilenamei3d file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
integerfillLevelfill level
Code
224function 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);
234end;

loadFromMemory

Description
Setting node id and i3d file name
Definition
loadFromMemory(integer nodeId, string i3dFilename)
Arguments
integernodeIdnode id
stringi3dFilenamei3d file name
Code
240function Bale:loadFromMemory(nodeId, i3dFilename)
241 self.i3dFilename = i3dFilename;
242 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename);
243 self:setNodeId(nodeId);
244end;

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
252function 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;
301end;

getSaveAttributesAndNodes

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

getValue

Description
Get price value of bale
Definition
getValue()
Code
323function Bale:getValue()
324 local pricePerLiter = g_currentMission.economyManager:getPricePerLiter(self.fillType);
325 return self.fillLevel * pricePerLiter * self.baleValueScale;
326end;

getFillType

Description
Get fill type of bale
Definition
getFillType()
Return Values
integerfillTypecurrent fill type id
Code
331function Bale:getFillType()
332 return self.fillType;
333end;

getFillLevel

Description
Get fill level of bale
Definition
getFillLevel()
Return Values
integerfillLevelcurrent fill level
Code
338function Bale:getFillLevel()
339 return self.fillLevel;
340end;

setFillLevel

Description
Set fill level of bale
Definition
setFillLevel(integer fillLevel)
Arguments
integerfillLevelfill level
Code
345function Bale:setFillLevel(fillLevel)
346 self.fillLevel = fillLevel;
347end;

setWrappingState

Description
Set wrapping state of bale
Definition
setWrappingState(boolean wrappingState)
Arguments
booleanwrappingStatenew wrapping state
Code
360function 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
368end

getMeshNodes

Description
Set wrapping state of bale
Definition
getMeshNodes()
Return Values
tablemeshNodesmesh nodes
Code
373function Bale:getMeshNodes()
374 return self.meshNodes
375end;

Basketball

Description
Class for basketballs
Parent
PhysicsObject

onCreate

Description
Creating basketball
Definition
onCreate(integer id)
Arguments
integeridnode id
Code
15function Basketball:onCreate(id)
16 local basketball = Basketball:new(g_server ~= nil, g_client ~= nil)
17 local x, y, z = getWorldTranslation(id)
18 local rx, ry, rz = getWorldRotation(id)
19 local filename = Utils.getNoNil(getUserAttribute(id, "filename"), "data/objects/basketball/basketball.i3d")
20 if basketball:load(filename, x, y, z, rx, ry, rz) then
21 g_currentMission:addOnCreateLoadedObject(basketball)
22 basketball:register(true)
23 else
24 basketball:delete()
25 end
26end

new

Description
Creating basketball object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustomMt
Return Values
tableinstanceInstance of object
Code
34function Basketball:new(isServer, isClient, customMt)
35 local mt = customMt
36 if mt == nil then
37 mt = Basketball_mt
38 end
39
40 local self = PhysicsObject:new(isServer, isClient, mt)
41
42 self.forcedClipDistance = 150
43 registerObjectClassName(self, "Basketball")
44
45 return self
46end

delete

Description
Deleting basketball object
Definition
delete()
Code
50function Basketball:delete()
51 if self.i3dFilename ~= nil then
52 Utils.releaseSharedI3DFile(self.i3dFilename, nil, true)
53 end
54 unregisterObjectClassName(self)
55 Basketball:superClass().delete(self)
56end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
62function Basketball:readStream(streamId, connection)
63 if connection:getIsServer() then
64 local i3dFilename = Utils.convertFromNetworkFilename(streamReadString(streamId))
65 if self.nodeId == 0 then
66 self:createNode(i3dFilename)
67 end
68 Basketball:superClass().readStream(self, streamId, connection)
69 end
70end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
76function Basketball:writeStream(streamId, connection)
77 if not connection:getIsServer() then
78 streamWriteString(streamId, Utils.convertToNetworkFilename(self.i3dFilename))
79 Basketball:superClass().writeStream(self, streamId, connection)
80 end
81end

createNode

Description
Load node from i3d file
Definition
createNode(string i3dFilename)
Arguments
stringi3dFilenamei3d file name
Code
86function Basketball:createNode(i3dFilename)
87 self.i3dFilename = i3dFilename
88 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename)
89 local basketballRoot = Utils.loadSharedI3DFile(i3dFilename)
90
91 local basketballId = getChildAt(basketballRoot, 0)
92 link(getRootNode(), basketballId)
93 delete(basketballRoot)
94
95 self:setNodeId(basketballId)
96end

load

Description
Load Basketball
Definition
load(string i3dFilename, float x, float y, float z, float rx, float ry, float rz)
Arguments
stringi3dFilenamei3d file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
Code
107function Basketball:load(i3dFilename, x,y,z, rx,ry,rz)
108 self.i3dFilename = i3dFilename
109 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename)
110 self:createNode(i3dFilename)
111 setTranslation(self.nodeId, x, y, z)
112 setRotation(self.nodeId, rx, ry, rz)
113
114 return true
115end;

Bga

Description
Class for bga

onCreate

Description
Creating bga object
Definition
onCreate(integer id)
Arguments
integeridnode id
Code
15function Bga:onCreate(id)
16 local object = Bga:new(g_server ~= nil, g_client ~= nil);
17 if object:load(id) then
18 g_currentMission:addOnCreateLoadedObject(object);
19 g_currentMission:addOnCreateLoadedObjectToSave(object);
20 object:register(true);
21 else
22 object:delete();
23 end;
24end;

new

Description
Creating bga object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustomMt
Return Values
tableinstanceInstance of object
Code
32function Bga:new(isServer, isClient, customMt)
33 local mt = customMt;
34 if mt == nil then
35 mt = Bga_mt;
36 end;
37
38 local self = Object:new(isServer, isClient, mt);
39 self.nodeId = 0;
40 self.tipTriggers = {};
41 self.bunkerFillLevel = 0;
42 self.liquidManureFillLevel = 0
43 self.sentBunkerFillLevel = self.bunkerFillLevel;
44 self.sentLiquidManureFillLevel = self.liquidManureFillLevel;
45
46 self.bunkerUseTime = 0;
47 self.bunkerUseSpeed = 100; -- liter per ingame seconds
48
49 self.bunkerPlaneMinY = 0;
50 self.bunkerPlaneMaxY = 1;
51 self.bunkerPlaneAlpha = 0;
52 self.bunkerPlaneMoveScale = 0.2;
53 self.bunkerPlaneNoScaling = false;
54
55 self.bunkerRolls = {};
56 self.bunkerRollsSpeed = -0.01;
57
58 self.bunkerCapacity = 50000;
59 self.liquidManureCapacity = 1000000
60
61 self.fillDeltaToManureDeltaScale = 0.3;
62 self.liquidManureToDigestateScale = 0.4
63 self.baleValueToFillDeltaScale = 1;
64
65 self.bgaDirtyFlag = self:getNextDirtyFlag();
66 return self;
67end;

delete

Description
Deleting bga object
Definition
delete()
Code
71function Bga:delete()
72 g_currentMission:removeOnCreateLoadedObjectToSave(self);
73 if self.digestateSiloTrigger ~= nil then
74 self.digestateSiloTrigger:delete();
75 end;
76 if self.isServer then
77 for _,trigger in pairs(self.tipTriggers) do
78 if trigger.isRegistered then
79 trigger:unregister();
80 trigger:delete();
81 end;
82 end;
83 end;
84 if self.objectDeleteTriggerId ~= nil then
85 removeTrigger(self.objectDeleteTriggerId);
86 end;
87 if self.nodeId ~= 0 then
88 g_currentMission:removeNodeObject(self.nodeId);
89 end;
90 Bga:superClass().delete(self);
91end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
97function Bga:readStream(streamId, connection)
98 if connection:getIsServer() then
99 local bunkerFillLevel = streamReadFloat32(streamId);
100 local liquidManureFillLevel = streamReadFloat32(streamId);
101 self:setFillLevel(bunkerFillLevel);
102 self:setFillLevel(liquidManureFillLevel, FillUtil.FILLTYPE_LIQUIDMANURE)
103 if self.digestateSiloTrigger ~= nil then
104 self.digestateSiloTrigger:setFillLevel(streamReadFloat32(streamId));
105 end
106 end;
107end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
113function Bga:writeStream(streamId, connection)
114 if not connection:getIsServer() then
115 streamWriteFloat32(streamId, self.bunkerFillLevel);
116 streamWriteFloat32(streamId, self.liquidManureFillLevel);
117 if self.digestateSiloTrigger ~= nil then
118 streamWriteFloat32(streamId, self.digestateSiloTrigger.fillLevel);
119 end
120 end;
121end;

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
128function Bga:readUpdateStream(streamId, timestamp, connection)
129 if connection:getIsServer() then
130 local bunkerFillLevel = streamReadFloat32(streamId);
131 local liquidManureFillLevel = streamReadFloat32(streamId);
132 self:setFillLevel(bunkerFillLevel);
133 self:setFillLevel(liquidManureFillLevel, FillUtil.FILLTYPE_LIQUIDMANURE)
134 if self.digestateSiloTrigger ~= nil then
135 self.digestateSiloTrigger:setFillLevel(streamReadFloat32(streamId));
136 end
137 end;
138end;

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
145function Bga:writeUpdateStream(streamId, connection, dirtyMask)
146 if not connection:getIsServer() then
147 streamWriteFloat32(streamId, self.bunkerFillLevel);
148 streamWriteFloat32(streamId, self.liquidManureFillLevel);
149 if self.digestateSiloTrigger ~= nil then
150 streamWriteFloat32(streamId, self.digestateSiloTrigger.fillLevel);
151 end
152 end;
153end;

load

Description
Load bga
Definition
load(integer nodeId)
Arguments
integernodeIdnode id
Return Values
booleansuccesssuccess
Code
159function Bga:load(nodeId)
160
161 self.nodeId = nodeId;
162
163 local digestateSiloIndex = getUserAttribute(nodeId, "liquidManureSiloIndex");
164 if digestateSiloIndex ~= nil then
165 local digestateSiloId = Utils.indexToObject(nodeId, digestateSiloIndex);
166 if digestateSiloId ~= nil then
167 self.digestateSiloTrigger = LiquidManureFillTrigger:new();
168 if self.digestateSiloTrigger:load(digestateSiloId, self, FillUtil.FILLTYPE_DIGESTATE) then
169 g_currentMission:addLiquidManureFillTrigger("$l10n_ui_bgaLiquidManureSilo", self.digestateSiloTrigger)
170 else
171 self.digestateSiloTrigger:delete();
172 self.digestateSiloTrigger = nil;
173 end
174 end;
175 end;
176
177 local tipTriggersIndex = getUserAttribute(nodeId, "tipTriggersIndex");
178 if tipTriggersIndex ~= nil then
179 local tipTriggersId = Utils.indexToObject(nodeId, tipTriggersIndex);
180 if tipTriggersId ~= nil then
181 local numChildren = getNumOfChildren(tipTriggersId);
182 for i=1,numChildren do
183 local childId = getChildAt(tipTriggersId, i-1);
184 local tipTrigger = TipTrigger:new(self.isServer, self.isClient);
185 local success = tipTrigger:load(childId, self);
186 if success then
187 tipTrigger.incomeName = "incomeBga";
188 g_currentMission:addOnCreateLoadedObject(tipTrigger);
189 tipTrigger:register(true);
190 tipTrigger:addTipTriggerTarget(self, false);
191 table.insert(self.tipTriggers, tipTrigger);
192 else
193 tipTrigger:delete();
194 end
195 end;
196 end;
197 end;
198
199 if self.isServer then
200 local objectDeleteTriggerIndex = getUserAttribute(nodeId, "objectDeleteTriggerIndex");
201 if objectDeleteTriggerIndex ~= nil then
202 self.objectDeleteTriggerId = Utils.indexToObject(nodeId, objectDeleteTriggerIndex);
203 if self.objectDeleteTriggerId ~= nil then
204 addTrigger(self.objectDeleteTriggerId, "objectDeleteTriggerCallback", self);
205 end;
206 end;
207
208 local silageCatcherIndex = getUserAttribute(nodeId, "silageCatcherIndex");
209 if silageCatcherIndex ~= nil then
210 local silageCatcherId = Utils.indexToObject(nodeId, silageCatcherIndex);
211 if silageCatcherId ~= nil then
212 print("Warning: Bga silageCatcherIndex is no longer supported. Use tipTrigger shovelTargetIndex instead");
213 end
214 end;
215 end;
216
217 local bunkerPlaneIndex = getUserAttribute(nodeId, "bunkerPlaneIndex");
218 if bunkerPlaneIndex ~= nil then
219 self.bunkerPlaneId = Utils.indexToObject(nodeId, bunkerPlaneIndex);
220 end;
221 local minY, maxY = Utils.getVectorFromString(getUserAttribute(nodeId, "bunkerPlaneMinMaxY"));
222 if minY ~= nil and maxY ~= nil then
223 self.bunkerPlaneMinY = minY;
224 self.bunkerPlaneMaxY = maxY;
225 end;
226
227 local bunkerPlaneNoScaling = Utils.getNoNil(