-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
357 lines (292 loc) · 11.7 KB
/
client.lua
File metadata and controls
357 lines (292 loc) · 11.7 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
local QBCore = exports['qb-core']:GetCoreObject()
local Config = Config or {} -- Load the config
--- Simple helper that only prints when debugging is enabled.
---@param ... any
local function debugPrint(...)
if not Config.debug then return end
print(...)
end
-- Function to spawn the ped and garage interactions
local function spawnPedAndGarageInteractions()
if not Config.PoliceGarages or type(Config.PoliceGarages) ~= "table" then
debugPrint("Error: Config.PoliceGarages is not defined or is not a table!")
return
end
debugPrint("Spawning peds for garages...") -- Debug message before spawning peds
for _, garage in ipairs(Config.PoliceGarages) do
debugPrint("Creating ped for garage: " .. garage.name) -- Debug message for each garage
local pedModel = garage.pedModel or `s_m_y_cop_01`
RequestModel(pedModel)
while not HasModelLoaded(pedModel) do
Wait(500)
end
local ped = CreatePed(4, pedModel, garage.pedCoords.x, garage.pedCoords.y, garage.pedCoords.z, garage.pedHeading, false, true)
SetEntityInvincible(ped, true)
SetEntityVisible(ped, true)
FreezeEntityPosition(ped, true)
exports['qb-target']:AddTargetEntity(ped, {
options = {
{
type = "client",
event = "qb-policehelper:openGarageMenu",
icon = "fas fa-car",
label = "Access Police Garage",
jobType = "leo",
garage_name = garage.name,
carSpawns = garage.carSpawns,
vehicleList = garage.vehicleList
}
},
distance = 3.0
})
debugPrint("Ped created for garage: " .. garage.name) -- Debug print for ped creation
end
end
local function spawnBossMenuPeds()
if not Config.BossMenus or type(Config.BossMenus) ~= "table" then
debugPrint("Config.BossMenus is not defined or is not a table, skipping boss menu ped setup.")
return
end
debugPrint("Spawning peds for boss menus...")
for _, bossMenu in ipairs(Config.BossMenus) do
if not bossMenu.pedCoords then
debugPrint("Boss menu entry missing pedCoords, skipping.")
else
local pedModel = bossMenu.pedModel or `s_m_m_security_01`
RequestModel(pedModel)
while not HasModelLoaded(pedModel) do
Wait(500)
end
local ped = CreatePed(4, pedModel, bossMenu.pedCoords.x, bossMenu.pedCoords.y, bossMenu.pedCoords.z, bossMenu.pedHeading or 0.0, false, true)
SetEntityInvincible(ped, true)
SetEntityVisible(ped, true)
FreezeEntityPosition(ped, true)
exports['qb-target']:AddTargetEntity(ped, {
options = {
{
type = "client",
event = "qb-policehelper:openBossMenu",
icon = bossMenu.icon or "fas fa-briefcase",
label = bossMenu.label or "Open Boss Menu",
job = bossMenu.job,
jobType = bossMenu.jobType,
args = {
job = bossMenu.job,
minimumGrade = bossMenu.minimumGrade,
requireBoss = bossMenu.requireBoss,
}
}
},
distance = bossMenu.distance or 2.0
})
debugPrint("Boss menu ped created for job: " .. (bossMenu.job or "unknown"))
end
end
end
local function setupJobActions()
if not Config.Actions or type(Config.Actions) ~= "table" then
debugPrint("Error: Config.Actions is not defined or is not a table!")
return
end
debugPrint("Setting up job actions...") -- Debug message for setting up actions
for _, action in ipairs(Config.Actions) do
exports['qb-target']:AddTargetEntity(PlayerPedId(), {
options = {
{
type = action.type,
event = action.event,
icon = action.icon,
label = action.label,
job = action.job,
item = action.item
}
},
distance = 2.0
})
debugPrint("Job action added: " .. action.label)
end
end
RegisterNetEvent('qb-policehelper:openGarageMenu', function(data)
debugPrint("Received data:", json.encode(data))
local garageName = data.garage_name
local carSpawns = data.carSpawns
local vehicleList = data.vehicleList
local PlayerData = QBCore.Functions.GetPlayerData()
local playerJob = PlayerData.job.name
local playerRank = PlayerData.job.grade
if garageName then
debugPrint("Opening garage menu for:", garageName)
end
if not carSpawns then
debugPrint("Error: carSpawns is not available in the received data!")
QBCore.Functions.Notify("Error: carSpawns is missing!", "error")
return
end
if type(carSpawns) ~= "table" then
debugPrint("Error: carSpawns is not a valid table!")
QBCore.Functions.Notify("Error: carSpawns is not a valid table!", "error")
return
end
if type(vehicleList) ~= "table" then
debugPrint("Error: vehicleList is not a valid table!")
QBCore.Functions.Notify("Error: vehicle list is missing!", "error")
return
end
debugPrint("Player Rank (Raw): ", json.encode(playerRank))
if playerJob ~= "police" then
QBCore.Functions.Notify("You are not a Law Enforcement Officer, you cannot access this garage.", "error")
return
end
if type(playerRank) == "table" then
if playerRank.grade then
playerRank = playerRank.grade
elseif playerRank.level then
playerRank = playerRank.level
else
playerRank = 0
end
debugPrint("Player Rank (Fixed):", playerRank)
end
local sanitizedSpawns = {}
for index, spawn in ipairs(carSpawns) do
if spawn and spawn.x and spawn.y and spawn.z and spawn.w then
sanitizedSpawns[index] = { x = spawn.x, y = spawn.y, z = spawn.z, w = spawn.w }
end
end
local options = {}
for i, vehicle in ipairs(vehicleList) do
debugPrint("Vehicle rank for", vehicle.label, ":", vehicle.rank)
local spawnLocation = sanitizedSpawns[i]
local hasRequiredRank = type(vehicle.rank) == "number" and playerRank >= vehicle.rank
local hasModel = type(vehicle.model) == "string" and vehicle.model ~= ""
if hasRequiredRank and hasModel and spawnLocation then
table.insert(options, {
label = vehicle.label,
vehicleModel = vehicle.model,
spawnLocation = spawnLocation,
requiredRank = vehicle.rank
})
end
end
if #options > 0 then
local menuOptions = {}
for _, option in ipairs(options) do
table.insert(menuOptions, {
header = option.label,
txt = "Rank required: " .. option.requiredRank,
params = {
event = 'qb-policehelper:spawnVehicle',
args = {
vehicleModel = option.vehicleModel,
spawnLocation = option.spawnLocation,
carSpawns = sanitizedSpawns
}
}
})
end
exports['qb-menu']:openMenu(menuOptions)
else
QBCore.Functions.Notify("You do not have the required rank to access any vehicles.", "error")
end
end)
RegisterNetEvent('qb-policehelper:openBossMenu', function(optionData)
local args = nil
if optionData then
if optionData.args then
args = optionData.args
elseif optionData.option and optionData.option.args then
args = optionData.option.args
end
end
local data = args or optionData or {}
local PlayerData = QBCore.Functions.GetPlayerData()
local jobData = PlayerData and PlayerData.job or {}
local playerJob = jobData.name
local playerGrade = jobData.grade
local requiredJob = data and data.job or nil
local minimumGrade = data and data.minimumGrade or 0
local requireBoss = data and data.requireBoss
if not requiredJob then
debugPrint("Boss menu interaction missing job requirement, aborting.")
QBCore.Functions.Notify("Boss menu not configured correctly.", "error")
return
end
if playerJob ~= requiredJob then
QBCore.Functions.Notify("You are not employed here.", "error")
return
end
if type(playerGrade) == "table" then
if playerGrade.grade then
playerGrade = playerGrade.grade
elseif playerGrade.level then
playerGrade = playerGrade.level
else
playerGrade = 0
end
end
playerGrade = tonumber(playerGrade) or 0
if requireBoss ~= false and not jobData.isboss then
QBCore.Functions.Notify("Only bosses can access this menu.", "error")
return
end
if minimumGrade and playerGrade < minimumGrade then
QBCore.Functions.Notify("You do not have the required rank.", "error")
return
end
TriggerServerEvent('qb-bossmenu:server:openMenu')
end)
RegisterNetEvent('qb-policehelper:spawnVehicle', function(data)
local vehicleModel = data.vehicleModel
local spawnLocation = data.spawnLocation
local carSpawns = data.carSpawns or {}
local function isSpawnOccupied(location)
if not location then return true end
local vehicles = GetGamePool('CVehicle')
for _, vehicle in ipairs(vehicles) do
local vehiclePos = GetEntityCoords(vehicle)
local distance = Vdist(vehiclePos.x, vehiclePos.y, vehiclePos.z, location.x, location.y, location.z)
if distance < 5.0 then
return true
end
end
return false
end
debugPrint("Requested vehicle model: ", vehicleModel)
debugPrint("Primary spawn location: ", json.encode(spawnLocation or {}))
debugPrint("Available carSpawns: ", json.encode(carSpawns))
if isSpawnOccupied(spawnLocation) then
debugPrint("Spawn point occupied. Searching for an empty spot...")
local foundEmptySpot = false
for _, newSpawn in ipairs(carSpawns) do
if not isSpawnOccupied(newSpawn) then
spawnLocation = newSpawn
debugPrint("Found an available spawn point.")
foundEmptySpot = true
break
end
end
if not foundEmptySpot then
debugPrint("No empty spawn spots available.")
QBCore.Functions.Notify("No empty spawn spots available!", "error")
return
end
end
if not vehicleModel or not spawnLocation then
debugPrint("Vehicle model or spawn location missing, aborting spawn.")
QBCore.Functions.Notify("Invalid vehicle information received!", "error")
return
end
RequestModel(vehicleModel)
while not HasModelLoaded(vehicleModel) do
Wait(500)
end
local vehicle = CreateVehicle(vehicleModel, spawnLocation.x, spawnLocation.y, spawnLocation.z, spawnLocation.w, true, false)
exports['LegacyFuel']:SetFuel(vehicle, 100.0)
SetEntityAsMissionEntity(vehicle, true, true)
local playerPed = PlayerPedId()
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
debugPrint("Vehicle spawned with full fuel: " .. vehicleModel)
end)
spawnPedAndGarageInteractions()
spawnBossMenuPeds()
setupJobActions()