forked from chopo156/Seatbelt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
149 lines (127 loc) · 4.58 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
--- "Ramsus" ---
local isUiOpen = false
local speedBuffer = {}
local velBuffer = {}
local SeatbeltON = false
local InVehicle = false
function Notify(string)
SetNotificationTextEntry("STRING")
AddTextComponentString(string)
DrawNotification(false, true)
end
AddEventHandler('seatbelt:sounds', function(soundFile, soundVolume)
SendNUIMessage({
transactionType = 'playSound',
transactionFile = soundFile,
transactionVolume = soundVolume
})
end)
function IsCar(veh)
local vc = GetVehicleClass(veh)
return (vc >= 0 and vc <= 7) or (vc >= 9 and vc <= 12) or (vc >= 17 and vc <= 20)
end
function Fwv(entity)
local hr = GetEntityHeading(entity) + 90.0
if hr < 0.0 then hr = 360.0 + hr end
hr = hr * 0.0174533
return { x = math.cos(hr) * 2.0, y = math.sin(hr) * 2.0 }
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = PlayerPedId()
local car = GetVehiclePedIsIn(ped)
if car ~= 0 and (InVehicle or IsCar(car)) then
InVehicle = true
if isUiOpen == false and not IsPlayerDead(PlayerId()) then
if Config.Blinker then
SendNUIMessage({displayWindow = 'true'})
end
isUiOpen = true
end
if SeatbeltON then
DisableControlAction(0, 75, true) -- Disable exit vehicle when stop
DisableControlAction(27, 75, true) -- Disable exit vehicle when Driving
end
speedBuffer[2] = speedBuffer[1]
speedBuffer[1] = GetEntitySpeed(car)
if not SeatbeltON and speedBuffer[2] ~= nil and GetEntitySpeedVector(car, true).y > 1.0 and speedBuffer[1] > (Config.Speed / 3.6) and (speedBuffer[2] - speedBuffer[1]) > (speedBuffer[1] * 0.255) then
local co = GetEntityCoords(ped)
local fw = Fwv(ped)
SetEntityCoords(ped, co.x + fw.x, co.y + fw.y, co.z - 0.47, true, true, true)
SetEntityVelocity(ped, velBuffer[2].x, velBuffer[2].y, velBuffer[2].z)
Citizen.Wait(1)
SetPedToRagdoll(ped, 1000, 1000, 0, 0, 0, 0)
end
velBuffer[2] = velBuffer[1]
velBuffer[1] = GetEntityVelocity(car)
if IsControlJustReleased(0, Config.Control) and GetLastInputMethod(0) then
SeatbeltON = not SeatbeltON
if SeatbeltON then
Citizen.Wait(1)
if Config.Sounds then
TriggerEvent("seatbelt:sounds", "buckle", Config.Volume)
end
if Config.Notification then
Notify(Config.Strings.seatbelt_on)
end
if Config.Blinker then
SendNUIMessage({displayWindow = 'false'})
end
isUiOpen = true
else
if Config.Notification then
Notify(Config.Strings.seatbelt_off)
end
if Config.Sounds then
TriggerEvent("seatbelt:sounds", "unbuckle", Config.Volume)
end
if Config.Blinker then
SendNUIMessage({displayWindow = 'true'})
end
isUiOpen = true
end
end
elseif InVehicle then
InVehicle = false
SeatbeltON = false
speedBuffer[1], speedBuffer[2] = 0.0, 0.0
if isUiOpen == true and not IsPlayerDead(PlayerId()) then
if Config.Blinker then
SendNUIMessage({displayWindow = 'false'})
end
isUiOpen = false
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
local Vehicle = GetVehiclePedIsIn(GetPlayerPed(-1), false)
local VehSpeed = GetEntitySpeed(Vehicle) * 3.6
if Config.AlarmOnlySpeed and VehSpeed > Config.AlarmSpeed then
ShowWindow = true
else
ShowWindow = false
SendNUIMessage({displayWindow = 'false'})
end
if IsPlayerDead(PlayerId()) or IsPauseMenuActive() then
if isUiOpen == true then
SendNUIMessage({displayWindow = 'false'})
end
elseif not SeatbeltON and InVehicle and not IsPauseMenuActive() and not IsPlayerDead(PlayerId()) and Config.Blinker then
if Config.AlarmOnlySpeed and ShowWindow and VehSpeed > Config.AlarmSpeed then
SendNUIMessage({displayWindow = 'true'})
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(3500)
if not SeatbeltON and InVehicle and not IsPauseMenuActive() and Config.LoopSound and ShowWindow then
TriggerEvent("seatbelt:sounds", "seatbelt", Config.Volume)
end
end
end)