-
Notifications
You must be signed in to change notification settings - Fork 11
/
client.lua
231 lines (221 loc) · 6.87 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
local customturbo = {}
local turboboost = {}
AddStateBagChangeHandler('turbo' --[[key filter]], nil --[[bag filter]], function(bagName, key, value, _unused, replicated)
Wait(500)
if not value then return end
local vehicle = GetEntityFromStateBagName(bagName)
if DoesEntityExist(vehicle) and value.turbo then
local ent = Entity(vehicle).state
local plate = GetVehicleNumberPlateText(vehicle)
customturbo[plate] = value
local weightadded = Config.turbos[value.turbo].weight
local weight = GetVehicleHandlingInt(vehicle,'CHandlingData', 'fMass')
if turboboost[plate] ~= value.turbo then
turboboost[plate] = value.turbo
SetVehicleHandlingInt(vehicle , "CHandlingData", "fMass", tonumber(weight)*weightadded)
end
if GetPedInVehicleSeat(vehicle,-1) == PlayerPedId() then
StartTurboLoop(plate,vehicle)
end
end
end)
invehicle = false
AddEventHandler('gameEventTriggered', function (name, args)
if name == 'CEventNetworkPlayerEnteredVehicle' then
if args[1] == PlayerId() then
local plate = GetVehicleNumberPlateText(args[2])
if customturbo[plate] and DoesEntityExist(args[2]) and GetPedInVehicleSeat(args[2],-1) == PlayerPedId() then
Wait(3000)
StartTurboLoop(plate,args[2])
end
end
end
end)
local exportboost = 1.0
exports('BoostPerGear', function(percent)
exportboost = percent
end)
local manualgear = false
local switchgear = false
AddStateBagChangeHandler('gearshift' --[[key filter]], nil --[[bag filter]], function(bagName, key, value, _unused, replicated) -- sync gear shifting and other vehicle stats
Wait(0)
if not value then return end
local vehicle = GetEntityFromStateBagName(bagName)
if not DoesEntityExist(vehicle) then return end
if DoesEntityExist(vehicle) and GetPedInVehicleSeat(vehicle,-1) == PlayerPedId() then
switchgear = true
manualgear = value.gear
end
end)
local boosted = false
StartTurboLoop = function(plate,vehicle)
if boosted then return end
if invehicle then return end
local vehicle = vehicle
SendNUIMessage({
show = true
})
if customturbo[plate] then
boosted = true
print("Turbo Loop")
invehicle = true
local turbo = Config.turbos[customturbo[plate].turbo]
local default = {fDriveInertia = GetVehicleHandlingFloat(vehicle , "CHandlingData","fDriveInertia"), fInitialDriveForce = GetVehicleHandlingFloat(vehicle , "CHandlingData","fInitialDriveForce")}
ToggleVehicleMod(vehicle,18,true)
local sound = false
local soundofnitro = nil
local customized = false
local boost = 0
local oldgear = 1
local cd = 0
local rpm = GetVehicleCurrentRpm(vehicle)
gear = GetVehicleCurrentGear(vehicle)
local maxvol = 0.4
local ent = Entity(vehicle).state
local maxtorque = turbo.Torque
local lastorque = 0
local torque = 0
local ped = PlayerPedId()
Citizen.CreateThreadNow(function()
while IsPedInAnyVehicle(ped) do
SendNUIMessage({
type = "turbo",
max = maxtorque * exportboost,
boost = torque * exportboost
})
Wait(25)
end
end)
while customturbo[plate] ~= nil and customturbo[plate].turbo ~= 'Default' and IsPedInAnyVehicle(ped) do
local durability = (ent.turbo?.durability or 100.0) / 100
local throttle = GetControlNormal(0,71)
turbo = Config.turbos[customturbo[plate].turbo]
boost = 0
rpm = GetVehicleCurrentRpm(vehicle)
local powercurve = (turbo.Power * (1 + (rpm*2)))
SendNUIMessage({
type = "turbo",
max = maxtorque,
boost = 0.0
})
torque = 0
while GetControlNormal(0,71) > 0.1 do
local throttle = GetControlNormal(0,71)
rpm = GetVehicleCurrentRpm(vehicle)
if boost <= maxtorque and turbo.rpmboost <= rpm then
local powercurve = (turbo.Power * (rpm / turbo.lag))
boost = maxtorque >= boost and (boost + powercurve) or maxtorque
elseif turbo.rpmboost >= rpm then
local powercurve = (turbo.Power * (rpm / (turbo.lag * 10)))
boost = maxtorque > boost and (boost + powercurve) or maxtorque
end
cd = cd + 10
gear = manualgear or GetVehicleCurrentGear(vehicle)
SetVehicleTurboPressure(vehicle , boost)
local power = (GetVehicleTurboPressure(vehicle) * (rpm < 0.8 and 0.5+rpm or rpm+0.2) * exportboost) * durability
if ent.nitroenable then
power = power + ent.nitropower
end
torque = boost
SetVehicleCheatPowerIncrease(vehicle,(power < 1.0 and 1.0 or power) * GetControlNormal(0,71))
if not sound then
StopSound(soundofnitro)
ReleaseSoundId(soundofnitro)
soundofnitro = PlaySoundFromEntity(GetSoundId(), "Flare", vehicle , "DLC_HEISTS_BIOLAB_FINALE_SOUNDS", 0, 0)
sound = true
end
if (torque / maxtorque) > 0.1 and GetControlNormal(0,71) < 0.5 or (torque / maxtorque) > 0.2 and gear ~= oldgear then
StopSound(soundofnitro)
ReleaseSoundId(soundofnitro)
if customturbo[plate].turbo == 'Ultimate' then
SetVehicleBoostActive(vehicle,1,0)
end
sound = false
if oldgear ~= gear then
oldgear = gear
lastorque = torque
end
local data = {
file = customturbo[plate].turbo,
volume = maxvol * (torque / maxtorque),
coord = GetEntityCoords(PlayerPedId()),
boost = exportboost
}
ent:set('bov', data, true)
switchgear = false
cd = 0
boost = 0
Wait(101)
end
Wait(5)
end
if (lastorque / maxtorque) > 0.1 and GetControlNormal(0,71) < 0.5 then
StopSound(soundofnitro)
ReleaseSoundId(soundofnitro)
sound = false
local data = {
file = customturbo[plate].turbo,
volume = maxvol * (boost / maxtorque),
coord = GetEntityCoords(PlayerPedId()),
boost = exportboost,
ts = math.random(1,99)
}
if GetVehicleTurboPressure(vehicle)+0.1 >= maxtorque and cd >= 1000 then
ent:set('bov', data, true)
cd = 0
torque = 0
SendNUIMessage({
type = "turbo",
max = maxtorque,
boost = 0.0
})
end
boost = 0
oldgear = gear
end
boost = 0
vehicle = GetVehiclePedIsIn(PlayerPedId())
if customturbo[plate].turbo == 'Default' then
break
end
turbo = Config.turbos[customturbo[plate].turbo]
if vehicle == 0 then
break
end
Wait(500)
customized = true
end
invehicle = false
boosted = false
manualgear = false
SendNUIMessage({
show = false
})
if customized then
Wait(1000)
end
end
end
AddStateBagChangeHandler('bov' --[[key filter]], nil --[[bag filter]], function(bagName, key, value, _unused, replicated)
Wait(0)
if not value then return end
if replicated then return end
local entity = GetEntityFromStateBagName(bagName)
if DoesEntityExist(entity) then
local volume = value.volume
local mycoord = GetEntityCoords(PlayerPedId())
local distIs = tonumber(string.format("%.1f", #(mycoord - value['coord'])))
if (distIs <= 30) then
distPerc = distIs / 30
volume = (1-distPerc) * value.volume
local data = {
file = value['file'],
volume = volume
}
SendNUIMessage({
type = "playsound",
content = data
})
end
end
end)