forked from Dukefarming/FS25-lua-scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicleAttachRequestEvent.lua
More file actions
63 lines (46 loc) · 2.04 KB
/
VehicleAttachRequestEvent.lua
File metadata and controls
63 lines (46 loc) · 2.04 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
---Event for request attaching
local VehicleAttachRequestEvent_mt = Class(VehicleAttachRequestEvent, Event)
---Create instance of Event class
-- @return table self instance of class event
function VehicleAttachRequestEvent.emptyNew()
return Event.new(VehicleAttachRequestEvent_mt)
end
---Create new instance of event
-- @param table info attach info [attacherVehicle, attachable, attacherVehicleJointDescIndex, attachableJointDescIndex]
-- @return table instance instance of event
function VehicleAttachRequestEvent.new(info)
local self = VehicleAttachRequestEvent.emptyNew()
self.attacherVehicle = info.attacherVehicle
self.attachable = info.attachable
self.attacherVehicleJointDescIndex = info.attacherVehicleJointDescIndex
self.attachableJointDescIndex = info.attachableJointDescIndex
return self
end
---Called on client side on join
-- @param integer streamId streamId
-- @param integer connection connection
function VehicleAttachRequestEvent:readStream(streamId, connection)
self.attacherVehicle = NetworkUtil.readNodeObject(streamId)
self.attachable = NetworkUtil.readNodeObject(streamId)
self.attacherVehicleJointDescIndex = streamReadUIntN(streamId, 7)
self.attachableJointDescIndex = streamReadUIntN(streamId, 7)
self:run(connection)
end
---Called on server side on join
-- @param integer streamId streamId
-- @param integer connection connection
function VehicleAttachRequestEvent:writeStream(streamId, connection)
NetworkUtil.writeNodeObject(streamId, self.attacherVehicle)
NetworkUtil.writeNodeObject(streamId, self.attachable)
streamWriteUIntN(streamId, self.attacherVehicleJointDescIndex, 7)
streamWriteUIntN(streamId, self.attachableJointDescIndex, 7)
end
---Run action on receiving side
-- @param integer connection connection
function VehicleAttachRequestEvent:run(connection)
if not connection:getIsServer() then
if self.attacherVehicle ~= nil and self.attacherVehicle:getIsSynchronized() then
self.attacherVehicle:attachImplementFromInfo(self)
end
end
end