forked from HugoSimoes12345/HRSGears
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
411 lines (374 loc) · 14.7 KB
/
client.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
local hg = {
vehicle = nil,
numgears = nil,
topspeedGTA = nil,
topspeedms = nil,
acc = nil,
hash = nil,
selectedgear = 0,
hbrake = nil,
manualon = false,
currspeedlimit = nil,
ready = false,
realistic = false
}
function Status()
-- Export function
return hg
end
local function resetvehicle()
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fInitialDriveForce", hg.acc)
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fInitialDriveMaxFlatVel",hg.topspeedGTA)
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fHandBrakeForce", hg.hbrake)
SetVehicleHighGear(hg.vehicle, hg.numgears)
ModifyVehicleTopSpeed(hg.vehicle,1)
--SetVehicleMaxSpeed(vehicle,topspeedms)
SetVehicleHandbrake(hg.vehicle, false)
hg.vehicle = nil
hg.numgears = nil
hg.topspeedGTA = nil
hg.topspeedms = nil
hg.acc = nil
hg.hash = nil
hg.hbrake = nil
hg.selectedgear = 0
hg.currspeedlimit = nil
hg.ready = false
end
local function SimulateGears()
local engineup = GetVehicleMod(hg.vehicle,11)
if hg.selectedgear > 0 then
local ratio
if Config.vehicles[hg.hash] ~= nil then
if hg.selectedgear ~= 0 and hg.selectedgear ~= nil then
if hg.numgears ~= nil and hg.selectedgear ~= nil then
ratio = Config.vehicles[hg.hash][hg.numgears][hg.selectedgear] * (1/0.9)
else
ratio = Config.gears[hg.numgears][hg.selectedgear] * (1/0.9)
end
end
else
if hg.selectedgear ~= 0 and hg.selectedgear ~= nil then
if hg.numgears ~= nil and hg.selectedgear ~= nil then
ratio = Config.gears[hg.numgears][hg.selectedgear] * (1/0.9)
end
end
end
if ratio ~= nil then
SetVehicleHighGear(hg.vehicle,1)
local newacc = ratio * hg.acc
local newtopspeedGTA = hg.topspeedGTA / ratio
local newtopspeedms = hg.topspeedms / ratio
--if GetEntitySpeed(vehicle) > newtopspeedms then
--selectedgear = selectedgear + 1
--else
SetVehicleHandbrake(hg.vehicle, false)
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fInitialDriveForce", newacc)
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fInitialDriveMaxFlatVel", newtopspeedGTA)
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fHandBrakeForce", hg.hbrake)
ModifyVehicleTopSpeed(hg.vehicle,1)
--SetVehicleMaxSpeed(vehicle,newtopspeedms)
hg.currspeedlimit = newtopspeedms
--end
end
elseif hg.selectedgear == 0 then
--SetVehicleHandlingFloat(vehicle, "CHandlingData", "fInitialDriveMaxFlatVel", 0.0)
elseif hg.selectedgear == -1 then
--if GetEntitySpeedVector(vehicle,true).y > 0.1 then
--selectedgear = selectedgear + 1
--else
SetVehicleHandbrake(hg.vehicle, false)
SetVehicleHighGear(hg.vehicle,hg.numgears)
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fInitialDriveForce", hg.acc)
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fInitialDriveMaxFlatVel", hg.topspeedGTA)
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fHandBrakeForce", hg.hbrake)
ModifyVehicleTopSpeed(hg.vehicle,1)
--SetVehicleMaxSpeed(vehicle,topspeedms)
--end
end
SetVehicleMod(hg.vehicle,11,engineup,false)
end
RegisterNetEvent("HRSGears:manual", function()
hg.manualon = not hg.manualon
end)
RegisterNetEvent("HRSGears:manualmode", function()
if hg.manualon then
hg.realistic = not hg.realistic
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(100)
local ped = PlayerPedId()
local newveh = GetVehiclePedIsIn(ped,false)
local class = GetVehicleClass(newveh)
if newveh == hg.vehicle then
elseif newveh == 0 and hg.vehicle ~= nil then
resetvehicle()
else
if GetPedInVehicleSeat(newveh,-1) == ped then
if class ~= 13 and class ~= 14 and class ~= 15 and class ~= 16 and class ~= 21 then
hg.vehicle = newveh
hg.hash = GetEntityModel(newveh)
if GetVehicleMod(hg.vehicle,13) < 0 then
hg.numgears = GetVehicleHandlingInt(newveh, "CHandlingData", "nInitialDriveGears")
else
hg.numgears = GetVehicleHandlingInt(newveh, "CHandlingData", "nInitialDriveGears") + 1
end
hg.hbrake = GetVehicleHandlingFloat(newveh, "CHandlingData", "fHandBrakeForce")
hg.topspeedGTA = GetVehicleHandlingFloat(newveh, "CHandlingData", "fInitialDriveMaxFlatVel")
hg.topspeedms = (hg.topspeedGTA * 1.32)/3.6
hg.acc = GetVehicleHandlingFloat(newveh, "CHandlingData", "fInitialDriveForce")
--SetVehicleMaxSpeed(newveh,topspeedms)
hg.selectedgear = 0
Citizen.Wait(50)
hg.ready = true
end
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if hg.manualon == true and hg.vehicle ~= nil then
DisableControlAction(0, 80, true)
DisableControlAction(0, 21, true)
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if hg.manualon == true and hg.vehicle ~= nil then
if hg.vehicle ~= nil then
-- Shift up and down
if hg.ready == true then
if IsDisabledControlJustPressed(0, 21) then
if hg.selectedgear <= hg.numgears - 1 then
DisableControlAction(0, 71, true)
Wait(300)
hg.selectedgear = hg.selectedgear + 1
DisableControlAction(0, 71, false)
SimulateGears()
end
elseif IsDisabledControlJustPressed(0, 80) then
if hg.selectedgear > -1 then
DisableControlAction(0, 71, true)
Wait(300)
hg.selectedgear = hg.selectedgear - 1
DisableControlAction(0, 71, false)
SimulateGears()
end
end
end
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if hg.manualon == true and hg.vehicle ~= nil then
if hg.selectedgear == -1 then
if GetVehicleCurrentGear(hg.vehicle) == 1 then
DisableControlAction(0, 71, true)
end
elseif hg.selectedgear > 0 then
if GetEntitySpeedVector(hg.vehicle,true).y < 0.0 then
DisableControlAction(0, 72, true)
end
elseif hg.selectedgear == 0 then
SetVehicleHandbrake(hg.vehicle, true)
if IsControlPressed(0, 76) == false then
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fHandBrakeForce", 0.0)
else
SetVehicleHandlingFloat(hg.vehicle, "CHandlingData", "fHandBrakeForce", hg.hbrake)
end
end
else
Citizen.Wait(100)
end
end
end)
local disable = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if hg.realistic == true then
if hg.manualon == true and hg.vehicle ~= nil then
if hg.selectedgear > 1 then
if IsControlPressed(0,71) then
local speed = GetEntitySpeed(hg.vehicle)
local minspeed = hg.currspeedlimit / 7
if speed < minspeed then
if GetVehicleCurrentRpm(hg.vehicle) < 0.4 then
disable = true
end
end
end
end
else
Citizen.Wait(100)
end
else
Citizen.Wait(100)
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if disable == true then
SetVehicleEngineOn(hg.vehicle,false,true,false)
Citizen.Wait(1000)
disable = false
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if hg.vehicle ~= nil and hg.selectedgear ~= 0 then
local speed = GetEntitySpeed(hg.vehicle)
if hg.currspeedlimit ~= nil then
if speed >= hg.currspeedlimit then
if Config.enginebrake == true then
if speed / hg.currspeedlimit > 1.1 then
--print('dead')
local hhhh = speed / hg.currspeedlimit
SetVehicleCurrentRpm(hg.vehicle,hhhh)
SetVehicleCheatPowerIncrease(hg.vehicle,-100.0)
--SetVehicleBurnout(vehicle,true)
else
--SetVehicleBurnout(vehicle,false)
SetVehicleCheatPowerIncrease(hg.vehicle,0.0)
end
else
SetVehicleCheatPowerIncrease(hg.vehicle,0.0)
end
--SetVehicleHandbrake(vehicle, true)
--if IsControlPressed(0, 76) == false then
--SetVehicleHandlingFloat(vehicle, "CHandlingData", "fHandBrakeForce", 0.0)
-- else
--SetVehicleHandlingFloat(vehicle, "CHandlingData", "fHandBrakeForce", hbrake)
--end
else
--SetVehicleHandbrake(vehicle, false)
--if IsControlPressed(0, 76) == false then
--else
--SetVehicleHandbrake(vehicle, true)
--SetVehicleHandlingFloat(vehicle, "CHandlingData", "fHandBrakeForce", hbrake)
--end
end
else
if speed >= hg.topspeedms then
SetVehicleCheatPowerIncrease(hg.vehicle,0.0)
--SetVehicleHandbrake(vehicle, true)
--if IsControlPressed(0, 76) == false then
--SetVehicleHandlingFloat(vehicle, "CHandlingData", "fHandBrakeForce", 0.0)
--else
--SetVehicleHandlingFloat(vehicle, "CHandlingData", "fHandBrakeForce", hbrake)
--end
else
--SetVehicleHandbrake(vehicle, false)
--if IsControlPressed(0, 76) == false then
--else
--SetVehicleHandbrake(vehicle, true)
--SetVehicleHandlingFloat(vehicle, "CHandlingData", "fHandBrakeForce", hbrake)
--end
end
end
end
end
end)
---------------debug
local function getinfo(gea)
if gea == 0 then
return "N"
elseif gea == -1 then
return "R"
else
return gea
end
end
local function round(value, numDecimalPlaces)
if numDecimalPlaces then
local power = 10^numDecimalPlaces
return math.floor((value * power) + 0.5) / (power)
else
return math.floor(value + 0.5)
end
end
Citizen.CreateThread(function()
Citizen.Wait(100)
if Config.gearhud == 1 then
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if hg.manualon == true and hg.vehicle ~= nil then
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.0, 0.3)
SetTextColour(128, 128, 128, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString("~r~Gear: ~w~"..getinfo(hg.selectedgear))
DrawText(0.015, 0.78)
else
Citizen.Wait(100)
end
end
end)
elseif Config.gearhud == 2 then
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if hg.manualon == true and hg.vehicle ~= nil then
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.0, 0.3)
SetTextColour(128, 128, 128, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString("~r~Gear: ~w~"..getinfo(hg.selectedgear).." ~r~Km/h: ~w~"..round((GetEntitySpeed(hg.vehicle)*3.6),0).." ~r~RPM: ~w~"..round(GetVehicleCurrentRpm(hg.vehicle),2))
DrawText(0.015, 0.78)
else
Citizen.Wait(100)
end
end
end)
end
end)
Citizen.CreateThread(function()
local should_draw = Config.gearhud == 1 or Config.gearhud == 2
while should_draw do
Citizen.Wait(0)
--if manualon == true and vehicle ~= nil then
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.0, 0.2)
SetTextColour(128, 128, 128, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
if hg.manualon == true then
if hg.realistic == false then
AddTextComponentString("~r~HRSGears: ~g~On ~r~Mode: ~g~Arcade")
else
AddTextComponentString("~r~HRSGears: ~g~On ~r~Mode: ~g~Realistic")
end
else
AddTextComponentString("~r~HRSGears: ~w~Off")
end
DrawText(0.95, 0.005)
end
end)