-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.lua
157 lines (144 loc) · 5.08 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
local inRepairShop = false
local uiVisible = false
local repairing = false
local function RepairBlips(coords, type, label, job, blipOptions)
if job then return end
if blip == false then return end
local blip = AddBlipForCoord(coords)
SetBlipSprite(blip, blipOptions.sprite or 357)
SetBlipScale(blip, blipOptions.scale or 0.8)
SetBlipColour(blip, blipOptions.colour ~= nil and blipOptions.colour or type == 'car' and Config.BlipColors.Car or type == 'boat' and Config.BlipColors.Boat or Config.BlipColors.Aircraft)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(label)
EndTextCommandSetBlipName(blip)
end
for k, v in pairs(Config.RepairShops) do
exports["bt-polyzone"]:AddBoxZone(v.zone.name, vector3(v.zone.x, v.zone.y, v.zone.z), v.zone.l, v.zone.w, {
name = v.zone.name,
heading = v.zone.h,
debugPoly = false,
minZ = v.zone.minZ,
maxZ = v.zone.maxZ
}
)
if v.blip ~= false then
RepairBlips(vector3(v.zone.x, v.zone.y, v.zone.z), v.type, v.label, v.job, v.blip)
end
end
RegisterNetEvent('just_repairs:enteredRepair')
AddEventHandler('just_repairs:enteredRepair', function (price)
Citizen.CreateThread(function ()
local check = false
local veh = nil
local driver = nil
local vehClass = nil
local Ped = PlayerPedId()
while inRepairShop do
Citizen.Wait(0)
if IsPedSittingInAnyVehicle(Ped) then
if check == false then
check = true
veh = GetVehiclePedIsUsing(Ped)
driver = GetPedInVehicleSeat(veh, -1)
vehClass = GetVehicleClass(veh)
end
if driver == Ped then
local bodyHealth = GetVehicleBodyHealth(veh)
local engineHealth = GetVehicleEngineHealth(veh)
repairCost = math.ceil((((1000 - bodyHealth) + (1000 - engineHealth)) * Config.CostFactor) * Config.ClassRepairMultiplier[vehClass])
if uiVisible == false and repairCost > 0 then
lib.showTextUI("[E] Fix Vehicle for $".. repairCost, {icon = "fa-solid fa-screwdriver-wrench"})
uiVisible = true
elseif uiVisible == false and repairCost == 0 then
uiVisible = true
repairing = false
lib.showTextUI("Nothing to repair")
end
if repairCost > 0 then
if IsControlJustPressed(1, 38) and repairing == false then
check = true
repairing = true
TriggerServerEvent('just_repairs:checkmoney',repairCost)
end
end
else
Citizen.Wait(2000)
check = false
repairing = false
end
else
repairing = false
uiVisible = false
lib.hideTextUI()
check = false
end
end
end)
end)
RegisterNetEvent('bt-polyzone:enter')
AddEventHandler('bt-polyzone:enter', function(name)
for k, v in pairs(Config.RepairShops) do
if v.zone.name == name then
inRepairShop = true
TriggerEvent('just_repairs:enteredRepair')
break
end
end
end)
RegisterNetEvent('bt-polyzone:exit')
AddEventHandler('bt-polyzone:exit', function(name)
for k, v in pairs(Config.RepairShops) do
if v.zone.name == name then
inRepairShop = false
Citizen.Wait(100)
uiVisible = false
lib.hideTextUI()
break
end
end
end)
RegisterNetEvent('just_repairs:success')
AddEventHandler('just_repairs:success', function ()
local car = GetVehiclePedIsUsing(PlayerPedId())
TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 5.0, 'car_repair', 0.1)
if lib.progressBar({
duration = (Config.RepairTime * 1000),
label = "Repairing Vehicle",
useWhileDead = false,
canCancel = true,
disable = {
move = true,
car = true,
},
}) then
SetVehicleEngineHealth(car, 1000)
SetVehicleFixed(car)
lib.notify({
title = "Your vehicle has been fixed!",
description = "Maybe you should take some driving lessons...",
status = "inform"
})
uiVisible = false
end
end)
RegisterNetEvent('just_repairs:notenoughmoney')
AddEventHandler('just_repairs:notenoughmoney', function (moneyleft)
lib.notify({
title = "You don't have enough money!",
description = "You need: $"..moneyleft,
status = "error"
})
end)
function DrawText3D(x, y, z, text)
local onScreen,_x,_y=World3dToScreen2d(x, y, z)
local px,py,pz=table.unpack(GetGameplayCamCoords())
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(1)
AddTextComponentString(text)
DrawText(_x,_y)
end