Skip to main content
Skip to main content

TramlineMapSetEvent

TramlineMapSetEvent

Description

Event for syncing the tramline settings from client to server

Parent

Event

Functions

emptyNew

Description

Create instance of Event class

Definition

emptyNew()

Return Values

anyselfinstance of class event

Code

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

new

Description

Create new instance of event

Definition

new(table object, , , , )

Arguments

tableobjectobject
anyworkingWidth
anyworkDirection
anyspacing
anyclearFruit

Code

function TramlineMapSetEvent.new(farmlandId, workingWidth, workDirection, spacing, clearFruit)
local self = TramlineMapSetEvent.emptyNew()
self.farmlandId = farmlandId
self.workingWidth = workingWidth
self.workDirection = workDirection
self.spacing = spacing
self.clearFruit = clearFruit

return self
end

readStream

Description

Called on client side on join

Definition

readStream(integer streamId, Connection connection)

Arguments

integerstreamIdstreamId
Connectionconnectionconnection

Code

function TramlineMapSetEvent:readStream(streamId, connection)
self.farmlandId = streamReadUIntN(streamId, g_farmlandManager.numberOfBits)
self.workingWidth = streamReadFloat32(streamId)
self.workDirection = streamReadFloat32(streamId)
self.spacing = streamReadFloat32(streamId)
self.clearFruit = streamReadBool(streamId)

self:run(connection)
end

run

Description

Run action on receiving side

Definition

run(Connection connection)

Arguments

Connectionconnectionconnection

Code

function TramlineMapSetEvent:run(connection)
if not connection:getIsServer() then
g_server:broadcastEvent( self , false , connection, nil )
end

if g_precisionFarming ~ = nil then
if g_precisionFarming.tramlineMap ~ = nil then
g_precisionFarming.tramlineMap:setFarmlandTramlines( self.farmlandId, self.workingWidth, self.workDirection, self.spacing, self.clearFruit, true )
end
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 object, boolean noEventSend, , , , )

Arguments

tableobjectobject
booleannoEventSendno event send
anyworkDirection
anyspacing
anyclearFruit
anynoEventSend

Code

function TramlineMapSetEvent.sendEvent(farmlandId, workingWidth, workDirection, spacing, clearFruit, noEventSend)
if noEventSend = = nil or noEventSend = = false then
if g_server ~ = nil then
g_server:broadcastEvent( TramlineMapSetEvent.new(farmlandId, workingWidth, workDirection, spacing, clearFruit), nil , nil , nil )
else
g_client:getServerConnection():sendEvent( TramlineMapSetEvent.new(farmlandId, workingWidth, workDirection, spacing, clearFruit))
end
end
end

writeStream

Description

Called on server side on join

Definition

writeStream(integer streamId, Connection connection)

Arguments

integerstreamIdstreamId
Connectionconnectionconnection

Code

function TramlineMapSetEvent:writeStream(streamId, connection)
streamWriteUIntN(streamId, self.farmlandId, g_farmlandManager.numberOfBits)
streamWriteFloat32(streamId, self.workingWidth)
streamWriteFloat32(streamId, self.workDirection)
streamWriteFloat32(streamId, self.spacing)
streamWriteBool(streamId, self.clearFruit)
end