LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

VehicleAttachEvent

Description
Event for attaching
Parent
Event
Functions

emptyNew

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

new

Description
Create new instance of event
Definition
new(table vehicle, table implement, integer inputJointIndex, integer jointIndex, boolean startLowered)
Arguments
tablevehiclevehicle
tableimplementimplement
integerinputJointIndexindex of input attacher joint
integerjointIndexindex of attacher joint
booleanstartLoweredstart in lowered state
Return Values
tableinstanceinstance of event
Code
27function VehicleAttachEvent.new(vehicle, implement, inputJointIndex, jointIndex, startLowered)
28 local self = VehicleAttachEvent.emptyNew()
29 self.jointIndex = jointIndex
30 self.inputJointIndex = inputJointIndex
31 self.vehicle = vehicle
32 self.implement = implement
33 self.startLowered = startLowered
34 assert(self.jointIndex >= 0 and self.jointIndex < 127)
35 return self
36end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function VehicleAttachEvent:readStream(streamId, connection)
43 self.vehicle = NetworkUtil.readNodeObject(streamId)
44 self.implement = NetworkUtil.readNodeObject(streamId)
45 self.jointIndex = streamReadUIntN(streamId, 7)
46 self.inputJointIndex = streamReadUIntN(streamId, 7)
47 self.startLowered = streamReadBool(streamId)
48 self:run(connection)
49end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
66function VehicleAttachEvent:run(connection)
67 if self.vehicle ~= nil and self.vehicle:getIsSynchronized() then
68 if self.implement == nil then
69 Logging.error("Failed to attach unknown implement to vehicle '%s' between joints '%d' and '%d'", self.vehicle.configFileName, self.jointIndex, self.inputJointIndex)
70 return
71 end
72
73 self.vehicle:attachImplement(self.implement, self.inputJointIndex, self.jointIndex, true, nil, self.startLowered)
74 end
75 if not connection:getIsServer() then
76 g_server:broadcastEvent(self, nil, connection, self.object)
77 end
78end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
55function VehicleAttachEvent:writeStream(streamId, connection)
56 NetworkUtil.writeNodeObject(streamId, self.vehicle)
57 NetworkUtil.writeNodeObject(streamId, self.implement)
58 streamWriteUIntN(streamId, self.jointIndex, 7)
59 streamWriteUIntN(streamId, self.inputJointIndex, 7)
60 streamWriteBool(streamId, self.startLowered)
61end