LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

ChainsawStateEvent

Description
Event for chainsaw state
Parent
Event
Functions

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function ChainsawStateEvent:emptyNew()
15 local self = Event:new(ChainsawStateEvent_mt)
16 return self
17end

new

Description
Create new instance of event
Definition
new(table player, boolean isCutting, boolean isHorizontalCut)
Arguments
tableplayerplayer
booleanisCuttingis cutting
booleanisHorizontalCutis horizontal cutting
Return Values
tableinstanceinstance of event
Code
25function ChainsawStateEvent:new(player, isCutting, isHorizontalCut, hasBeencut)
26 local self = ChainsawStateEvent:emptyNew()
27 self.player = player
28 self.isCutting = isCutting
29 self.isHorizontalCut = isHorizontalCut
30 self.hasBeenCut = hasBeencut
31 return self
32end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
38function ChainsawStateEvent:readStream(streamId, connection)
39 self.player = NetworkUtil.readNodeObject(streamId)
40 self.isCutting = streamReadBool(streamId)
41 self.isHorizontalCut = streamReadBool(streamId)
42 self.hasBeenCut = streamReadBool(streamId)
43 self:run(connection)
44end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
60function ChainsawStateEvent:run(connection)
61 if not connection:getIsServer() then
62 g_server:broadcastEvent(self, false, connection, self.player)
63 end
64
65 local currentTool = self.player.baseInformation.currentHandtool
66 if currentTool ~= nil and currentTool.setCutting ~= nil then
67 currentTool:setCutting(self.isCutting, self.isHorizontalCut, self.hasBeenCut, true)
68 end
69end

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 player, boolean isCutting, boolean isHorizontalCut, boolean noEventSend)
Arguments
tableplayerplayer
booleanisCuttingis cutting
booleanisHorizontalCutis horizontal cutting
booleannoEventSendno event send
Code
77function ChainsawStateEvent.sendEvent(player, isCutting, isHorizontalCut, hasBeenCut, noEventSend)
78 local currentTool = player.baseInformation.currentHandtool
79 if currentTool ~= nil and currentTool.setCutting ~= nil and (currentTool.isCutting ~= isCutting or currentTool.hasBeenCut ~= hasBeenCut) then
80 if noEventSend == nil or noEventSend == false then
81 if g_server ~= nil then
82 g_server:broadcastEvent(ChainsawStateEvent:new(player, isCutting, isHorizontalCut, hasBeenCut), nil, nil, player)
83 else
84 g_client:getServerConnection():sendEvent(ChainsawStateEvent:new(player, isCutting, isHorizontalCut, hasBeenCut))
85 end
86 end
87 end
88end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
50function ChainsawStateEvent:writeStream(streamId, connection)
51 NetworkUtil.writeNodeObject(streamId, self.player)
52 streamWriteBool(streamId, self.isCutting)
53 streamWriteBool(streamId, self.isHorizontalCut)
54 streamWriteBool(streamId, self.hasBeenCut)
55end