This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathFS22_EnhancedVehicle_Event.lua
114 lines (87 loc) · 4.66 KB
/
FS22_EnhancedVehicle_Event.lua
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
--
-- Mod: FS22_EnhancedVehicle_Event
--
-- Author: Majo76
-- email: [email protected]
-- @Date: 11.01.2022
-- @Version: 1.1.3.0
local myName = "FS22_EnhancedVehicle_Event"
-- #############################################################################
FS22_EnhancedVehicle_Event = {}
local FS22_EnhancedVehicle_Event_mt = Class(FS22_EnhancedVehicle_Event, Event)
InitEventClass(FS22_EnhancedVehicle_Event, "FS22_EnhancedVehicle_Event")
-- #############################################################################
function FS22_EnhancedVehicle_Event.emptyNew()
if debug > 2 then print("-> " .. myName .. ": emptyNew()") end
local self = Event.new(FS22_EnhancedVehicle_Event_mt)
return self
end
-- #############################################################################
function FS22_EnhancedVehicle_Event.new(vehicle, b1, b2, i1, f1, b3, b4, f2, f3, f4, f5, f6, f7, b5 )
local args = { b1, b2, i1, f1, b3, b4, f2, f3, f4, f5, f6, f7, b5 }
if debug > 2 then print("-> " .. myName .. ": new(): " .. lU:args_to_txt(unpack(args))) end
local self = FS22_EnhancedVehicle_Event.emptyNew()
self.vehicle = vehicle
self.vehicle.vData.want = { unpack(args) }
return self
end
-- #############################################################################
function FS22_EnhancedVehicle_Event:readStream(streamId, connection)
if debug > 1 then print("-> " .. myName .. ": readStream() - " .. streamId) end
self.vehicle = NetworkUtil.readNodeObject(streamId);
self.vehicle.vData.want[1] = streamReadBool(streamId);
self.vehicle.vData.want[2] = streamReadBool(streamId);
self.vehicle.vData.want[3] = streamReadInt8(streamId);
self.vehicle.vData.want[4] = streamReadFloat32(streamId);
self.vehicle.vData.want[5] = streamReadBool(streamId);
self.vehicle.vData.want[6] = streamReadBool(streamId);
self.vehicle.vData.want[7] = streamReadFloat32(streamId);
self.vehicle.vData.want[8] = streamReadFloat32(streamId);
self.vehicle.vData.want[9] = streamReadFloat32(streamId);
self.vehicle.vData.want[10] = streamReadFloat32(streamId);
self.vehicle.vData.want[11] = streamReadFloat32(streamId);
self.vehicle.vData.want[12] = streamReadFloat32(streamId);
self.vehicle.vData.want[13] = streamReadBool(streamId);
self:run(connection)
end
-- #############################################################################
function FS22_EnhancedVehicle_Event:writeStream(streamId, connection)
if debug > 1 then print("-> " .. myName .. ": writeStream() - " .. streamId) end
NetworkUtil.writeNodeObject(streamId, self.vehicle);
streamWriteBool(streamId, self.vehicle.vData.want[1])
streamWriteBool(streamId, self.vehicle.vData.want[2])
streamWriteInt8(streamId, self.vehicle.vData.want[3])
streamWriteFloat32(streamId, self.vehicle.vData.want[4])
streamWriteBool(streamId, self.vehicle.vData.want[5])
streamWriteBool(streamId, self.vehicle.vData.want[6])
streamWriteFloat32(streamId, self.vehicle.vData.want[7])
streamWriteFloat32(streamId, self.vehicle.vData.want[8])
streamWriteFloat32(streamId, self.vehicle.vData.want[9])
streamWriteFloat32(streamId, self.vehicle.vData.want[10])
streamWriteFloat32(streamId, self.vehicle.vData.want[11])
streamWriteFloat32(streamId, self.vehicle.vData.want[12])
streamWriteBool(streamId, self.vehicle.vData.want[13])
end
-- #############################################################################
function FS22_EnhancedVehicle_Event:run(connection)
if debug > 1 then print("-> " .. myName .. ": run()") end
if g_server == nil then
self.vehicle.vData.is = { unpack(self.vehicle.vData.want) }
end
if debug > 1 then print("--> " .. self.vehicle.rootNode .. " - (" .. lU:args_to_txt(unpack(self.vehicle.vData.is)).."|"..lU:args_to_txt(unpack(self.vehicle.vData.want))..")") end
if not connection:getIsServer() then
g_server:broadcastEvent(FS22_EnhancedVehicle_Event.new(self.vehicle, unpack(self.vehicle.vData.want)), nil, connection)
end
end
-- #############################################################################
function FS22_EnhancedVehicle_Event.sendEvent(vehicle, b1, b2, i1, f1, b3, b4, f2, f3, f4, f5, f6, f7, b5 )
local args = { b1, b2, i1, f1, b3, b4, f2, f3, f4, f5, f6, f7, b5 }
if debug > 1 then print("-> " .. myName .. ": sendEvent(): " .. lU:args_to_txt(unpack(args))) end
if g_server ~= nil then
if debug > 1 then print("--> g_server:broadcastEvent()") end
g_server:broadcastEvent(FS22_EnhancedVehicle_Event.new(vehicle, unpack(args)), nil, nil, vehicle)
else
if debug > 1 then print("--> g_client:getServerConnection():sendEvent()") end
g_client:getServerConnection():sendEvent(FS22_EnhancedVehicle_Event.new(vehicle, unpack(args)))
end
end