-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.lua
116 lines (106 loc) · 3 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
local canRepair = false
--Keybind to repair
local repairzonebind = lib.addKeybind({
name = 'repairzone',
description = 'Press e to repair your vehicle',
defaultKey = 'E',
onPressed = function()
TriggerEvent('nazz:repairzones')
end
})
repairzonebind:disable(true)
--Function
function getClosestVehicle(coords)
local ped = cache.ped
local vehicles = GetGamePool('CVehicle')
local closestDistance = -1
local closestVehicle = -1
if coords then
coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords
else
coords = GetEntityCoords(ped)
end
for i = 1, #vehicles, 1 do
local vehicleCoords = GetEntityCoords(vehicles[i])
local distance = #(vehicleCoords - coords)
if closestDistance == -1 or closestDistance > distance then
closestVehicle = vehicles[i]
closestDistance = distance
end
end
return closestVehicle, closestDistance
end
local function RepairVehicle(veh)
local veh = getClosestVehicle()
SetVehicleFixed(veh)
SetVehicleEngineOn(veh, true, false)
SetVehicleTyreFixed(veh, 0)
SetVehicleTyreFixed(veh, 1)
SetVehicleTyreFixed(veh, 2)
SetVehicleTyreFixed(veh, 3)
SetVehicleTyreFixed(veh, 4)
end
function onEnter(self)
repairzonebind:disable(false)
end
function onExit(self)
canRepair = false
repairzonebind:disable(true)
lib.hideTextUI()
end
function inside(self)
canRepair = true
lib.showTextUI('[E] Repair Vehicle', {
icon = 'fa-solid fa-screwdriver-wrench',
position = "left-center"
})
end
for k, v in pairs(Config.RepairZone) do
local poly = lib.zones.poly({
points = v.points,
thickness = v.thickness,
debug = true,
inside = inside,
onEnter = onEnter,
onExit = onExit
})
end
--Event
RegisterNetEvent('nazz:repairzones', function()
local ped = cache.ped
if canRepair then
if IsPedInAnyVehicle(ped) then
if repairing then return end
repairing = true
if lib.progressCircle({
duration = 5000,
position = 'bottom',
useWhileDead = false,
canCancel = false,
disable = {
car = true
},
}) then
RepairVehicle(veh)
lib.notify({
title = 'Vehicle Repaired!',
type = 'success',
position = 'top'
})
end
repairing = false
else
lib.notify({
title = 'Youre not inside vehicle!',
type = 'error',
position = 'top'
})
end
else
lib.notify({
title = 'Youre outside repair zone!',
type = 'error',
position = 'top'
})
end
end)