LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

PlaceableLightsStateEvent

Description
Event for toggeling placeable light state
Parent
Event
Functions

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function PlaceableLightsStateEvent.emptyNew()
15 return Event.new(PlaceableLightsStateEvent_mt)
16end

new

Description
Create new instance of event
Definition
new(table object, integer groupIndex, boolean isActive)
Arguments
tableobjectobject
integergroupIndexindex of group
booleanisActiveis active
Code
23function PlaceableLightsStateEvent.new(placeable, groupIndex, isActive)
24 local self = PlaceableLightsStateEvent.emptyNew()
25 self.placeable = placeable
26 self.groupIndex = groupIndex
27 self.isActive = isActive
28 return self
29end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function PlaceableLightsStateEvent:readStream(streamId, connection)
36 self.placeable = NetworkUtil.readNodeObject(streamId)
37 self.groupIndex = streamReadUIntN(streamId, PlaceableLights.MAX_NUM_BITS)
38 self.isActive = streamReadBool(streamId)
39 self:run(connection)
40end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
55function PlaceableLightsStateEvent:run(connection)
56 if not connection:getIsServer() then
57 g_server:broadcastEvent(self, false, connection, self.placeable)
58 end
59
60 if self.placeable ~= nil and self.placeable:getIsSynchronized() and self.placeable.setGroupIsActive ~= nil then
61 self.placeable:setGroupIsActive(self.groupIndex, self.isActive, true)
62 end
63end

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 lightSystem, integer groupIndex, boolean isActive)
Arguments
tablelightSystemlightSystem object
integergroupIndexindex of group
booleanisActiveis active
Code
70function PlaceableLightsStateEvent.sendEvent(placeable, groupIndex, isActive, noEventSend)
71 if noEventSend == nil or noEventSend == false then
72 if g_server ~= nil then
73 g_server:broadcastEvent(PlaceableLightsStateEvent.new(placeable, groupIndex, isActive), nil, nil, placeable)
74 else
75 g_client:getServerConnection():sendEvent(PlaceableLightsStateEvent.new(placeable, groupIndex, isActive))
76 end
77 end
78end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
46function PlaceableLightsStateEvent:writeStream(streamId, connection)
47 NetworkUtil.writeNodeObject(streamId, self.placeable)
48 streamWriteUIntN(streamId, self.groupIndex, PlaceableLights.MAX_NUM_BITS)
49 streamWriteBool(streamId, self.isActive)
50end