-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFS25_EnhancedVehicle_Event.lua
120 lines (93 loc) · 5.07 KB
/
FS25_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
115
116
117
118
119
120
--
-- Mod: FS25_EnhancedVehicle_Event
--
-- Author: Majo76
-- email: ls (at) majo76 (dot) de
-- @Date: 24.11.2024
-- @Version: 1.0.1.0
local myName = "FS25_EnhancedVehicle_Event"
-- #############################################################################
FS25_EnhancedVehicle_Event = {}
local FS25_EnhancedVehicle_Event_mt = Class(FS25_EnhancedVehicle_Event, Event)
InitEventClass(FS25_EnhancedVehicle_Event, "FS25_EnhancedVehicle_Event")
-- #############################################################################
function FS25_EnhancedVehicle_Event.emptyNew()
if debug > 2 then print("-> " .. myName .. ": emptyNew()") end
local self = Event.new(FS25_EnhancedVehicle_Event_mt)
return self
end
-- #############################################################################
function FS25_EnhancedVehicle_Event.new(vehicle, b1, b2, i1, f1, b3, b4, f2, f3, f4, f5, f6, f7, b5, f8, f9, i2 )
local args = { b1, b2, i1, f1, b3, b4, f2, f3, f4, f5, f6, f7, b5, f8, f9, i2 }
if debug > 2 then print("-> " .. myName .. ": new(): " .. lU:args_to_txt(unpack(args))) end
local self = FS25_EnhancedVehicle_Event.emptyNew()
self.vehicle = vehicle
self.vehicle.vData.want = { unpack(args) }
return self
end
-- #############################################################################
function FS25_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.vehicle.vData.want[14] = streamReadFloat32(streamId);
self.vehicle.vData.want[15] = streamReadFloat32(streamId);
self.vehicle.vData.want[16] = streamReadInt8(streamId);
self:run(connection)
end
-- #############################################################################
function FS25_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])
streamWriteFloat32(streamId, self.vehicle.vData.want[14])
streamWriteFloat32(streamId, self.vehicle.vData.want[15])
streamWriteInt8(streamId, self.vehicle.vData.want[16])
end
-- #############################################################################
function FS25_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(FS25_EnhancedVehicle_Event.new(self.vehicle, unpack(self.vehicle.vData.want)), nil, connection)
end
end
-- #############################################################################
function FS25_EnhancedVehicle_Event.sendEvent(vehicle, b1, b2, i1, f1, b3, b4, f2, f3, f4, f5, f6, f7, b5, f8, f9, i2 )
local args = { b1, b2, i1, f1, b3, b4, f2, f3, f4, f5, f6, f7, b5, f8, f9, i2 }
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(FS25_EnhancedVehicle_Event.new(vehicle, unpack(args)), nil, nil, vehicle)
else
if debug > 1 then print("--> g_client:getServerConnection():sendEvent()") end
g_client:getServerConnection():sendEvent(FS25_EnhancedVehicle_Event.new(vehicle, unpack(args)))
end
end