-
Notifications
You must be signed in to change notification settings - Fork 6
/
client.lua
177 lines (158 loc) · 4.93 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
local showingWarning = false
local lastSpeed = 0
local lastVelocity = vector3(0, 0, 0)
local newbieBeep = true
local showHelp = false
local activated
local hasSeatbelt
RegisterKeyMapping('seatbelt', 'Seatbelt', 'keyboard', Constants.DefaultKeybind)
RegisterFrameworkCommand('seatbelt', function()
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
local vehcileHasSeatbelt, strong = DoesPedVehicleHaveSeatbelt(ped)
if vehcileHasSeatbelt and not strong then
if activated then
DeactivateSeatbelt()
else
ActivateSeatbelt()
end
SendNuiMessage('{"t":0,"d":' .. (activated == true and '1' or '0') .. '}')
end
end
end)
function ActivateSeatbelt()
if activated == true then
return error('seatbelt attempted to activate when already active.')
end
-- compat for other resources like carhud
TriggerEvent('seatbelt:stateChange', true)
-- disable exit keys
Citizen.CreateThread(function()
while activated do
Citizen.Wait(1)
DisableControlAction(0, 75, true)
DisableControlAction(27, 75, true)
end
end)
-- quick unbuckled
Citizen.CreateThread(function()
while activated do
Citizen.Wait(1)
if IsDisabledControlJustPressed(0, 75) and IsControlPressed(0, 21) then
DeactivateSeatbelt()
end
end
end)
-- validation
Citizen.CreateThread(function()
while activated do
if not IsPedInAnyVehicle(PlayerPedId()) then
DeactivateSeatbelt()
end
Citizen.Wait(50)
end
end)
activated = true
end
function DeactivateSeatbelt()
if activated == false then
return error('seatbelt attempted to deactivate when already deactivated.')
end
TriggerEvent('seatbelt:stateChange', false)
-- help text separate from hud
Citizen.CreateThread(function()
while not activated do
if showHelp then
local message = '~BLIP_GANG_VEHICLE~ Press ~INPUT_REPLAY_SHOWHOTKEY~ to ~y~buckle~s~ your seatbelt.'
ShowHelpText(message, newbieBeep)
newbieBeep = false
for _ = 0, 8 do
Citizen.Wait(5)
ShowHelpText(message, false)
end
end
Citizen.Wait(65)
end
end)
-- handling and HUD
Citizen.CreateThread(function()
while not activated do
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
local _hasSeatbelt, strong = DoesPedVehicleHaveSeatbelt(ped)
hasSeatbelt = _hasSeatbelt
if hasSeatbelt and not strong then
local vehicle = GetVehiclePedIsIn(ped)
local speed = GetEntitySpeed(vehicle)
if speed > (50 / 3.6) and (lastSpeed - speed) > (speed * .2) then
local coords = GetEntityCoords(ped)
local fw = Fwv(ped)
ForceStopWarning()
showHelp = false
SetEntityCoords(ped, coords.x + fw.x, coords.y + fw.y, coords.z - .47, true, true, true)
SetEntityVelocity(ped, lastVelocity.x, lastVelocity.y, lastVelocity.z)
SetPedToRagdoll(ped, 1e3, 1e3, 0, false, false, false)
elseif speed > (20 / 3.6) then
SetWarning(true)
showHelp = not (IsPauseMenuActive() or IsHudHidden() or IsPlayerDead(PlayerId()))
else
SetWarning(false)
showHelp = false
end
lastSpeed = speed
lastVelocity = GetEntityVelocity(vehicle)
end
else
ForceStopWarning()
showHelp = false
end
Citizen.Wait(50)
end
SetWarning(false)
showHelp = false
end)
-- notification
Citizen.CreateThread(function()
while not activated do
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn(ped)
if IsPedInAnyVehicle(ped) and hasSeatbelt and GetEntitySpeed(vehicle) * 3.6 > 10 then
TriggerServerEvent('seatbelt:ServerNotify')
end
Citizen.Wait(3e3)
end
end)
activated = false
end
function SetWarning(bool)
if bool ~= showingWarning then
SendNuiMessage('{"t":1,"d":' .. (bool == true and '1' or '0') .. '}')
showingWarning = bool
end
end
function ForceStopWarning()
if showingWarning then
SendNuiMessage('{"t":1,"d":3}')
showingWarning = false
end
end
RegisterNetEvent('seatbelt:ClientNotify', function(serverId)
local ped = PlayerPedId()
local player = GetPlayerFromServerId(serverId) -- onesync notice: returns -1 if not loaded
local playerPed = GetPlayerPed(player)
if player ~= PlayerId() and player > 0 and IsLEO() and not IsHudHidden() and IsPedInAnyVehicle(playerPed) then
local vehicle = GetVehiclePedIsIn(playerPed)
local identifier = GetPlayerIdentifier_(serverId, playerPed, vehicle)
if #(GetEntityCoords(ped) - GetEntityCoords(GetPlayerPed(player))) < Constants.Distance and identifier then
ShowNotification(
identifier ..
' is not weaing a seatbelt in <C>~y~' ..
GetVehicleNumberPlateText(vehicle) ..
'~s~</C>.'
)
end
end
end)
Citizen.CreateThread(function()
DeactivateSeatbelt()
end)