-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.lua
More file actions
85 lines (72 loc) · 2.75 KB
/
Copy pathclient.lua
File metadata and controls
85 lines (72 loc) · 2.75 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
ESX = nil
local cooldown = {}
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
function isOfficer()
local playerData = ESX.GetPlayerData()
return playerData.job.name == 'police' or playerData.job.name == 'fbi'
end
function isInVehicle()
local ped = PlayerPedId()
return IsPedInAnyVehicle(ped, false)
end
function getNearestVehicle()
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local vehicles = ESX.Game.GetVehiclesInArea(pos, 50.0)
local closestVehicle = nil
local minDist = 1000
for _, vehicle in ipairs(vehicles) do
local dist = #(pos - GetEntityCoords(vehicle))
if dist < minDist and vehicle ~= GetVehiclePedIsIn(ped, false) then
minDist = dist
closestVehicle = vehicle
end
end
return closestVehicle, minDist
end
RegisterCommand('engineblock', function()
if isOfficer() and isInVehicle() then
local playerId = GetPlayerServerId(PlayerId())
if cooldown[playerId] and (GetGameTimer() - cooldown[playerId]) < 1200000 then
ESX.ShowNotification("You need to wait before using this again.")
return
end
local nearestVehicle, dist = getNearestVehicle()
if nearestVehicle and dist < 50.0 then
local speed = GetEntitySpeed(nearestVehicle) * 3.6
ESX.ShowNotification(string.format("Nearest vehicle speed: %.2f km/h", speed))
local driver = GetPedInVehicleSeat(nearestVehicle, -1)
if driver ~= 0 then
TriggerServerEvent('blockEngine', GetPlayerServerId(NetworkGetEntityOwner(driver)), NetworkGetNetworkIdFromEntity(nearestVehicle))
cooldown[playerId] = GetGameTimer()
end
else
ESX.ShowNotification("No vehicle nearby.")
end
else
ESX.ShowNotification("You need to be a police or fbi officer in a vehicle.")
end
end, false)
RegisterKeyMapping('engineblock', 'Block Engine', 'keyboard', 'B')
RegisterNetEvent('engineBlocked')
AddEventHandler('engineBlocked', function(vehicleNetId)
local vehicle = NetToVeh(vehicleNetId)
SetVehicleEngineOn(vehicle, false, true, true)
ESX.ShowNotification("Your engine has been blocked by an officer.")
Citizen.Wait(10000)
SetVehicleEngineOn(vehicle, true, true, true)
ESX.ShowNotification("Your engine is now unblocked.")
end)
RegisterNetEvent('antiEngineBlock')
AddEventHandler('antiEngineBlock', function()
ESX.ShowNotification("You have the anti-engine block item. Engine block failed.")
end)
RegisterNetEvent('notifyOfficer')
AddEventHandler('notifyOfficer', function(message)
ESX.ShowNotification(message)
end)