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 |
List all available commands
Show frames per second
Enable/disable frame per second limiter
Frame per second limit attribute
Print detailed entity list
Print detailed resource list
Enable parallel rendering and physics
Quits application
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 |
Class for chainsaws
Creating chainsaw objectDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | custom metatable |
table | instance | Instance of object |
17 | function 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 |
25 | end |
Load chainsaw from xml fileDefinition
load(string xmlFilename, table player)Arguments
string | xmlFilename | xml file name |
table | player | player |
boolean | success | success |
32 | function 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 |
154 | end |
Deleting chainsawDefinition
delete()Code
158 | function 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 |
176 | end |
UpdateDefinition
update(float dt, boolean allowInput)Arguments
float | dt | time since last call in ms |
boolean | allowInput | allow input |
182 | function 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 |
425 | end |
Update ring selectorDefinition
updateRingSelector()Code
429 | function 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 |
443 | end |
Update tickDefinition
updateTick(float dt, boolean allowInput)Arguments
float | dt | time since last call in ms |
boolean | allowInput | allow input |
449 | function 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 |
466 | end |
Set cuttingDefinition
setCutting(boolean isCutting, boolean isHorizontalCut, boolean noEventSend)Arguments
boolean | isCutting | is cutting |
boolean | isHorizontalCut | is horizontal cut |
boolean | noEventSend | no event send |
473 | function 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 |
480 | end |
Set on delimbDefinition
setOnDelimb(boolean state)Arguments
boolean | state | new state |
485 | function 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 |
495 | end |
Set hand nodeDefinition
setHandNode(integer handNode)Arguments
integer | handNode | hand node id |
507 | function 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 |
520 | end |
On activateDefinition
onActivate(boolean allowInput)Arguments
boolean | allowInput | allow input |
525 | function 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 |
534 | end |
On deactivateDefinition
onDeactivate(boolean allowInput)Arguments
boolean | allowInput | allow input |
539 | function 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 |
563 | end |
Class for handtools
Register handtool typeDefinition
registerHandTool(string typeName, table classObject)Arguments
string | typeName | name of new type |
table | classObject | class object |
Creating handtool objectDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | custom metatable |
table | instance | Instance of object |
30 | function 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; |
42 | end; |
Load chainsaw from xml fileDefinition
load(string xmlFilename, table player)Arguments
string | xmlFilename | xml file name |
table | player | player |
boolean | success | success |
49 | function 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; |
97 | end; |
Called on client side on joinDefinition
readStream(integer streamId, table connection, table player)Arguments
integer | streamId | stream ID |
table | connection | connection |
table | player | player |
107 | function 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); |
112 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
118 | function HandTool:writeStream(streamId, connection) |
119 | streamWriteString(streamId, Utils.convertToNetworkFilename(self.configFileName)); |
120 | streamWriteUInt16(streamId, self.age); |
121 | streamWriteUInt16(streamId, self.price); |
122 | end; |
Deleting handtoolDefinition
delete()Code
126 | function 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; |
137 | end; |
On activateDefinition
onActivate(boolean allowInput)Arguments
boolean | allowInput | allow input |
151 | function HandTool:onActivate(allowInput) |
152 | setVisibility(self.rootNode, true); |
153 | end; |
On deactivateDefinition
onDeactivate(boolean allowInput)Arguments
boolean | allowInput | allow input |
158 | function HandTool:onDeactivate(allowInput) |
159 | setVisibility(self.rootNode, false); |
160 | end; |
Get daily up keepDefinition
getDailyUpKeep()Return Values
float | dailyUpKeep | daily up keep |
175 | function 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 |
183 | end |
Get sell priceDefinition
getSellPrice()Return Values
float | sellPrice | sell price |
188 | function 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)); |
197 | end |
Called if day changedDefinition
dayChanged()Code
201 | function HandTool:dayChanged() |
202 | self.age = self.age + 1; |
203 | end |
Event for ai rotate left
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function AIVehicleRotateLeftEvent:emptyNew() |
16 | local self = Event:new(AIVehicleRotateLeftEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object)Arguments
table | object | object |
23 | function AIVehicleRotateLeftEvent:new(object) |
24 | local self = AIVehicleRotateLeftEvent:emptyNew() |
25 | self.object = object; |
26 | return self; |
27 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
33 | function AIVehicleRotateLeftEvent:readStream(streamId, connection) |
34 | self.object = readNetworkNodeObject(streamId); |
35 | self:run(connection); |
36 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
42 | function AIVehicleRotateLeftEvent:writeStream(streamId, connection) |
43 | writeNetworkNodeObject(streamId, self.object); |
44 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
49 | function AIVehicleRotateLeftEvent:run(connection) |
50 | AIVehicle.aiRotateLeft(self.object); |
51 | end; |
Event for ai rotate right
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function AIVehicleRotateRightEvent:emptyNew() |
16 | local self = Event:new(AIVehicleRotateRightEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object)Arguments
table | object | object |
23 | function AIVehicleRotateRightEvent:new(object) |
24 | local self = AIVehicleRotateRightEvent:emptyNew() |
25 | self.object = object; |
26 | return self; |
27 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
33 | function AIVehicleRotateRightEvent:readStream(streamId, connection) |
34 | self.object = readNetworkNodeObject(streamId); |
35 | self:run(connection); |
36 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
42 | function AIVehicleRotateRightEvent:writeStream(streamId, connection) |
43 | writeNetworkNodeObject(streamId, self.object); |
44 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
49 | function AIVehicleRotateRightEvent:run(connection) |
50 | AIVehicle.aiRotateRight(self.object); |
51 | end; |
Event for conveyor belt angle
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function AIVehicleSetConveyorBeltAngleEvent:emptyNew() |
16 | local self = Event:new(AIVehicleSetConveyorBeltAngleEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table vehicle, integer currentAngle)Arguments
table | vehicle | vehicle |
integer | currentAngle | current angle |
24 | function AIVehicleSetConveyorBeltAngleEvent:new(vehicle, currentAngle) |
25 | local self = AIVehicleSetConveyorBeltAngleEvent:emptyNew() |
26 | self.currentAngle = currentAngle; |
27 | self.vehicle = vehicle; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function AIVehicleSetConveyorBeltAngleEvent:readStream(streamId, connection) |
36 | self.vehicle = readNetworkNodeObject(streamId); |
37 | self.currentAngle = streamReadInt8(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function AIVehicleSetConveyorBeltAngleEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.vehicle); |
47 | streamWriteInt8(streamId, self.currentAngle); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Event for ai start
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function AIVehicleSetStartedEvent:emptyNew() |
16 | local self = Event:new(AIVehicleSetStartedEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, integer reason, boolean isStarted, integer helper)Arguments
table | object | object |
integer | reason | reason |
boolean | isStarted | is started |
integer | helper | helper id |
26 | function 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; |
35 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
41 | function 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); |
50 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
56 | function 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 |
64 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
69 | function 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; |
82 | end; |
Event for animation start
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function AnimatedVehicleStartEvent:emptyNew() |
16 | local self = Event:new(AnimatedVehicleStartEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, string name, float speed, float animTime)Arguments
table | object | object |
string | name | name of animation |
float | speed | speed of animation |
float | animTime | time of animation |
26 | function 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; |
33 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
39 | function 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; |
49 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
55 | function AnimatedVehicleStartEvent:writeStream(streamId, connection) |
56 | writeNetworkNodeObject(streamId, self.object); |
57 | streamWriteString(streamId, self.name); |
58 | streamWriteFloat32(streamId, self.speed); |
59 | streamWriteFloat32(streamId, self.animTime); |
60 | end; |
Event for animation stop
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function AnimatedVehicleStopEvent:emptyNew() |
16 | local self = Event:new(AnimatedVehicleStopEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, string name)Arguments
table | object | object |
string | name | name |
24 | function AnimatedVehicleStopEvent:new(object, name) |
25 | local self = AnimatedVehicleStopEvent:emptyNew() |
26 | self.name = name; |
27 | self.object = object; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function AnimatedVehicleStopEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.name = streamReadString(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function AnimatedVehicleStopEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteString(streamId, self.name); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Event for bale loader state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function BaleLoaderStateEvent:emptyNew() |
16 | local self = Event:new(BaleLoaderStateEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, integer stateId, integer nearestBaleServerId)Arguments
table | object | object |
integer | stateId | stateId |
integer | nearestBaleServerId | nearestBaleServerId |
25 | function 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; |
32 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
38 | function 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); |
46 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
52 | function 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; |
58 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
63 | function BaleLoaderStateEvent:run(connection) |
64 | self.object:doStateChange(self.stateId, self.nearestBaleServerId); |
65 | end; |
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function BalerCreateBaleEvent:emptyNew() |
15 | local self = Event:new(BalerCreateBaleEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
new(table object, integer baleFillType, float baleTime)Arguments
table | object | object |
integer | baleFillType | bale fill type |
float | baleTime | bale time |
24 | function 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; |
30 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
36 | function 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); |
41 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
47 | function BalerCreateBaleEvent:writeStream(streamId, connection) |
48 | writeNetworkNodeObject(streamId, self.object); |
49 | streamWriteFloat32(streamId, self.baleTime); |
50 | streamWriteUIntN(streamId, self.baleFillType, FillUtil.sendNumBits); |
51 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
56 | function BalerCreateBaleEvent:run(connection) |
57 | self.object:createBale(self.baleFillType); |
58 | self.object:setBaleTime(table.getn(self.object.baler.bales), self.baleTime); |
59 | end; |
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function BalerSetBaleTimeEvent:emptyNew() |
15 | local self = Event:new(BalerSetBaleTimeEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
BalerSetBaleTimeEvent:new(table object, integer bale, float baleTime)Arguments
table | object | object |
integer | bale | bale id |
float | baleTime | bale time |
24 | function 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; |
30 | end; |
Called on client side on joinDefinition
BalerSetBaleTimeEvent:readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
36 | function BalerSetBaleTimeEvent:readStream(streamId, connection) |
37 | self.object = readNetworkNodeObject(streamId); |
38 | self.bale = streamReadInt32(streamId); |
39 | self.baleTime = streamReadFloat32(streamId); |
40 | self:run(connection); |
41 | end; |
Called on server side on joinDefinition
BalerSetBaleTimeEvent:writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
47 | function BalerSetBaleTimeEvent:writeStream(streamId, connection) |
48 | writeNetworkNodeObject(streamId, self.object); |
49 | streamWriteInt32(streamId, self.bale); |
50 | streamWriteFloat32(streamId, self.baleTime); |
51 | end; |
Run action on receiving sideDefinition
BalerSetBaleTimeEvent:run(integer connection)Arguments
integer | connection | connection |
56 | function BalerSetBaleTimeEvent:run(connection) |
57 | self.object:setBaleTime(self.bale, self.baleTime); |
58 | end; |
Event for baler is unloading state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function BalerSetIsUnloadingBaleEvent:emptyNew() |
16 | local self = Event:new(BalerSetIsUnloadingBaleEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isUnloadingBale)Arguments
table | object | object |
boolean | isUnloadingBale | is unloading bale |
24 | function BalerSetIsUnloadingBaleEvent:new(object, isUnloadingBale) |
25 | local self = BalerSetIsUnloadingBaleEvent:emptyNew() |
26 | self.object = object; |
27 | self.isUnloadingBale = isUnloadingBale; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function BalerSetIsUnloadingBaleEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.isUnloadingBale = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function BalerSetIsUnloadingBaleEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.isUnloadingBale); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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); |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table object, boolean isUnloadingBale, boolean noEventSend)Arguments
table | object | object |
boolean | isUnloadingBale | isUnloadingBale |
boolean | noEventSend | no event send |
65 | function 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; |
73 | end; |
Event for bale wrapper state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function BaleWrapperStateEvent:emptyNew() |
16 | local self = Event:new(BaleWrapperStateEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, integer stateId, integer nearestBaleServerId)Arguments
table | object | object |
integer | stateId | state id |
integer | nearestBaleServerId | server id of nearest bale |
25 | function 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; |
32 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
38 | function 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); |
45 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
51 | function 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; |
57 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
62 | function BaleWrapperStateEvent:run(connection) |
63 | self.object:doStateChange(self.stateId, self.nearestBaleServerId); |
64 | end; |
Event for bunker silo close
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
13 | function BunkerSiloCloseEvent:emptyNew() |
14 | local self = Event:new(BunkerSiloCloseEvent_mt); |
15 | return self; |
16 | end; |
Create new instance of eventDefinition
new(table bunkerSilo)Arguments
table | bunkerSilo | bunkerSilo |
table | instance | instance of event |
22 | function BunkerSiloCloseEvent:new(bunkerSilo) |
23 | local self = BunkerSiloCloseEvent:emptyNew() |
24 | self.bunkerSilo = bunkerSilo; |
25 | return self; |
26 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
32 | function BunkerSiloCloseEvent:readStream(streamId, connection) |
33 | if not connection:getIsServer() then |
34 | self.bunkerSilo = readNetworkNodeObject(streamId); |
35 | end; |
36 | self:run(connection); |
37 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
43 | function BunkerSiloCloseEvent:writeStream(streamId, connection) |
44 | if connection:getIsServer() then |
45 | writeNetworkNodeObject(streamId, self.bunkerSilo); |
46 | end; |
47 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
52 | function BunkerSiloCloseEvent:run(connection) |
53 | if not connection:getIsServer() then |
54 | self.bunkerSilo:setState(BunkerSilo.STATE_CLOSED); |
55 | end; |
56 | end; |
Event for bunker silo open
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
13 | function BunkerSiloOpenEvent:emptyNew() |
14 | local self = Event:new(BunkerSiloOpenEvent_mt); |
15 | return self; |
16 | end; |
Create new instance of eventDefinition
new(table bunkerSilo, float x, float y, float z)Arguments
table | bunkerSilo | bunkerSilo |
float | x | x opening position |
float | y | y opening position |
float | z | z opening position |
table | instance | instance of event |
25 | function 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; |
32 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
38 | function 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); |
46 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
52 | function 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; |
59 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
64 | function BunkerSiloOpenEvent:run(connection) |
65 | if not connection:getIsServer() then |
66 | self.bunkerSilo:openSilo(self.x, self.y, self.z); |
67 | end; |
68 | end; |
Event for cutting
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function ChainsawCutEvent:emptyNew() |
15 | local self = Event:new(ChainsawCutEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
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
integer | splitShapeId | id of split shape |
float | x | x |
float | y | y |
float | z | z |
float | nx | nx |
float | ny | ny |
float | nz | nz |
float | yx | yx |
float | yy | yy |
float | yz | yz |
float | cutSizeY | y cut size |
float | cutSizeZ | z cut size |
table | instance | instance of event |
34 | function 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; |
42 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
48 | function 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 |
66 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
72 | function 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 |
87 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
92 | function ChainsawCutEvent:run(connection) |
93 | print("Error: ChainsawCutEvent is not allowed to be executed on a local client"); |
94 | end; |
Event for delimb
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function ChainsawDelimbEvent:emptyNew() |
15 | local self = Event:new(ChainsawDelimbEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
new(table player, float x, float y, float z, float nx, float ny, float nz, float yx, float yy, float yz, boolean onDelimb)Arguments
table | player | player |
float | x | x |
float | y | y |
float | z | z |
float | nx | nx |
float | ny | ny |
float | nz | nz |
float | yx | yx |
float | yy | yy |
float | yz | yz |
boolean | onDelimb | on delimb |
table | instance | instance of event |
33 | function 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; |
41 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
47 | function 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 |
79 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
85 | function 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 |
101 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
106 | function ChainsawDelimbEvent:run(connection) |
107 | print("Error: ChainsawDelimbEvent is not allowed to be executed on a local client"); |
108 | end; |
Event for chainsaw state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function ChainsawStateEvent:emptyNew() |
15 | local self = Event:new(ChainsawStateEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
new(table player, boolean isCutting, boolean isHorizontalCut)Arguments
table | player | player |
boolean | isCutting | is cutting |
boolean | isHorizontalCut | is horizontal cutting |
table | instance | instance of event |
25 | function 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; |
31 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
37 | function ChainsawStateEvent:readStream(streamId, connection) |
38 | self.player = readNetworkNodeObject(streamId); |
39 | self.isCutting = streamReadBool(streamId); |
40 | self.isHorizontalCut = streamReadBool(streamId); |
41 | self:run(connection); |
42 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
48 | function ChainsawStateEvent:writeStream(streamId, connection) |
49 | writeNetworkNodeObject(streamId, self.player); |
50 | streamWriteBool(streamId, self.isCutting); |
51 | streamWriteBool(streamId, self.isHorizontalCut); |
52 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
57 | function 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; |
66 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table player, boolean isCutting, boolean isHorizontalCut, boolean noEventSend)Arguments
table | player | player |
boolean | isCutting | is cutting |
boolean | isHorizontalCut | is horizontal cutting |
boolean | noEventSend | no event send |
74 | function 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; |
85 | end; |
Event for straw enable state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function CombineStrawEnableEvent:emptyNew() |
16 | local self = Event:new(CombineStrawEnableEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table vehicle, boolean isStrawEnabled)Arguments
table | vehicle | vehicle |
boolean | isStrawEnabled | is straw enabled |
24 | function CombineStrawEnableEvent:new(vehicle, isStrawEnabled) |
25 | local self = CombineStrawEnableEvent:emptyNew() |
26 | self.vehicle = vehicle; |
27 | self.isStrawEnabled = isStrawEnabled; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function CombineStrawEnableEvent:readStream(streamId, connection) |
36 | self.vehicle = readNetworkNodeObject(streamId); |
37 | self.isStrawEnabled = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function CombineStrawEnableEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.vehicle); |
47 | streamWriteBool(streamId, self.isStrawEnabled); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean isStrawEnabled, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | isStrawEnabled | is straw enabled |
boolean | noEventSend | no event send |
65 | function 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; |
73 | end; |
Event for toggle lower all
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function DrivableToggleLowerAllEvent:emptyNew() |
16 | local self = Event:new(DrivableToggleLowerAllEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table vehicle)Arguments
table | vehicle | vehicle |
23 | function DrivableToggleLowerAllEvent:new(vehicle) |
24 | local self = DrivableToggleLowerAllEvent:emptyNew() |
25 | self.vehicle = vehicle; |
26 | return self; |
27 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
33 | function DrivableToggleLowerAllEvent:readStream(streamId, connection) |
34 | self.vehicle = readNetworkNodeObject(streamId); |
35 | self:run(connection); |
36 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
42 | function DrivableToggleLowerAllEvent:writeStream(streamId, connection) |
43 | writeNetworkNodeObject(streamId, self.vehicle); |
44 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
49 | function 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; |
54 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | noEventSend | no event send |
60 | function 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; |
68 | end; |
Event for set folding direction
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function FoldableSetFoldDirectionEvent:emptyNew() |
16 | local self = Event:new(FoldableSetFoldDirectionEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, integer direction, boolean moveToMiddle)Arguments
table | object | object |
integer | direction | direction |
boolean | moveToMiddle | move to middle |
25 | function 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; |
31 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
37 | function 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); |
42 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
48 | function FoldableSetFoldDirectionEvent:writeStream(streamId, connection) |
49 | writeNetworkNodeObject(streamId, self.object); |
50 | streamWriteUIntN(streamId, self.direction+1, 2); |
51 | streamWriteBool(streamId, self.moveToMiddle); |
52 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
57 | function 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; |
64 | end; |
Event for greenhouse tank filling state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function GreenhouseSetIsWaterTankFillingEvent:emptyNew() |
16 | local self = Event:new(GreenhouseSetIsWaterTankFillingEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isFilling, table trailer)Arguments
table | object | object |
boolean | isFilling | is filling |
table | trailer | trailer |
table | instance | instance of event |
26 | function 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; |
32 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
38 | function 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); |
45 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
51 | function 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; |
57 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
62 | function 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); |
67 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table object, boolean isFilling, table trailer, boolean noEventSend)Arguments
table | object | object |
boolean | isFilling | is filling |
table | trailer | trailer |
boolean | noEventSend | no event send |
75 | function 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; |
86 | end; |
Event for honking
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function HonkEvent:emptyNew() |
16 | local self = Event:new(HonkEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isPlaying)Arguments
table | object | object |
boolean | isPlaying | honk is playing |
24 | function HonkEvent:new(object, isPlaying) |
25 | local self = HonkEvent:emptyNew() |
26 | self.object = object; |
27 | self.isPlaying = isPlaying; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function HonkEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.isPlaying = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function HonkEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.isPlaying); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean isPlaying, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | isPlaying | honk is playing |
boolean | noEventSend | no event send |
65 | function 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; |
75 | end; |
Event for hpw state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function HPWPlaceableStateEvent:emptyNew() |
16 | local self = Event:new(HPWPlaceableStateEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean doWashing)Arguments
table | object | object |
boolean | doWashing | do washing |
table | instance | instance of event |
25 | function HPWPlaceableStateEvent:new(object, doWashing) |
26 | local self = HPWPlaceableStateEvent:emptyNew() |
27 | self.object = object; |
28 | self.doWashing = doWashing; |
29 | |
30 | return self; |
31 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
37 | function HPWPlaceableStateEvent:readStream(streamId, connection) |
38 | self.object = readNetworkNodeObject(streamId); |
39 | self.doWashing = streamReadBool(streamId); |
40 | self:run(connection); |
41 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
47 | function HPWPlaceableStateEvent:writeStream(streamId, connection) |
48 | writeNetworkNodeObject(streamId, self.object); |
49 | streamWriteBool(streamId, self.doWashing); |
50 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
55 | function 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); |
60 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table object, boolean doWashing, boolean noEventSend)Arguments
table | object | object |
boolean | doWashing | do washing |
boolean | noEventSend | no event send |
67 | function 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; |
77 | end; |
Event for hpw turn on state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function HPWPlaceableTurnOnEvent:emptyNew() |
16 | local self = Event:new(HPWPlaceableTurnOnEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isTurnedOn, table player)Arguments
table | object | object |
boolean | isTurnedOn | is turned on |
table | player | player |
table | instance | instance of event |
26 | function 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; |
33 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
39 | function 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); |
46 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
52 | function 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; |
58 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
63 | function 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); |
68 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table object, boolean isTurnedOn, table player, boolean noEventSend)Arguments
table | object | object |
boolean | isTurnedOn | is turned on |
table | player | player |
boolean | noEventSend | no event send |
76 | function 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; |
86 | end; |
Event for honking
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function MixerWagonBaleNotAcceptedEvent:emptyNew() |
16 | local self = Event:new(MixerWagonBaleNotAcceptedEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object)Arguments
table | object | object |
23 | function MixerWagonBaleNotAcceptedEvent:new(object) |
24 | local self = MixerWagonBaleNotAcceptedEvent:emptyNew() |
25 | self.object = object; |
26 | self.isPlaying = isPlaying; |
27 | return self; |
28 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
34 | function 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")); |
38 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
44 | function MixerWagonBaleNotAcceptedEvent:writeStream(streamId, connection) |
45 | writeNetworkNodeObject(streamId, self.object); |
46 | end; |
Event for mower toggle drop
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function MowerToggleWindrowDropEvent:emptyNew() |
16 | local self = Event:new(MowerToggleWindrowDropEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean useMowerWindrowDropAreas)Arguments
table | object | object |
boolean | useMowerWindrowDropAreas | use mower windrow drop areas |
24 | function MowerToggleWindrowDropEvent:new(object, useMowerWindrowDropAreas) |
25 | local self = MowerToggleWindrowDropEvent:emptyNew() |
26 | self.object = object; |
27 | self.useMowerWindrowDropAreas = useMowerWindrowDropAreas; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function MowerToggleWindrowDropEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.useMowerWindrowDropAreas = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function MowerToggleWindrowDropEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.useMowerWindrowDropAreas); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
60 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean useMowerWindrowDropAreas, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | useMowerWindrowDropAreas | use mower windrow drop areas |
boolean | noEventSend | no event send |
67 | function 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; |
77 | end; |
Event for toggle overloading
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function OverloadingToggleUnloadEvent:emptyNew() |
16 | local self = Event:new(OverloadingToggleUnloadEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isActive)Arguments
table | object | object |
boolean | isActive | is active |
24 | function OverloadingToggleUnloadEvent:new(vehicle, isActive) |
25 | local self = OverloadingToggleUnloadEvent:emptyNew() |
26 | self.vehicle = vehicle; |
27 | self.isActive = isActive; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function OverloadingToggleUnloadEvent:readStream(streamId, connection) |
36 | self.vehicle = readNetworkNodeObject(streamId); |
37 | self.isActive = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function OverloadingToggleUnloadEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.vehicle); |
47 | streamWriteBool(streamId, self.isActive); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean isActive, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | isActive | is active |
boolean | noEventSend | no event send |
65 | function 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; |
73 | end; |
Event for lower and lift pickup
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function PickupSetStateEvent:emptyNew() |
16 | local self = Event:new(PickupSetStateEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isPickupLowered)Arguments
table | object | object |
boolean | isPickupLowered | is pickup lowered |
24 | function PickupSetStateEvent:new(object, isPickupLowered) |
25 | local self = PickupSetStateEvent:emptyNew() |
26 | self.object = object; |
27 | self.isPickupLowered = isPickupLowered; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function PickupSetStateEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.isPickupLowered = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function PickupSetStateEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.isPickupLowered); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
60 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean isPickupLowered, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | isPickupLowered | is pickup lowered |
boolean | noEventSend | no event send |
67 | function 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; |
77 | end; |
Event for limit to field state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function PlantLimitToFieldEvent:emptyNew() |
16 | local self = Event:new(PlantLimitToFieldEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean plantLimitToField)Arguments
table | object | object |
boolean | plantLimitToField | plant is limited to field |
24 | function PlantLimitToFieldEvent:new(object, plantLimitToField) |
25 | local self = PlantLimitToFieldEvent:emptyNew() |
26 | self.object = object; |
27 | self.plantLimitToField = plantLimitToField; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function PlantLimitToFieldEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.plantLimitToField = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function PlantLimitToFieldEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.plantLimitToField); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Event for limit to field state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function PloughLimitToFieldEvent:emptyNew() |
16 | local self = Event:new(PloughLimitToFieldEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean ploughLimitToField)Arguments
table | object | object |
boolean | ploughLimitToField | plough is limited to field |
24 | function PloughLimitToFieldEvent:new(object, ploughLimitToField) |
25 | local self = PloughLimitToFieldEvent:emptyNew() |
26 | self.object = object; |
27 | self.ploughLimitToField = ploughLimitToField; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function PloughLimitToFieldEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.ploughLimitToField = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function PloughLimitToFieldEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.ploughLimitToField); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Event for plough rotation
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function PloughRotationEvent:emptyNew() |
16 | local self = Event:new(PloughRotationEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean rotationMax)Arguments
table | object | object |
boolean | rotationMax | rotation max |
24 | function PloughRotationEvent:new(object, rotationMax) |
25 | local self = PloughRotationEvent:emptyNew() |
26 | self.object = object; |
27 | self.rotationMax = rotationMax; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function PloughRotationEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.rotationMax = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function PloughRotationEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.rotationMax); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Event for toggle box creation
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function ReceivingHopperSetCreateBoxesEvent:emptyNew() |
16 | local self = Event:new(ReceivingHopperSetCreateBoxesEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean state)Arguments
table | object | object |
boolean | state | state |
24 | function ReceivingHopperSetCreateBoxesEvent:new(object, state) |
25 | local self = ReceivingHopperSetCreateBoxesEvent:emptyNew() |
26 | self.object = object; |
27 | self.state = state; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function ReceivingHopperSetCreateBoxesEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.state = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function ReceivingHopperSetCreateBoxesEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.state); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean state, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | state | state |
boolean | noEventSend | no event send |
65 | function 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; |
75 | end; |
Event for reverse driving state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function ReverseDrivingSetStateEvent:emptyNew() |
16 | local self = Event:new(ReverseDrivingSetStateEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table vehicle, boolean isReverseDriving)Arguments
table | vehicle | vehicle |
boolean | isReverseDriving | is reverse driving |
24 | function ReverseDrivingSetStateEvent:new(vehicle, isReverseDriving) |
25 | local self = ReverseDrivingSetStateEvent:emptyNew() |
26 | self.vehicle = vehicle; |
27 | self.isReverseDriving = isReverseDriving; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function ReverseDrivingSetStateEvent:readStream(streamId, connection) |
36 | self.vehicle = readNetworkNodeObject(streamId); |
37 | self.isReverseDriving = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function ReverseDrivingSetStateEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.vehicle); |
47 | streamWriteBool(streamId, self.isReverseDriving); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
60 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean isReverseDriving, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | isReverseDriving | is reverse driving |
boolean | noEventSend | no event send |
67 | function 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; |
77 | end; |
Event for ridge marker state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function RidgeMarkerSetStateEvent:emptyNew() |
16 | local self = Event:new(RidgeMarkerSetStateEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean state)Arguments
table | object | object |
boolean | state | state |
24 | function 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; |
30 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
36 | function RidgeMarkerSetStateEvent:readStream(streamId, connection) |
37 | self.object = readNetworkNodeObject(streamId); |
38 | self.state = streamReadUIntN(streamId, RidgeMarker.sendNumBits); |
39 | self:run(connection); |
40 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
46 | function RidgeMarkerSetStateEvent:writeStream(streamId, connection) |
47 | writeNetworkNodeObject(streamId, self.object); |
48 | streamWriteUIntN(streamId, self.state, RidgeMarker.sendNumBits); |
49 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
54 | function 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; |
59 | end; |
Event for cover state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SetCoverStateEvent:emptyNew() |
16 | local self = Event:new(SetCoverStateEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isOpen)Arguments
table | object | object |
boolean | isOpen | cover is open |
24 | function SetCoverStateEvent:new(object, isOpen) |
25 | local self = SetCoverStateEvent:emptyNew() |
26 | self.object = object; |
27 | self.isOpen = isOpen; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function SetCoverStateEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.isOpen = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function SetCoverStateEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.isOpen); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
60 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean isOpen, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | isOpen | cover is open |
boolean | noEventSend | no event send |
67 | function 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; |
77 | end; |
Event for steering mode
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SetCrabSteeringEvent:emptyNew() |
16 | local self = Event:new(SetCrabSteeringEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, integer state)Arguments
table | object | object |
integer | state | state |
24 | function SetCrabSteeringEvent:new(vehicle, state) |
25 | local self = SetCrabSteeringEvent:emptyNew() |
26 | self.vehicle = vehicle; |
27 | self.state = state; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function SetCrabSteeringEvent:readStream(streamId, connection) |
36 | self.vehicle = readNetworkNodeObject(streamId); |
37 | self.state = streamReadUIntN(streamId, CrabSteering.STEERING_SEND_NUM_BITS); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function SetCrabSteeringEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.vehicle); |
47 | streamWriteUIntN(streamId, self.state, CrabSteering.STEERING_SEND_NUM_BITS); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, integer state, boolean noEventSend)Arguments
table | vehicle | vehicle |
integer | state | state |
boolean | noEventSend | no event send |
65 | function 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; |
73 | end; |
Event for cruise control speed
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SetCruiseControlSpeedEvent:emptyNew() |
16 | local self = Event:new(SetCruiseControlSpeedEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table vehicle, float speed)Arguments
table | vehicle | vehicle |
float | speed | speed |
24 | function SetCruiseControlSpeedEvent:new(vehicle, speed) |
25 | local self = SetCruiseControlSpeedEvent:emptyNew() |
26 | self.speed = speed; |
27 | self.vehicle = vehicle; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function SetCruiseControlSpeedEvent:readStream(streamId, connection) |
36 | self.vehicle = readNetworkNodeObject(streamId); |
37 | self.speed = streamReadUInt8(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function SetCruiseControlSpeedEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.vehicle); |
47 | streamWriteUInt8(streamId, self.speed); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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); |
58 | end; |
Event for cruise control state event
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SetCruiseControlStateEvent:emptyNew() |
16 | local self = Event:new(SetCruiseControlStateEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table vehicle, integer state)Arguments
table | vehicle | vehicle |
integer | state | state |
24 | function SetCruiseControlStateEvent:new(vehicle, state) |
25 | local self = SetCruiseControlStateEvent:emptyNew() |
26 | self.state = state; |
27 | self.vehicle = vehicle; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function SetCruiseControlStateEvent:readStream(streamId, connection) |
36 | self.vehicle = readNetworkNodeObject(streamId); |
37 | self.state = streamReadUIntN(streamId, 2); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function SetCruiseControlStateEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.vehicle); |
47 | streamWriteUIntN(streamId, self.state, 2); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function SetCruiseControlStateEvent:run(connection) |
54 | self.vehicle:setCruiseControlState(self.state, true); |
55 | end; |
Event for discharge to ground state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SetDischargeToGroundEvent:emptyNew() |
16 | local self = Event:new(SetDischargeToGroundEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean dischargeToGround)Arguments
table | object | object |
boolean | dischargeToGround | discharge to ground |
24 | function SetDischargeToGroundEvent:new(object, dischargeToGround) |
25 | local self = SetDischargeToGroundEvent:emptyNew() |
26 | self.object = object; |
27 | self.dischargeToGround = dischargeToGround; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function SetDischargeToGroundEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.dischargeToGround = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function SetDischargeToGroundEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.dischargeToGround); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
60 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean dischargeToGround, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | dischargeToGround | discharge to ground |
boolean | noEventSend | no event send |
67 | function 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; |
77 | end; |
Event for set is filling state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SetIsFillingEvent:emptyNew() |
16 | local self = Event:new(SetIsFillingEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isFilling)Arguments
table | object | object |
boolean | isFilling | is filling |
24 | function SetIsFillingEvent:new(object, isFilling) |
25 | local self = SetIsFillingEvent:emptyNew() |
26 | self.object = object; |
27 | self.isFilling = isFilling; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function SetIsFillingEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.isFilling = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function SetIsFillingEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.isFilling); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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); |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table object, boolean isFilling, boolean noEventSend)Arguments
table | object | object |
boolean | isFilling | is filling |
boolean | noEventSend | no event send |
65 | function 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; |
75 | end; |
Event for motor turned on state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SetMotorTurnedOnEvent:emptyNew() |
16 | local self = Event:new(SetMotorTurnedOnEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean turnedOn)Arguments
table | object | object |
boolean | turnedOn | is turned on |
24 | function SetMotorTurnedOnEvent:new(object, turnedOn) |
25 | local self = SetMotorTurnedOnEvent:emptyNew() |
26 | self.object = object; |
27 | self.turnedOn = turnedOn; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function SetMotorTurnedOnEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.turnedOn = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function SetMotorTurnedOnEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.turnedOn); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
62 | end; |
Event for pipe state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SetPipeStateEvent:emptyNew() |
16 | local self = Event:new(SetPipeStateEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, integer pipeState)Arguments
table | object | object |
integer | pipeState | pipe state |
24 | function 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; |
30 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
36 | function SetPipeStateEvent:readStream(streamId, connection) |
37 | self.object = readNetworkNodeObject(streamId); |
38 | self.pipeState = streamReadUIntN(streamId, 3); |
39 | self:run(connection); |
40 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
46 | function SetPipeStateEvent:writeStream(streamId, connection) |
47 | writeNetworkNodeObject(streamId, self.object); |
48 | streamWriteUIntN(streamId, self.pipeState, 3); |
49 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
54 | function 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; |
59 | end; |
Event for turned on state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SetTurnedOnEvent:emptyNew() |
16 | local self = Event:new(SetTurnedOnEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isTurnedOn)Arguments
table | object | object |
boolean | isTurnedOn | is turned on state |
24 | function SetTurnedOnEvent:new(object, isTurnedOn) |
25 | local self = SetTurnedOnEvent:emptyNew() |
26 | self.object = object; |
27 | self.isTurnedOn = isTurnedOn; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function SetTurnedOnEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.isTurnedOn = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function SetTurnedOnEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.isTurnedOn); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
60 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table object, boolean isTurnedOn, boolean noEventSend)Arguments
table | object | object |
boolean | isTurnedOn | is turned on state |
boolean | noEventSend | no event send |
67 | function 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; |
77 | end; |
Set seed index event
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SowingMachineSetSeedIndex:emptyNew() |
16 | local self = Event:new(SowingMachineSetSeedIndex_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, integer seedIndex)Arguments
table | object | object |
integer | seedIndex | index of seed |
24 | function SowingMachineSetSeedIndex:new(object, seedIndex) |
25 | local self = SowingMachineSetSeedIndex:emptyNew() |
26 | self.object = object; |
27 | self.seedIndex = seedIndex; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function SowingMachineSetSeedIndex:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.seedIndex = streamReadUInt8(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function SowingMachineSetSeedIndex:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteUInt8(streamId, self.seedIndex); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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); |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table object, integer seedIndex, boolean noEventSend)Arguments
table | object | object |
integer | seedIndex | index of seed |
boolean | noEventSend | no event send |
65 | function 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; |
73 | end; |
Event for toggle refueling
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function SteerableToggleRefuelEvent:emptyNew() |
16 | local self = Event:new(SteerableToggleRefuelEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isRefueling)Arguments
table | object | object |
boolean | isRefueling | is refueling state |
24 | function SteerableToggleRefuelEvent:new(object, isRefueling) |
25 | local self = SteerableToggleRefuelEvent:emptyNew() |
26 | self.object = object; |
27 | self.isRefueling = isRefueling; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function SteerableToggleRefuelEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.isRefueling = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function SteerableToggleRefuelEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.isRefueling); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Event for straw blower door state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function StrawBlowerDoorOpenEvent:emptyNew() |
16 | local self = Event:new(StrawBlowerDoorOpenEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isStrawBlowerDoorOpen)Arguments
table | object | object |
boolean | isStrawBlowerDoorOpen | straw blower door state |
24 | function StrawBlowerDoorOpenEvent:new(object, isStrawBlowerDoorOpen) |
25 | local self = StrawBlowerDoorOpenEvent:emptyNew() |
26 | self.object = object; |
27 | self.isStrawBlowerDoorOpen = isStrawBlowerDoorOpen; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function StrawBlowerDoorOpenEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.isStrawBlowerDoorOpen = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function StrawBlowerDoorOpenEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.isStrawBlowerDoorOpen); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
60 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean isStrawBlowerDoorOpen, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | isStrawBlowerDoorOpen | straw blower door state |
boolean | noEventSend | no event send |
67 | function 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; |
77 | end; |
Event for tension belts state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function TensionBeltsEvent:emptyNew() |
16 | local self = Event:new(TensionBeltsEvent_mt) |
17 | return self |
18 | end |
Create new instance of eventDefinition
new(table object, boolean isActive, integer beltId)Arguments
table | object | object |
boolean | isActive | belt is active |
integer | beltId | id of belt |
25 | function 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 |
31 | end |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
37 | function 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) |
44 | end |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
50 | function 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) |
57 | end |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
62 | function 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) |
67 | end |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, boolean isActive, integer beltId, boolean noEventSend)Arguments
table | vehicle | vehicle |
boolean | isActive | belt is active |
integer | beltId | id of belt |
boolean | noEventSend | no event send |
75 | function 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 |
83 | end |
Event for tension belts state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function TensionBeltsRefreshEvent:emptyNew() |
16 | local self = Event:new(TensionBeltsRefreshEvent_mt) |
17 | return self |
18 | end |
Create new instance of eventDefinition
new(table object, boolean isActive, integer beltId)Arguments
table | object | object |
boolean | isActive | belt is active |
integer | beltId | id of belt |
25 | function TensionBeltsRefreshEvent:new(object) |
26 | local self = TensionBeltsRefreshEvent:emptyNew() |
27 | self.object = object |
28 | return self |
29 | end |
Called on client sideDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function TensionBeltsRefreshEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self:run(connection) |
38 | end |
Called on server sideDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
44 | function TensionBeltsRefreshEvent:writeStream(streamId, connection) |
45 | writeNetworkNodeObject(streamId, self.object) |
46 | end |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
51 | function TensionBeltsRefreshEvent:run(connection) |
52 | if not connection:getIsServer() then |
53 | g_server:broadcastEvent(self, false, connection, self.object) |
54 | end |
55 | self.object:refreshTensionBelts() |
56 | end |
Event for toggle trailer tipping
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function TrailerToggleTipEvent:emptyNew() |
16 | local self = Event:new(TrailerToggleTipEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isStart, table tipTrigger, integer tipReferencePointIndex)Arguments
table | object | object |
boolean | isStart | is start |
table | tipTrigger | tip trigger |
integer | tipReferencePointIndex | index of tip reference point |
26 | function 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; |
34 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
40 | function 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); |
48 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
54 | function 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; |
61 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
66 | function 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; |
76 | end; |
Event for loading of pallet on tree planter
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function TreePlanterLoadPalletEvent:emptyNew() |
16 | local self = Event:new(TreePlanterLoadPalletEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, integer palletObjectId)Arguments
table | object | object |
integer | palletObjectId | object id of pallet |
24 | function TreePlanterLoadPalletEvent:new(object, palletObjectId) |
25 | local self = TreePlanterLoadPalletEvent:emptyNew() |
26 | self.object = object; |
27 | self.palletObjectId = palletObjectId; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function TreePlanterLoadPalletEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.palletObjectId = readNetworkNodeObjectId(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function TreePlanterLoadPalletEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | writeNetworkNodeObjectId(streamId, self.palletObjectId); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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); |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table object, integer palletObjectId, boolean noEventSend)Arguments
table | object | object |
integer | palletObjectId | object id of pallet |
boolean | noEventSend | no event send |
65 | function 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; |
73 | end; |
Event for attaching
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function VehicleAttachEvent:emptyNew() |
15 | local self = Event:new(VehicleAttachEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
new(table vehicle, table implement, integer inputJointIndex, integer jointIndex, boolean startLowered)Arguments
table | vehicle | vehicle |
table | implement | implement |
integer | inputJointIndex | index of input attacher joint |
integer | jointIndex | index of attacher joint |
boolean | startLowered | start in lowered state |
table | instance | instance of event |
27 | function 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; |
36 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
42 | function 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); |
49 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
55 | function 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); |
61 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
66 | function 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; |
71 | end; |
Event for bundle attaching
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function VehicleBundleAttachEvent:emptyNew() |
15 | local self = Event:new(VehicleBundleAttachEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
new(table bundles)Arguments
table | bundles | bundles |
table | instance | instance of event |
23 | function VehicleBundleAttachEvent:new(bundles) |
24 | local self = VehicleBundleAttachEvent:emptyNew() |
25 | self.bundles = bundles; |
26 | return self; |
27 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
33 | function 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 |
42 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
48 | function 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 |
57 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
62 | function 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; |
67 | end; |
Event for detaching
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function VehicleDetachEvent:emptyNew() |
15 | local self = Event:new(VehicleDetachEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
new(table vehicle, table implement)Arguments
table | vehicle | vehicle |
table | implement | implement |
table | instance | instance of event |
24 | function VehicleDetachEvent:new(vehicle, implement) |
25 | local self = VehicleDetachEvent:emptyNew() |
26 | self.implement = implement; |
27 | self.vehicle = vehicle; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function 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; |
43 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
49 | function VehicleDetachEvent:writeStream(streamId, connection) |
50 | writeNetworkNodeObject(streamId, self.vehicle); |
51 | writeNetworkNodeObject(streamId, self.implement); |
52 | end; |
Event for enter request
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function VehicleEnterRequestEvent:emptyNew() |
15 | local self = Event:new(VehicleEnterRequestEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
new(table object, string controllerName, integer playerIndex, integer playerColorIndex)Arguments
table | object | object |
string | controllerName | name of controller |
integer | playerIndex | index of player |
integer | playerColorIndex | index of player color |
table | instance | instance of event |
26 | function 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; |
34 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
40 | function 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) |
47 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
53 | function 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) |
58 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
63 | function 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; |
69 | end; |
Event for enter response
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function VehicleEnterResponseEvent:emptyNew() |
15 | local self = Event:new(VehicleEnterResponseEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
new(table id, boolean isOwner, string controllerName, integer playerIndex, integer playerColorIndex)Arguments
table | id | id |
boolean | isOwner | is owner |
string | controllerName | name of controller |
integer | playerIndex | index of player |
integer | playerColorIndex | index of player color |
table | instance | instance of event |
27 | function 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; |
35 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
41 | function 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); |
50 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
56 | function 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; |
64 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
69 | function 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; |
79 | end; |
Event for leaving
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function VehicleLeaveEvent:emptyNew() |
15 | local self = Event:new(VehicleLeaveEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
new(table object)Arguments
table | object | object |
table | instance | instance of event |
23 | function VehicleLeaveEvent:new(object) |
24 | local self = VehicleLeaveEvent:emptyNew() |
25 | self.object = object; |
26 | return self; |
27 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
33 | function VehicleLeaveEvent:readStream(streamId, connection) |
34 | self.object = readNetworkNodeObject(streamId); |
35 | self:run(connection); |
36 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
42 | function VehicleLeaveEvent:writeStream(streamId, connection) |
43 | writeNetworkNodeObject(streamId, self.object); |
44 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
49 | function 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(); |
57 | end; |
Event for lowering implement
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
14 | function VehicleLowerImplementEvent:emptyNew() |
15 | local self = Event:new(VehicleLowerImplementEvent_mt); |
16 | return self; |
17 | end; |
Create new instance of eventDefinition
new(table vehicle, integer jointIndex, boolean moveDown)Arguments
table | vehicle | vehicle |
integer | jointIndex | index of joint |
boolean | moveDown | move down |
table | instance | instance of event |
25 | function 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; |
31 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
37 | function VehicleLowerImplementEvent:readStream(streamId, connection) |
38 | self.vehicle = readNetworkNodeObject(streamId); |
39 | self.jointIndex = streamReadInt8(streamId); |
40 | self.moveDown = streamReadBool(streamId); |
41 | self:run(connection); |
42 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
48 | function VehicleLowerImplementEvent:writeStream(streamId, connection) |
49 | writeNetworkNodeObject(streamId, self.vehicle); |
50 | streamWriteInt8(streamId, self.jointIndex); |
51 | streamWriteBool(streamId, self.moveDown); |
52 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
57 | function 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; |
62 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table vehicle, integer jointIndex, boolean moveDown, boolean noEventSend)Arguments
table | vehicle | vehicle |
integer | jointIndex | index of joint |
boolean | moveDown | move down |
boolean | noEventSend | no event send |
70 | function 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; |
78 | end; |
Event for beacon light state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function VehicleSetBeaconLightEvent:emptyNew() |
16 | local self = Event:new(VehicleSetBeaconLightEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean active)Arguments
table | object | object |
boolean | active | active |
24 | function VehicleSetBeaconLightEvent:new(object, active) |
25 | local self = VehicleSetBeaconLightEvent:emptyNew() |
26 | self.active = active; |
27 | self.object = object; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function VehicleSetBeaconLightEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.active = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function VehicleSetBeaconLightEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.active); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Event for light state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function VehicleSetLightEvent:emptyNew() |
16 | local self = Event:new(VehicleSetLightEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, integer lightsTypesMask)Arguments
table | object | object |
integer | lightsTypesMask | light types mask |
24 | function VehicleSetLightEvent:new(object, lightsTypesMask) |
25 | local self = VehicleSetLightEvent:emptyNew() |
26 | self.lightsTypesMask = lightsTypesMask; |
27 | self.object = object; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function VehicleSetLightEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.lightsTypesMask = streamReadInt32(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function VehicleSetLightEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteInt32(streamId, self.lightsTypesMask); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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; |
58 | end; |
Event for turn light state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function VehicleSetTurnLightEvent:emptyNew() |
16 | local self = Event:new(VehicleSetTurnLightEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, integer state)Arguments
table | object | object |
integer | state | state |
24 | function 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; |
30 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
36 | function VehicleSetTurnLightEvent:readStream(streamId, connection) |
37 | self.object = readNetworkNodeObject(streamId); |
38 | self.state = streamReadUIntN(streamId, Lights.turnLightSendNumBits); |
39 | self:run(connection); |
40 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
46 | function VehicleSetTurnLightEvent:writeStream(streamId, connection) |
47 | writeNetworkNodeObject(streamId, self.object); |
48 | streamWriteUIntN(streamId, self.state, Lights.turnLightSendNumBits); |
49 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
54 | function 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; |
59 | end; |
Event for water trailer filling
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function WaterTrailerSetIsFillingEvent:emptyNew() |
16 | local self = Event:new(WaterTrailerSetIsFillingEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean isFilling)Arguments
table | object | object |
boolean | isFilling | is filling |
24 | function WaterTrailerSetIsFillingEvent:new(object, isFilling) |
25 | local self = WaterTrailerSetIsFillingEvent:emptyNew() |
26 | self.object = object; |
27 | self.isFilling = isFilling; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function WaterTrailerSetIsFillingEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.isFilling = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function WaterTrailerSetIsFillingEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.isFilling); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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); |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table object, boolean isFilling, boolean noEventSend)Arguments
table | object | object |
boolean | isFilling | is filling |
boolean | noEventSend | no event send |
65 | function 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; |
75 | end; |
Event for cut tree
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function WoodHarvesterCutTreeEvent:emptyNew() |
16 | local self = Event:new(WoodHarvesterCutTreeEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, float length)Arguments
table | object | object |
float | length | length |
24 | function WoodHarvesterCutTreeEvent:new(object, length) |
25 | local self = WoodHarvesterCutTreeEvent:emptyNew() |
26 | self.object = object; |
27 | self.length = length; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function WoodHarvesterCutTreeEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.length = streamReadFloat32(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function WoodHarvesterCutTreeEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteFloat32(streamId, self.length); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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); |
58 | end; |
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clientsDefinition
sendEvent(table object, float length, boolean noEventSend)Arguments
table | object | object |
float | length | length |
boolean | noEventSend | no event send |
65 | function 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; |
73 | end; |
Event for on cut tree
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function WoodHarvesterOnCutTreeEvent:emptyNew() |
16 | local self = Event:new(WoodHarvesterOnCutTreeEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, float radius)Arguments
table | object | object |
float | radius | radius |
24 | function WoodHarvesterOnCutTreeEvent:new(object, radius) |
25 | local self = WoodHarvesterOnCutTreeEvent:emptyNew() |
26 | self.object = object; |
27 | self.radius = radius; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function WoodHarvesterOnCutTreeEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.radius = streamReadFloat32(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function WoodHarvesterOnCutTreeEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteFloat32(streamId, self.radius); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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); |
58 | end; |
Event for delimb tree state
Create instance of Event classDefinition
emptyNew()Return Values
table | self | instance of class event |
15 | function WoodHarvesterOnDelimbTreeEvent:emptyNew() |
16 | local self = Event:new(WoodHarvesterOnDelimbTreeEvent_mt); |
17 | return self; |
18 | end; |
Create new instance of eventDefinition
new(table object, boolean state)Arguments
table | object | object |
boolean | state | state |
24 | function WoodHarvesterOnDelimbTreeEvent:new(object, state) |
25 | local self = WoodHarvesterOnDelimbTreeEvent:emptyNew() |
26 | self.object = object; |
27 | self.state = state; |
28 | return self; |
29 | end; |
Called on client side on joinDefinition
readStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
35 | function WoodHarvesterOnDelimbTreeEvent:readStream(streamId, connection) |
36 | self.object = readNetworkNodeObject(streamId); |
37 | self.state = streamReadBool(streamId); |
38 | self:run(connection); |
39 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
45 | function WoodHarvesterOnDelimbTreeEvent:writeStream(streamId, connection) |
46 | writeNetworkNodeObject(streamId, self.object); |
47 | streamWriteBool(streamId, self.state); |
48 | end; |
Run action on receiving sideDefinition
run(integer connection)Arguments
integer | connection | connection |
53 | function 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); |
58 | end; |
Class for animated map objects
Creating animated objectDefinition
onCreate(integer id)Arguments
integer | id | node id |
19 | function 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 |
28 | end |
Creating new instance of animated object classDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | custom metatable |
table | self | new instance of object |
36 | function 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 |
51 | end |
Load animated object attributes from objectDefinition
load(integer nodeId)Arguments
integer | nodeId | id of object to load from |
boolean | success | success |
57 | function 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 |
233 | end |
Load frame values from xmlDefinition
loadFrameValues(integer fileId, string key, integer node)Arguments
integer | fileId | xml file id |
string | key | key |
integer | node | node id |
float | x | x translation |
float | y | y translation |
float | z | z translation |
float | rx | x rotation |
float | ry | y rotation |
float | rz | z rotation |
float | sx | x scale |
float | sy | y scale |
float | sz | z scale |
integer | visibility | visibility |
250 | function 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 |
275 | end |
Delete animated objectDefinition
delete()Code
279 | function 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) |
294 | end |
Called on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
300 | function 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 |
306 | end |
Called on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
312 | function 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 |
317 | end |
Called on client side on updateDefinition
readUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | stream ID |
integer | timestamp | timestamp |
table | connection | connection |
324 | function 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 |
333 | end |
Called on server side on updateDefinition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | stream ID |
table | connection | connection |
integer | dirtyMask | dirty mask |
340 | function 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 |
351 | end |
Loading from attributes and nodesDefinition
loadFromAttributesAndNodes(integer xmlFile, string key)Arguments
integer | xmlFile | id of xml object |
string | key | key |
boolean | success | success |
358 | function 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 |
368 | end |
Get save attributes and nodesDefinition
getSaveAttributesAndNodes()Return Values
string | attributes | attributes |
373 | function AnimatedObject:getSaveAttributesAndNodes() |
374 | local attributes = 'animTime="' .. tostring(self.animation.time) .. '" direction="'..tostring(self.animation.direction)..'"' |
375 | return attributes |
376 | end |
Called on updateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
381 | function 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 |
461 | end |
Called on update tickDefinition
updateTick(float dt)Arguments
float | dt | time since last call in ms |
466 | function 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 |
500 | end |
Set animation timeDefinition
setAnimTime(float t)Arguments
float | t | time |
505 | function 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 |
512 | end |
Set frame valuesDefinition
setFrameValues(integer node, table v)Arguments
integer | node | node id |
table | v | values |
518 | function 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) |
523 | end |
Called on hour changeDefinition
hourChanged()Code
527 | function 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 |
554 | end |
Trigger callbackDefinition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)Arguments
integer | triggerId | id of trigger |
integer | otherId | id of object that calls callback |
boolean | onEnter | called on enter |
boolean | onLeave | called on leave |
boolean | onStay | called on stay |
563 | function 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 |
575 | end |
Class for balesParent
MountableObject
Creating bale objectDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | customMt |
table | instance | Instance of object |
18 | function Bale:new(isServer, isClient, customMt) |
19 | local mt = customMt; |
20 | if mt == nil then |
21 | mt = Bale_mt; |
22 | end; |
23 | |
24 | local self = MountableObject:new(isServer, isClient, mt); |
25 | |
26 | self.forcedClipDistance = 150; |
27 | registerObjectClassName(self, "Bale"); |
28 | |
29 | self.fillType = FillUtil.FILLTYPE_STRAW; |
30 | self.fillLevel = 0; |
31 | self.wrappingState = 0; |
32 | self.baleValueScale = 1; |
33 | self.canBeSold = true |
34 | |
35 | g_currentMission:addLimitedObject(FSBaseMission.LIMITED_OBJECT_TYPE_BALE, self); |
36 | |
37 | return self; |
38 | end; |
Deleting bale objectDefinition
delete()Code
42 | function Bale:delete() |
43 | if self.i3dFilename ~= nil then |
44 | Utils.releaseSharedI3DFile(self.i3dFilename, nil, true); |
45 | end |
46 | g_currentMission:removeLimitedObject(FSBaseMission.LIMITED_OBJECT_TYPE_BALE, self); |
47 | unregisterObjectClassName(self); |
48 | g_currentMission:removeItemToSave(self); |
49 | Bale:superClass().delete(self); |
50 | end; |
Called on client side on updateDefinition
readUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | stream ID |
integer | timestamp | timestamp |
table | connection | connection |
57 | function Bale:readUpdateStream(streamId, timestamp, connection) |
58 | if connection:getIsServer() then |
59 | if self.supportsWrapping then |
60 | self:setWrappingState(streamReadUInt8(streamId)/255); |
61 | end |
62 | end |
63 | Bale:superClass().readUpdateStream(self, streamId, timestamp, connection); |
64 | end; |
Called on server side on updateDefinition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | stream ID |
table | connection | connection |
integer | dirtyMask | dirty mask |
71 | function Bale:writeUpdateStream(streamId, connection, dirtyMask) |
72 | if not connection:getIsServer() then |
73 | if self.supportsWrapping then |
74 | streamWriteUInt8(streamId, Utils.clamp(self.wrappingState*255, 0, 255)); |
75 | end |
76 | end |
77 | Bale:superClass().writeUpdateStream(self, streamId, connection, dirtyMask); |
78 | end; |
Called on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
84 | function Bale:readStream(streamId, connection) |
85 | local i3dFilename = Utils.convertFromNetworkFilename(streamReadString(streamId)); |
86 | if self.nodeId == 0 then |
87 | self:createNode(i3dFilename); |
88 | end; |
89 | self.fillLevel = streamReadFloat32(streamId); |
90 | Bale:superClass().readStream(self, streamId, connection); |
91 | g_currentMission:addItemToSave(self); |
92 | |
93 | self.baleValueScale = streamReadFloat32(streamId); |
94 | if self.supportsWrapping then |
95 | self:setWrappingState(streamReadUInt8(streamId)/255); |
96 | setShaderParameter(self.meshNode, "wrappingState", self.wrappingState, 0, 0, 0, false); |
97 | end |
98 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
104 | function Bale:writeStream(streamId, connection) |
105 | streamWriteString(streamId, Utils.convertToNetworkFilename(self.i3dFilename)); |
106 | streamWriteFloat32(streamId, self.fillLevel); |
107 | Bale:superClass().writeStream(self, streamId, connection); |
108 | |
109 | streamWriteFloat32(streamId, self.baleValueScale); |
110 | |
111 | if self.supportsWrapping then |
112 | streamWriteUInt8(streamId, Utils.clamp(self.wrappingState*255, 0, 255)); |
113 | end |
114 | end; |
Mount bale to objectDefinition
mount(table object, integer node, float x, float y, float z, float rx, float ry, float rz)Arguments
table | object | target object |
integer | node | target node id |
float | x | x position |
float | y | z position |
float | z | z position |
float | rx | rx rotation |
float | ry | ry rotation |
float | rz | rz rotation |
126 | function Bale:mount(object, node, x,y,z, rx,ry,rz) |
127 | g_currentMission:removeItemToSave(self); |
128 | Bale:superClass().mount(self, object, node, x,y,z, rx,ry,rz); |
129 | end; |
Unmount baleDefinition
unmount()Code
133 | function Bale:unmount() |
134 | if Bale:superClass().unmount(self) then |
135 | g_currentMission:addItemToSave(self); |
136 | return true; |
137 | end |
138 | return false; |
139 | end; |
Set node idDefinition
setNodeId(integer nodeId)Arguments
integer | nodeId | node Id |
144 | function Bale:setNodeId(nodeId) |
145 | Bale:superClass().setNodeId(self, nodeId); |
146 | |
147 | local isRoundbale = Utils.getNoNil(getUserAttribute(nodeId, "isRoundbale"), false); |
148 | local defaultFillLevel = 2100*2; |
149 | if isRoundbale then |
150 | defaultFillLevel = 2000*2; |
151 | end |
152 | if getUserAttribute(nodeId, "baleValue") ~= nil then |
153 | print("Warning: bale 'baleValue' is not supported anymore. Use 'baleValueScale' instead and adjust the creating vehicles."); |
154 | end |
155 | local meshIndex = Utils.getNoNil(getUserAttribute(nodeId, "baleMeshIndex"), "1|0"); |
156 | self.meshNode = Utils.indexToObject(nodeId, meshIndex); |
157 | |
158 | self.meshNodes = {self.meshNode} |
159 | |
160 | self.supportsWrapping = Utils.getNoNil(getUserAttribute(nodeId, "supportsWrapping"), false); |
161 | self.fillLevel = defaultFillLevel |
162 | self.baleValueScale = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "baleValueScale")), 1); |
163 | |
164 | self.fillType = FillUtil.FILLTYPE_STRAW; |
165 | local fillTypeStr = getUserAttribute(nodeId, "fillType"); |
166 | if fillTypeStr ~= nil then |
167 | local fillTypeInt = FillUtil.fillTypeNameToInt[fillTypeStr]; |
168 | if fillTypeInt ~= nil then |
169 | self.fillType = fillTypeInt; |
170 | end |
171 | elseif Utils.getNoNil(getUserAttribute(nodeId, "isHaybale"), false) then |
172 | self.fillType = FillUtil.FILLTYPE_DRYGRASS_WINDROW; |
173 | end |
174 | |
175 | local baleWidth = tonumber(getUserAttribute(nodeId, "baleWidth")); |
176 | local baleHeight = tonumber(getUserAttribute(nodeId, "baleHeight")); |
177 | local baleLength = tonumber(getUserAttribute(nodeId, "baleLength")); |
178 | local baleDiameter = tonumber(getUserAttribute(nodeId, "baleDiameter")); |
179 | if baleDiameter ~= nil and baleWidth ~= nil then |
180 | self.baleDiameter = baleDiameter; |
181 | self.baleWidth = baleWidth; |
182 | elseif baleHeight ~= nil and baleWidth ~= nil and baleLength ~= nil then |
183 | self.baleHeight = baleHeight; |
184 | self.baleWidth = baleWidth; |
185 | self.baleLength = baleLength; |
186 | else |
187 | local isRoundbale = Utils.getNoNil(getUserAttribute(nodeId, "isRoundbale"), false); |
188 | if isRoundbale then |
189 | self.baleDiameter = 1.8; |
190 | self.baleWidth = 1.2; |
191 | else |
192 | self.baleHeight = 0.8; |
193 | self.baleWidth = 1.2; |
194 | self.baleLength = 2.4; |
195 | end |
196 | end |
197 | end; |
Load node from i3d fileDefinition
createNode(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
202 | function Bale:createNode(i3dFilename) |
203 | self.i3dFilename = i3dFilename; |
204 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
205 | local baleRoot = Utils.loadSharedI3DFile(i3dFilename); |
206 | |
207 | local baleId = getChildAt(baleRoot, 0); |
208 | link(getRootNode(), baleId); |
209 | delete(baleRoot); |
210 | |
211 | self:setNodeId(baleId); |
212 | end; |
Load baleDefinition
load(string i3dFilename, float x, float y, float z, float rx, float ry, float rz, integer fillLevel)Arguments
string | i3dFilename | i3d file name |
float | x | x world position |
float | y | z world position |
float | z | z world position |
float | rx | rx world rotation |
float | ry | ry world rotation |
float | rz | rz world rotation |
integer | fillLevel | fill level |
224 | function Bale:load(i3dFilename, x,y,z, rx,ry,rz, fillLevel) |
225 | self.i3dFilename = i3dFilename; |
226 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
227 | self:createNode(i3dFilename); |
228 | setTranslation(self.nodeId, x, y, z); |
229 | setRotation(self.nodeId, rx, ry, rz); |
230 | if fillLevel ~= nil then |
231 | self.fillLevel = fillLevel; |
232 | end |
233 | g_currentMission:addItemToSave(self); |
234 | end; |
Setting node id and i3d file nameDefinition
loadFromMemory(integer nodeId, string i3dFilename)Arguments
integer | nodeId | node id |
string | i3dFilename | i3d file name |
240 | function Bale:loadFromMemory(nodeId, i3dFilename) |
241 | self.i3dFilename = i3dFilename; |
242 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename); |
243 | self:setNodeId(nodeId); |
244 | end; |
Loading from attributes and nodesDefinition
loadFromAttributesAndNodes(integer xmlFile, string key, boolean resetVehicles)Arguments
integer | xmlFile | id of xml object |
string | key | key |
boolean | resetVehicles | reset vehicles |
boolean | success | success |
252 | function Bale:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) |
253 | |
254 | local x,y,z = Utils.getVectorFromString(getXMLString(xmlFile, key.."#position")); |
255 | local xRot,yRot,zRot = Utils.getVectorFromString(getXMLString(xmlFile, key.."#rotation")); |
256 | if x == nil or y == nil or z == nil or xRot == nil or yRot == nil or zRot == nil then |
257 | return false; |
258 | end; |
259 | local filename = getXMLString(xmlFile, key.."#filename"); |
260 | if filename == nil then |
261 | return false; |
262 | end; |
263 | filename = Utils.convertFromNetworkFilename(filename); |
264 | local rootNode = Utils.loadSharedI3DFile(filename); |
265 | if rootNode == 0 then |
266 | return false; |
267 | end; |
268 | |
269 | local ret = false; |
270 | local node = getChildAt(rootNode, 0); |
271 | if node ~= nil and node ~= 0 then |
272 | setTranslation(node, x,y,z); |
273 | setRotation(node, xRot,yRot,zRot); |
274 | link(getRootNode(), node); |
275 | ret = true; |
276 | end; |
277 | delete(rootNode); |
278 | if not ret then |
279 | return false; |
280 | end; |
281 | |
282 | self:loadFromMemory(node, filename); |
283 | |
284 | |
285 | local fillLevel = getXMLFloat(xmlFile, key.."#fillLevel"); |
286 | if fillLevel ~= nil then |
287 | self.fillLevel = fillLevel; |
288 | end; |
289 | |
290 | if self.supportsWrapping then |
291 | self.wrappingState = Utils.getNoNil(getXMLFloat(xmlFile, key.."#wrappingState"),0); |
292 | setShaderParameter(self.meshNode, "wrappingState", self.wrappingState, 0, 0, 0, false); |
293 | end; |
294 | |
295 | local baleValueScale = Utils.getNoNil(tonumber(getXMLString(xmlFile, key.."#baleValueScale")), 1); |
296 | if baleValueScale ~= nil then |
297 | self.baleValueScale = baleValueScale; |
298 | end |
299 | |
300 | return true; |
301 | end; |
Get save attributes and nodesDefinition
getSaveAttributesAndNodes(string nodeIdent)Arguments
string | nodeIdent | node ident |
string | attributes | attributes |
string | nodes | nodes |
308 | function Bale:getSaveAttributesAndNodes(nodeIdent) |
309 | |
310 | local x,y,z = getTranslation(self.nodeId); |
311 | local xRot,yRot,zRot = getRotation(self.nodeId); |
312 | local wrapping = ""; |
313 | if self.supportsWrapping then |
314 | wrapping = ' wrappingState="'..tostring(self.wrappingState)..'"'; |
315 | end; |
316 | local attributes = 'filename="'.. Utils.encodeToHTML(Utils.convertToNetworkFilename(self.i3dFilename))..'" position="'..x..' '..y..' '..z..'" rotation="'..xRot..' '..yRot..' '..zRot..'" baleValueScale="'..self.baleValueScale..'" fillLevel="'..self.fillLevel..'"'..wrapping; |
317 | local nodes = ""; |
318 | return attributes, nodes; |
319 | end; |
Get price value of baleDefinition
getValue()Code
323 | function Bale:getValue() |
324 | local pricePerLiter = g_currentMission.economyManager:getPricePerLiter(self.fillType); |
325 | return self.fillLevel * pricePerLiter * self.baleValueScale; |
326 | end; |
Get fill type of baleDefinition
getFillType()Return Values
integer | fillType | current fill type id |
331 | function Bale:getFillType() |
332 | return self.fillType; |
333 | end; |
Get fill level of baleDefinition
getFillLevel()Return Values
integer | fillLevel | current fill level |
338 | function Bale:getFillLevel() |
339 | return self.fillLevel; |
340 | end; |
Set fill level of baleDefinition
setFillLevel(integer fillLevel)Arguments
integer | fillLevel | fill level |
345 | function Bale:setFillLevel(fillLevel) |
346 | self.fillLevel = fillLevel; |
347 | end; |
Set wrapping state of baleDefinition
setWrappingState(boolean wrappingState)Arguments
boolean | wrappingState | new wrapping state |
360 | function Bale:setWrappingState(wrappingState) |
361 | if self.supportsWrapping then |
362 | if self.wrappingState ~= wrappingState then |
363 | self:raiseDirtyFlags(self.physicsObjectDirtyFlag); |
364 | end |
365 | self.wrappingState = wrappingState; |
366 | setShaderParameter(self.meshNode, "wrappingState", self.wrappingState, 0, 0, 0, false); |
367 | end |
368 | end |
Set wrapping state of baleDefinition
getMeshNodes()Return Values
table | meshNodes | mesh nodes |
373 | function Bale:getMeshNodes() |
374 | return self.meshNodes |
375 | end; |
Class for basketballsParent
PhysicsObject
Creating basketballDefinition
onCreate(integer id)Arguments
integer | id | node id |
15 | function 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 |
26 | end |
Creating basketball objectDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | customMt |
table | instance | Instance of object |
34 | function 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 |
46 | end |
Deleting basketball objectDefinition
delete()Code
50 | function 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) |
56 | end |
Called on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
62 | function 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 |
70 | end |
Called on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
76 | function 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 |
81 | end |
Load node from i3d fileDefinition
createNode(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
86 | function 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) |
96 | end |
Load BasketballDefinition
load(string i3dFilename, float x, float y, float z, float rx, float ry, float rz)Arguments
string | i3dFilename | i3d file name |
float | x | x world position |
float | y | z world position |
float | z | z world position |
float | rx | rx world rotation |
float | ry | ry world rotation |
float | rz | rz world rotation |
107 | function 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 |
115 | end; |
Class for bga
Creating bga objectDefinition
onCreate(integer id)Arguments
integer | id | node id |
15 | function 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; |
24 | end; |
Creating bga objectDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | customMt |
table | instance | Instance of object |
32 | function 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; |
67 | end; |
Deleting bga objectDefinition
delete()Code
71 | function 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); |
91 | end; |
Called on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
97 | function 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; |
107 | end; |
Called on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
113 | function 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; |
121 | end; |
Called on client side on updateDefinition
readUpdateStream(integer streamId, integer timestamp, table connection)Arguments
integer | streamId | stream ID |
integer | timestamp | timestamp |
table | connection | connection |
128 | function 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; |
138 | end; |
Called on server side on updateDefinition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)Arguments
integer | streamId | stream ID |
table | connection | connection |
integer | dirtyMask | dirty mask |
145 | function 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; |
153 | end; |
Load bgaDefinition
load(integer nodeId)Arguments
integer | nodeId | node id |
boolean | success | success |
159 | function 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( |