LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

BalerAutomaticDropEvent

Description
Event for balers to sync automatic drop state
Parent
Event
Functions

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
13function BalerAutomaticDropEvent.emptyNew()
14 return Event.new(BalerAutomaticDropEvent_mt)
15end

new

Description
Create new instance of event
Definition
new(table object, boolean automaticDrop)
Arguments
tableobjectobject
booleanautomaticDropautomaticDrop
Code
21function BalerAutomaticDropEvent.new(object, automaticDrop)
22 local self = BalerAutomaticDropEvent.emptyNew()
23 self.object = object
24 self.automaticDrop = automaticDrop
25 return self
26end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
32function BalerAutomaticDropEvent:readStream(streamId, connection)
33 self.object = NetworkUtil.readNodeObject(streamId)
34 self.automaticDrop = streamReadBool(streamId)
35 self:run(connection)
36end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
50function BalerAutomaticDropEvent:run(connection)
51 if not connection:getIsServer() then
52 g_server:broadcastEvent(self, false, connection, self.object)
53 end
54
55 if self.object ~= nil and self.object:getIsSynchronized() then
56 self.object:setBalerAutomaticDrop(self.automaticDrop, true)
57 end
58end

sendEvent

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

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function BalerAutomaticDropEvent:writeStream(streamId, connection)
43 NetworkUtil.writeNodeObject(streamId, self.object)
44 streamWriteBool(streamId, self.automaticDrop)
45end