forked from Dukefarming/FS25-lua-scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicleBundleAttachEvent.lua
More file actions
69 lines (52 loc) · 2.19 KB
/
VehicleBundleAttachEvent.lua
File metadata and controls
69 lines (52 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---Event for bundle attaching
local VehicleBundleAttachEvent_mt = Class(VehicleBundleAttachEvent, Event)
---Create instance of Event class
-- @return table self instance of class event
function VehicleBundleAttachEvent.emptyNew()
local self = Event.new(VehicleBundleAttachEvent_mt)
return self
end
---Create new instance of event
-- @param table bundles bundles
-- @return table instance instance of event
function VehicleBundleAttachEvent.new(bundles)
local self = VehicleBundleAttachEvent.emptyNew()
self.bundles = bundles
return self
end
---Called on client side on join
-- @param integer streamId streamId
-- @param integer connection connection
function VehicleBundleAttachEvent:readStream(streamId, connection)
local numBundles = streamReadUInt8(streamId)
for _=1, numBundles do
local v1 = NetworkUtil.readNodeObjectId(streamId)
local v2 = NetworkUtil.readNodeObjectId(streamId)
local inputJointIndex = streamReadUIntN(streamId, 7)
local jointIndex = streamReadUIntN(streamId, 7)
table.insert(g_currentMission.vehicleSystem.vehiclesToAttach, {v1id=v1, v2id=v2, inputJointIndex=inputJointIndex, jointIndex=jointIndex})
end
end
---Called on server side on join
-- @param integer streamId streamId
-- @param integer connection connection
function VehicleBundleAttachEvent:writeStream(streamId, connection)
streamWriteUInt8(streamId, #self.bundles)
for i=1, #self.bundles do
local bundle = self.bundles[i]
NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(bundle.v1))
NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(bundle.v2))
streamWriteUIntN(streamId, bundle.input, 7)
streamWriteUIntN(streamId, bundle.attacher, 7)
end
end
---Run action on receiving side
-- @param integer connection connection
function VehicleBundleAttachEvent:run(connection)
if self.object ~= nil and self.object:getIsSynchronized() then
self.object:attachImplement(self.implement, self.inputJointIndex, self.jointIndex, true, nil, self.startLowered)
end
if not connection:getIsServer() then
g_server:broadcastEvent(self, nil, connection, self.object)
end
end