-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.lua
152 lines (124 loc) · 5.35 KB
/
main.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
local playerPed, playerVehicle, playerDriver, vehicleClass, vehicleModel, surfaceMaterial = nil, nil, nil, nil, nil, nil
local intensityType = type(Config.IntensityMultiplier)
local offroadVehicles = {}
AddEventHandler('onResourceStart', function(resName)
if resourceName == resName then
TriggerServerEvent(serverEvent('requestUpdate'))
end
end)
RegisterNetEvent(clientEvent('receiveUpdate'), function(vehicleList)
offroadVehicles = vehicleList
end)
RegisterNetEvent(clientEvent('toggleDebug'), function()
LocalPlayer.state:set('debuggingOffroad', not LocalPlayer.state['debuggingOffroad'])
end)
RegisterNetEvent(clientEvent('showNotification'), function(message)
Config.Notification(message)
end)
local function getIntensityMultiplier()
if intensityType == "number" then
return Config.IntensityMultiplier or 1.0
end
local roadMultiplier = Config.IntensityMultiplier[surfaceMaterial] or Config.IntensityMultiplier.global or 1.0
local classMultiplier = Config.BypassVehicleClasses[vehicleClass] or 1.0
return roadMultiplier * classMultiplier
end
CreateThread(function()
while true do
Wait(200)
-- Is player in any vehicle?
if IsPedInAnyVehicle(playerPed, false) and playerDriver and not InTable(Config.BypassWheels, GetVehicleWheelType(playerVehicle)) then
if InTable(Config.Roads, surfaceMaterial) then
-- Check if the slippery should go away
if DoesEntityExist(playerVehicle) and Entity(playerVehicle).state['noGrip'] then
Entity(playerVehicle).state:set('noGrip', false)
NetworkRequestControlOfEntity(playerVehicle)
SetVehicleHandlingFloat(playerVehicle, 'CHandlingData', 'fTractionCurveMax',
Entity(playerVehicle).state['defaultCurveMax'])
SetVehicleHandlingFloat(playerVehicle, 'CHandlingData', 'fTractionCurveMin',
Entity(playerVehicle).state['defaultCurveMin'])
SetVehicleHandlingFloat(playerVehicle, 'CHandlingData', 'fLowSpeedTractionLossMult',
Entity(playerVehicle).state['defaultTractionLoss'])
ModifyVehicleTopSpeed(playerVehicle, 1.0)
Wait(100)
else
Wait(500)
end
else
if not (InTable(Config.BypassVehicleClasses, vehicleClass) or InTable(offroadVehicles, vehicleModel)) and DoesEntityExist(playerVehicle) and
not Entity(playerVehicle).state['noGrip'] then
-- Make grip go away!
NetworkRequestControlOfEntity(playerVehicle)
local defaultCurveMax = GetVehicleHandlingFloat(playerVehicle, 'CHandlingData', 'fTractionCurveMax')
local defaultCurveMin = GetVehicleHandlingFloat(playerVehicle, 'CHandlingData', 'fTractionCurveMin')
local defaultTractionLoss = GetVehicleHandlingFloat(playerVehicle, 'CHandlingData', 'fLowSpeedTractionLossMult')
Entity(playerVehicle).state:set('defaultCurveMax', defaultCurveMax)
Entity(playerVehicle).state:set('defaultCurveMin', defaultCurveMin)
Entity(playerVehicle).state:set('defaultTractionLoss', defaultTractionLoss)
local invensityMultiplier = getIntensityMultiplier()
SetVehicleHandlingFloat(playerVehicle, 'CHandlingData', 'fTractionCurveMax',
defaultCurveMax - (1.2 * invensityMultiplier))
SetVehicleHandlingFloat(playerVehicle, 'CHandlingData', 'fTractionCurveMin',
defaultCurveMin - (1.1 * invensityMultiplier))
SetVehicleHandlingFloat(playerVehicle, 'CHandlingData', 'fLowSpeedTractionLossMult',
defaultTractionLoss + (1.0 * invensityMultiplier))
ModifyVehicleTopSpeed(playerVehicle, 1.0)
Entity(playerVehicle).state:set('noGrip', true)
Wait(100)
else
-- Do not apply effect, let thread sleep
Wait(500)
end
end
else
-- Let thread sleep.
Wait(500)
end
end
end)
CreateThread(function()
while true do
Wait(1500)
playerPed = PlayerPedId()
playerVehicle = GetVehiclePedIsIn(playerPed, false)
playerDriver = (playerVehicle and playerVehicle ~= 0) and GetPedInVehicleSeat(playerVehicle, -1) == playerPed or nil
vehicleModel = (playerVehicle and playerVehicle ~= 0) and GetEntityModel(playerVehicle) or nil
vehicleClass = (playerVehicle and playerVehicle ~= 0) and GetVehicleClass(playerVehicle) or nil
surfaceMaterial = (playerVehicle and playerVehicle ~= 0) and GetVehicleWheelSurfaceMaterial(playerVehicle, 1) or nil
end
end)
CreateThread(function()
while true do
Wait(0)
if LocalPlayer.state['debuggingOffroad'] then
playerVehicle = GetVehiclePedIsIn(playerPed, false)
surfaceMaterial = (playerVehicle and playerVehicle ~= 0) and GetVehicleWheelSurfaceMaterial(playerVehicle, 1) or
nil
if playerVehicle and surfaceMaterial then
SetTextScale(0.65, 0.65)
SetTextFont(4)
SetTextCentre(true)
SetTextColour(255, 255, 255, 200)
AddTextEntry('debuggingOffroad', ('Currently ' ..
(InTable(Config.Roads, surfaceMaterial) and 'ON' or 'OFF') ..
' road, type: ' ..
surfaceMaterial .. ', effect: ' .. tostring(Entity(playerVehicle).state['noGrip'] and 'ON' or 'OFF') .. ', intensity (multiplier): ' .. getIntensityMultiplier()))
BeginTextCommandDisplayText('debuggingOffroad')
EndTextCommandDisplayText(0.5, 0.85)
end
else
Wait(5000)
end
end
end)
TriggerEvent('chat:addSuggestion', '/offroad',
Config.Language.command_usage, {
{
name = "action",
help = Config.EnableSQL and
Config.Language.command_param_action_sql or
Config.Language.command_param_action_nosql
},
Config.EnableSQL and
{ name = "comment", help = Config.Language.command_param_comment } or nil
})