-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
100 lines (86 loc) · 3.73 KB
/
client.lua
File metadata and controls
100 lines (86 loc) · 3.73 KB
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
local QBCore = exports['qb-core']:GetCoreObject()
local isPolice = false
local uiEnabled = true
local active = false
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(job)
isPolice = (job.name == 'police')
end)
AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() == resourceName then
local PlayerData = QBCore.Functions.GetPlayerData()
if PlayerData and PlayerData.job and PlayerData.job.name == 'police' then isPolice = true end
end
end)
RegisterCommand('dashcam', function()
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn(ped, false)
if not isPolice then
QBCore.Functions.Notify("Bu sistem sadece emniyet birimlerine tahsis edilmiştir.", "error")
return
end
if vehicle == 0 or GetVehicleClass(vehicle) ~= 18 then
QBCore.Functions.Notify("Dashcam arayüzünü sadece polis aracındayken yönetebilirsiniz.", "error")
return
end
uiEnabled = not uiEnabled
if not uiEnabled and active then
active = false
SendNUIMessage({type = "close"})
end
local status = uiEnabled and "Sistem aktif edildi." or "Sistem kapatıldı."
QBCore.Functions.Notify(status, "primary")
end)
Citizen.CreateThread(function()
while true do
local sleep = 1000
local ped = PlayerPedId()
if isPolice and uiEnabled and IsPedInAnyVehicle(ped, false) then
local vehicle = GetVehiclePedIsIn(ped, false)
if vehicle ~= 0 and GetPedInVehicleSeat(vehicle, -1) == ped and GetVehicleClass(vehicle) == 18 then
sleep = 400
if not active then
active = true
SendNUIMessage({type = "open"})
end
local target = GetVehicleInFront(vehicle)
if target ~= 0 then
local plate = GetVehicleNumberPlateText(target)
local speed = math.floor(GetEntitySpeed(target) * 3.6)
local model = GetLabelText(GetDisplayNameFromVehicleModel(GetEntityModel(target)))
local driverDisplayName = "Bilinmiyor"
local driverPed = GetPedInVehicleSeat(target, -1)
if driverPed ~= 0 then
local serverId = GetPlayerServerId(NetworkGetPlayerIndexFromPed(driverPed))
if serverId > 0 then
QBCore.Functions.TriggerCallback('tox_dashcam:getDriverName', function(name)
driverDisplayName = name
end, serverId)
end
end
SendNUIMessage({
type = "update",
plate = plate,
speed = speed,
model = model,
driver = driverDisplayName
})
else
SendNUIMessage({type = "reset"})
end
else
if active then active = false SendNUIMessage({type = "close"}) end
end
else
if active then active = false SendNUIMessage({type = "close"}) end
sleep = 1500
end
Citizen.Wait(sleep)
end
end)
function GetVehicleInFront(veh)
local coords = GetEntityCoords(veh)
local offset = GetOffsetFromEntityInWorldCoords(veh, 0.0, 20.0, 0.0)
local ray = StartShapeTestCapsule(coords.x, coords.y, coords.z, offset.x, offset.y, offset.z, 1.2, 10, veh, 7)
local _, _, _, _, vehicle = GetShapeTestResult(ray)
return vehicle
end