This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
forked from brzys/bengines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine_s.lua
339 lines (289 loc) · 5.81 KB
/
engine_s.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
ENGINE_DATA = {
-- heavy vehicles
["Truck"] = {
["6.0"] = {
idleRPM=600,
maxRPM=4000,
soundPack="truck3",
fuel="diesel",
},
["7.0"] = {
idleRPM=600,
maxRPM=4000,
soundPack="truck2",
fuel="diesel",
},
["8.0"] = {
idleRPM=600,
maxRPM=4000,
soundPack="truck1",
fuel="diesel",
},
},
["Bus"] = {
["3.0"] = {
idleRPM=600,
maxRPM=3000,
soundPack="bus1",
fuel="diesel",
shiftDownRPM=800,
shiftUpRPM=2500,
},
["4.0"] = {
idleRPM=700,
maxRPM=4000,
soundPack="bus2",
fuel="diesel",
shiftDownRPM=1300,
shiftUpRPM=3300,
},
},
-- motorcycles
["Motorbike"] = {
["0.5"] = { -- 1.0
idleRPM=700,
maxRPM=7000,
soundPack="motorbike1",
fuel="petrol",
},
["0.6"] = { -- 1.4
idleRPM=700,
maxRPM=8000,
soundPack="motorbike5",
fuel="petrol",
},
["0.7"] = { -- 1.5
idleRPM=700,
maxRPM=8000,
soundPack="motorbike4",
fuel="petrol",
},
["0.8"] = { -- 2.0
idleRPM=700,
maxRPM=8000,
soundPack="motorbike2",
fuel="petrol",
},
["0.9"] = { -- 3.0
idleRPM=700,
maxRPM=8000,
soundPack="motorbike3",
fuel="petrol",
},
},
-- casual vehicles
["Casual"] = {
["1.5"] = {
idleRPM=700,
maxRPM=6000,
soundPack="casual6",
fuel="petrol",
},
["1.6"] = {
idleRPM=900,
maxRPM=6000,
soundPack="muscle2",
fuel="petrol",
},
["1.7"] = {
idleRPM=900,
maxRPM=6000,
soundPack="casual1",
fuel="petrol",
},
["1.8"] = {
idleRPM=900,
maxRPM=6800,
soundPack="casual4",
fuel="petrol",
},
["1.9"] = {
idleRPM=900,
maxRPM=6800,
soundPack="casual2",
fuel="petrol",
},
["2.0"] = {
idleRPM=900,
maxRPM=6800,
soundPack="casual5",
fuel="petrol",
},
["2.1"] = {
idleRPM=900,
maxRPM=7500,
soundPack="casual7",
fuel="petrol",
},
["2.2"] = {
idleRPM=900,
maxRPM=7500,
soundPack="casual7",
fuel="diesel",
},
},
-- muscle vehicles
["Muscle"] = {
["2.0"] = {
idleRPM=700,
maxRPM=6500,
soundPack="muscle1",
fuel="diesel",
},
["2.5"] = {
idleRPM=700,
maxRPM=6500,
soundPack="muscle2",
fuel="diesel",
},
["3.0"] = {
idleRPM=1000,
maxRPM=7000,
soundPack="muscle3",
fuel="diesel",
},
["3.5"] = {
idleRPM=1000,
maxRPM=7000,
soundPack="muscle4",
fuel="diesel",
},
},
-- sport vehicles
["Sport"] = {
["3.0"] = {
idleRPM=900,
maxRPM=8000,
soundPack="sport7",
fuel="diesel",
},
["3.3"] = {
idleRPM=900,
maxRPM=8000,
soundPack="sport1",
fuel="diesel",
},
["3.5"] = {
idleRPM=900,
maxRPM=8000,
soundPack="sport5",
fuel="diesel",
},
["3.6"] = {
idleRPM=900,
maxRPM=8000,
soundPack="sport9",
fuel="diesel",
},
["3.9"] = {
idleRPM=900,
maxRPM=8000,
soundPack="sport8",
fuel="diesel",
},
["4.2"] = {
idleRPM=900,
maxRPM=8000,
soundPack="sport4",
fuel="diesel",
},
["4.5"] = {
idleRPM=900,
maxRPM=8000,
soundPack="sport2",
fuel="diesel",
},
["5.0"] = {
idleRPM=900,
maxRPM=8000,
soundPack="sport3",
fuel="diesel",
},
}
}
-- override default engines
VEHICLE_ENGINES = {
-- bikes
[463] = "0.6", -- harley
[581] = "0.8", -- bf-400
[523] = "0.9", -- sapd
-- casual
[414] = "1.2", -- mule
-- sport
[596] = "2.0", -- police LS
[598] = "3.9",
}
-- soundpack volume boosting
SOUNDPACK_VOLUME = {
["motorbike2"] = 1.5,
["motorbike3"] = 1.5,
["motorbike4"] = 1.5,
["motorbike5"] = 2,
}
function calculateVehicleEngine(vehicle)
local model = getElementModel(vehicle)
local type = getElementData(vehicle, "vehicle:type")
if VEHICLE_ENGINES[model] then
return VEHICLE_ENGINES[model]
end
if ENGINE_DATA[type] then
local engines = {}
for name, data in pairs(ENGINE_DATA[type]) do
table.insert(engines, {name, data})
end
table.sort(engines, function(a, b)
return a[1] < b[1]
end)
local class = math.floor((calculateVehicleClass(vehicle) / calculateVehicleClass(getBestVehicleClassByType(type))) * #engines)
if type == "Sport" then
class = class-2
end
class = math.max(1, math.min(class, #engines))
return engines[class][1] -- name of engine
end
return false
end
function addVehicleEngine(vehicle)
local data = calculateVehicleEngine(vehicle)
local type = getElementData(vehicle, "vehicle:type")
local model = getElementModel(vehicle)
if data then
local upgrades = getElementData(vehicle, "vehicle:upgrades") or {engine={turbo=false}}
local engine = ENGINE_DATA[type][data]
engine.name = data
engine.volMult = SOUNDPACK_VOLUME[engine.soundPack] or 1
engine.turbo = upgrades.engine and upgrades.engine.turbo or false
engine.turbo_shifts = engine.turbo
setElementData(vehicle, "vehicle:engine", engine)
setElementData(vehicle, "vehicle:fuel_type", engine.fuel)
-- refresh for players nearby
local x, y, z = getElementPosition(vehicle)
local col = createColSphere(x, y, z, 20)
for k, v in ipairs(getElementsWithinColShape(col, "player")) do
triggerClientEvent(v, "onClientRefreshEngineSounds", v)
end
destroyElement(col)
end
end
function onResourceStart()
for k, v in ipairs(getElementsByType("vehicle")) do
local type = getElementData(v, "vehicle:type")
if not type then
type = getVehicleTypeByModel(getElementModel(v))
setElementData(v, "vehicle:type", type)
end
addVehicleEngine(v)
end
end
addEventHandler("onResourceStart", resourceRoot, onResourceStart)
function onVehicleEnter(player, seat, jacked)
if seat == 0 then
local type = getElementData(source, "vehicle:type")
if not type then
type = getVehicleTypeByModel(getElementModel(source))
setElementData(source, "vehicle:type", type)
end
addVehicleEngine(source)
end
end
addEventHandler("onVehicleEnter", root, onVehicleEnter)