LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

ExtendedSowingMachineRateEvent

Description
Event for sync of seed rate
Parent
Event
Functions

emptyNew

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

new

Description
Create new instance of event
Definition
new(table object, bool automaticMode, integer manualValue)
Arguments
tableobjectobject
boolautomaticModeautomaticMode
integermanualValuemanualValue
Code
23function ExtendedSowingMachineRateEvent.new(object, automaticMode, manualValue)
24 local self = ExtendedSowingMachineRateEvent:emptyNew()
25 self.object = object
26 self.automaticMode = automaticMode
27 self.manualValue = manualValue
28 return self
29end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function ExtendedSowingMachineRateEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId)
37 self.automaticMode = streamReadBool(streamId)
38 if not self.automaticMode then
39 self.manualValue = streamReadUIntN(streamId, 2)
40 end
41
42 self:run(connection)
43end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
59function ExtendedSowingMachineRateEvent:run(connection)
60 if not connection:getIsServer() then
61 g_server:broadcastEvent(self, false, connection, self.object)
62 end
63
64 if self.object ~= nil and self.object:getIsSynchronized() then
65 self.object:setSeedRateAutoMode(self.automaticMode, true)
66 if not self.automaticMode then
67 self.object:setManualSeedRate(self.manualValue, true)
68 end
69 end
70end

sendEvent

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

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
49function ExtendedSowingMachineRateEvent:writeStream(streamId, connection)
50 NetworkUtil.writeNodeObject(streamId, self.object)
51 if not streamWriteBool(streamId, self.automaticMode) then
52 streamWriteUIntN(streamId, self.manualValue, 2)
53 end
54end