Skip to main content
Skip to main content

TensionBeltsEvent

TensionBeltsEvent

Description

Event for tension belts state

Parent

Event

Functions

emptyNew

Description

Create instance of Event class

Definition

emptyNew()

Return Values

anyselfinstance of class event

Code

function TensionBeltsEvent.emptyNew()
local self = Event.new( TensionBeltsEvent _mt)
return self
end

new

Description

Create new instance of event

Definition

new(table object, boolean isActive, integer beltId)

Arguments

tableobjectobject
booleanisActivebelt is active
integerbeltIdid of belt

Code

function TensionBeltsEvent.new(object, isActive, beltId)
local self = TensionBeltsEvent.emptyNew()
self.object = object
self.isActive = isActive
self.beltId = beltId
return self
end

readStream

Description

Called on client side on join

Definition

readStream(integer streamId, Connection connection)

Arguments

integerstreamIdstreamId
Connectionconnectionconnection

Code

function TensionBeltsEvent:readStream(streamId, connection)
self.object = NetworkUtil.readNodeObject(streamId)
if not streamReadBool(streamId) then
self.beltId = streamReadUIntN(streamId, TensionBelts.NUM_SEND_BITS) + 1
end
self.isActive = streamReadBool(streamId)
self:run(connection)
end

run

Description

Run action on receiving side

Definition

run(Connection connection)

Arguments

Connectionconnectionconnection

Code

function TensionBeltsEvent:run(connection)
if not connection:getIsServer() then
g_server:broadcastEvent( self , false , connection, self.object)
end

if self.object ~ = nil and self.object:getIsSynchronized() then
self.object:setTensionBeltsActive( self.isActive, self.beltId, true )
end
end

sendEvent

Description

Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients

Definition

sendEvent(table vehicle, boolean isActive, integer beltId, boolean noEventSend)

Arguments

tablevehiclevehicle
booleanisActivebelt is active
integerbeltIdid of belt
booleannoEventSendno event send

Code

function TensionBeltsEvent.sendEvent(vehicle, isActive, beltId, noEventSend)
if noEventSend = = nil or noEventSend = = false then
if g_server ~ = nil then
g_server:broadcastEvent( TensionBeltsEvent.new(vehicle, isActive, beltId), nil , nil , vehicle)
else
g_client:getServerConnection():sendEvent( TensionBeltsEvent.new(vehicle, isActive, beltId))
end
end
end

writeStream

Description

Called on server side on join

Definition

writeStream(integer streamId, Connection connection)

Arguments

integerstreamIdstreamId
Connectionconnectionconnection

Code

function TensionBeltsEvent:writeStream(streamId, connection)
NetworkUtil.writeNodeObject(streamId, self.object)
streamWriteBool(streamId, self.beltId = = nil )
if self.beltId ~ = nil then
streamWriteUIntN(streamId, self.beltId - 1 , TensionBelts.NUM_SEND_BITS)
end
streamWriteBool(streamId, self.isActive)
end