-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
431 lines (387 loc) · 13.4 KB
/
Copy pathclient.lua
File metadata and controls
431 lines (387 loc) · 13.4 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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
local QBCore = exports['qb-core']:GetCoreObject()
local inZone = false
local currentMenu = nil
local activeTextUI = nil
local PlayerJob = {} -- Variable para guardar el trabajo localmente
-- ==========================================================
-- GESTIÓN DE JUGADOR Y JOB (OPTIMIZACIÓN)
-- ==========================================================
-- Obtener trabajo al iniciar
AddEventHandler('onResourceStart', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then
return
end
local PlayerData = QBCore.Functions.GetPlayerData()
if PlayerData then
PlayerJob = PlayerData.job
end
end)
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
local PlayerData = QBCore.Functions.GetPlayerData()
PlayerJob = PlayerData.job
end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
PlayerJob = JobInfo
end)
-- ==========================================================
-- FUNCIONES UI
-- ==========================================================
function ShowTextUI(text)
if Config.UseDPTextUI then
exports['DP-TextUI']:MostrarUI('dp_extras_menu', text, 'E', false)
else
TriggerEvent('qb-core:client:DrawText', text, 'left')
end
end
function HideTextUI()
if Config.UseDPTextUI then
exports['DP-TextUI']:OcultarUI('dp_extras_menu')
else
TriggerEvent('qb-core:client:HideText')
end
end
-- ==========================================================
-- LÓGICA DE VEHÍCULOS (LIVERIES Y EXTRAS)
-- ==========================================================
function GetVehicleLiveries(vehicle)
local liveries = {}
local numLiveries = GetVehicleLiveryCount(vehicle)
if numLiveries > 0 then
for i = 0, numLiveries - 1 do
table.insert(liveries, {
id = i,
type = "normal",
name = "Livery " .. (i + 1)
})
end
end
local numMods = GetNumVehicleMods(vehicle, 48)
if numMods > 0 then
for i = 0, numMods - 1 do
table.insert(liveries, {
id = i,
type = "mod",
name = "Design " .. (i + 1)
})
end
end
if numLiveries == 0 and numMods == 0 then
for i = 0, 10 do
if GetVehicleModVariation(vehicle, 48) or DoesExtraExist(vehicle, i) then
table.insert(liveries, {
id = i,
type = "variation",
name = "Style " .. (i + 1)
})
end
end
end
return liveries
end
function ApplyVehicleLivery(vehicle, liveryData)
if liveryData.type == "normal" then
SetVehicleLivery(vehicle, liveryData.id)
elseif liveryData.type == "mod" then
SetVehicleMod(vehicle, 48, liveryData.id, true)
elseif liveryData.type == "variation" then
if DoesExtraExist(vehicle, liveryData.id) then
SetVehicleExtra(vehicle, liveryData.id, 0)
end
end
ForceVehicleUpdate(vehicle)
Citizen.Wait(100)
if liveryData.type == "normal" then
SetVehicleLivery(vehicle, liveryData.id)
elseif liveryData.type == "mod" then
SetVehicleMod(vehicle, 48, liveryData.id, true)
end
end
function ForceVehicleUpdate(vehicle)
if not DoesEntityExist(vehicle) then
return
end
local health = GetVehicleEngineHealth(vehicle)
local dirtLevel = GetVehicleDirtLevel(vehicle)
SetVehicleFixed(vehicle)
Citizen.Wait(50)
SetVehicleEngineHealth(vehicle, health)
SetVehicleBodyHealth(vehicle, health)
SetVehicleDirtLevel(vehicle, dirtLevel)
end
function ToggleExtra(extraId, currentState)
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if vehicle == 0 then
return false
end
local newState = not currentState
local extraValue = newState and 0 or 1
local progressText = newState and Config.Texts.applyingExtra or Config.Texts.removingExtra
ExecuteProgressBar(progressText, Config.ProgressTimes.extra, function()
SetVehicleExtra(vehicle, extraId, extraValue)
ForceVehicleUpdate(vehicle)
Citizen.Wait(100)
SetVehicleExtra(vehicle, extraId, extraValue)
local message = newState and Config.Texts.extraEnabled or Config.Texts.extraDisabled
QBCore.Functions.Notify(message:gsub("{extraId}", extraId), 'success')
if currentMenu == "extras" then
Citizen.Wait(100)
OpenExtrasMenu()
end
end)
return newState
end
function ChangeLivery(liveryData)
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if vehicle == 0 then
return
end
ExecuteProgressBar(Config.Texts.applyingLivery, Config.ProgressTimes.livery, function()
ApplyVehicleLivery(vehicle, liveryData)
local message = Config.Texts.liveryChanged:gsub("{liveryId}", liveryData.name)
QBCore.Functions.Notify(message, 'success')
if currentMenu == "livery" then
Citizen.Wait(100)
OpenLiveryMenu()
end
end)
end
function ExecuteProgressBar(label, time, callback)
QBCore.Functions.Progressbar("dp_extras_progress", label, time, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true
}, {}, {}, {}, function()
if callback then
callback()
end
end, function()
QBCore.Functions.Notify("Cancelado", "error")
end)
end
-- ==========================================================
-- MENÚS
-- ==========================================================
function OpenVehicleMenu()
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if vehicle == 0 then
QBCore.Functions.Notify(Config.Texts.noVehicle, 'error')
return
end
local menu = {{
header = Config.Texts.mainTitle,
isMenuHeader = true
}, {
header = "Livery's",
txt = Config.Texts.liveriesOption,
icon = Config.Icons.paintRoller,
params = {
event = "dp-extras:openLiveryMenu"
}
}, {
header = "Extras",
txt = Config.Texts.extrasOption,
icon = Config.Icons.gears,
params = {
event = "dp-extras:openExtrasMenu"
}
}, {
header = "Lavar",
txt = Config.Texts.washOption,
icon = Config.Icons.soap,
params = {
event = "dp-extras:cleanVehicle"
}
}, {
header = "Reparar",
txt = Config.Texts.repairOption,
icon = Config.Icons.wrench,
params = {
event = "dp-extras:repairVehicle"
}
}}
currentMenu = "main"
exports['DP-Menu']:openMenu(menu)
end
function OpenLiveryMenu()
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if vehicle == 0 then
return
end
local menu = {{
header = Config.Texts.liveriesTitle,
isMenuHeader = true
}}
local liveries = GetVehicleLiveries(vehicle)
local currentLivery = GetVehicleLivery(vehicle)
local currentMod = GetVehicleMod(vehicle, 48)
if #liveries > 0 then
for _, livery in ipairs(liveries) do
local isSelected = (livery.type == "normal" and currentLivery == livery.id) or
(livery.type == "mod" and currentMod == livery.id)
table.insert(menu, {
header = livery.name,
txt = (isSelected and Config.Texts.selected or Config.Texts.clickToSelect),
icon = Config.Icons.paintBrush,
params = {
event = "dp-extras:setLivery",
args = {
liveryData = livery
}
}
})
end
else
table.insert(menu, {
header = "ESTE VEHÍCULO NO TIENE LIVERY'S",
txt = Config.Texts.noLiveries,
isMenuHeader = true
})
end
table.insert(menu, {
header = Config.Texts.backOption,
icon = Config.Icons.back,
params = {
event = "dp-extras:openMainMenu"
}
})
currentMenu = "livery"
exports['DP-Menu']:openMenu(menu)
end
function OpenExtrasMenu()
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if vehicle == 0 then
return
end
local menu = {{
header = Config.Texts.extrasTitle,
isMenuHeader = true
}}
local hasExtras = false
for extraId = 1, 14 do
if DoesExtraExist(vehicle, extraId) then
hasExtras = true
local isEnabled = IsVehicleExtraTurnedOn(vehicle, extraId) == 1
table.insert(menu, {
header = "Extra " .. extraId,
txt = (isEnabled and Config.Texts.enabled or Config.Texts.disabled),
icon = isEnabled and Config.Icons.toggleOn or Config.Icons.toggleOff,
params = {
event = "dp-extras:toggleExtra",
args = {
extraId = extraId,
currentState = isEnabled
}
}
})
end
end
if not hasExtras then
table.insert(menu, {
header = "ESTE VEHÍCULO NO TIENE EXTRAS",
txt = Config.Texts.noExtras,
isMenuHeader = true
})
end
table.insert(menu, {
header = Config.Texts.backOption,
icon = Config.Icons.back,
params = {
event = "dp-extras:openMainMenu"
}
})
currentMenu = "extras"
exports['DP-Menu']:openMenu(menu)
end
-- ==========================================================
-- EVENTOS
-- ==========================================================
RegisterNetEvent('dp-extras:toggleExtra', function(data)
ToggleExtra(data.extraId, data.currentState)
end)
RegisterNetEvent('dp-extras:setLivery', function(data)
ChangeLivery(data.liveryData)
end)
RegisterNetEvent('dp-extras:openMainMenu', OpenVehicleMenu)
RegisterNetEvent('dp-extras:openLiveryMenu', OpenLiveryMenu)
RegisterNetEvent('dp-extras:openExtrasMenu', OpenExtrasMenu)
RegisterNetEvent('dp-extras:cleanVehicle', function()
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if vehicle == 0 then
return
end
ExecuteProgressBar(Config.Texts.washing, Config.ProgressTimes.wash, function()
SetVehicleDirtLevel(vehicle, 0.0)
QBCore.Functions.Notify(Config.Texts.washed, 'success')
Citizen.Wait(300)
OpenVehicleMenu()
end)
end)
RegisterNetEvent('dp-extras:repairVehicle', function()
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if vehicle == 0 then
return
end
ExecuteProgressBar(Config.Texts.repairing, Config.ProgressTimes.repair, function()
SetVehicleEngineHealth(vehicle, 1000.0)
SetVehicleBodyHealth(vehicle, 1000.0)
SetVehicleFixed(vehicle)
QBCore.Functions.Notify(Config.Texts.repaired, 'success')
Citizen.Wait(300)
OpenVehicleMenu()
end)
end)
-- ==========================================================
-- BUCLE PRINCIPAL (OPTIMIZADO)
-- ==========================================================
Citizen.CreateThread(function()
while true do
local wait = 1000 -- Por defecto, duerme 1 segundo (ahorra CPU)
-- Verificar si tiene el trabajo requerido (o si no se requiere job)
if not Config.JobRequired or (PlayerJob.name == Config.JobRequired) then
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local distance = #(playerCoords - Config.Marker.position)
-- Si está cerca, cambiamos el wait a 0 para dibujar fluido
if distance < Config.Marker.drawDistance then
wait = 0
DrawMarker(Config.Marker.type, Config.Marker.position.x, Config.Marker.position.y,
Config.Marker.position.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Marker.size.x, Config.Marker.size.y,
Config.Marker.size.z, Config.Marker.color.r, Config.Marker.color.g, Config.Marker.color.b,
Config.Marker.color.a, Config.Marker.saltos, Config.Marker.sigue, false, Config.Marker.rotacion,
false, false, false)
if distance < Config.Marker.interactionDistance then
if not inZone then
inZone = true
ShowTextUI(Config.Texts.drawText)
end
if IsControlJustReleased(0, 38) then
if IsPedInAnyVehicle(playerPed, false) then
OpenVehicleMenu()
else
QBCore.Functions.Notify(Config.Texts.noVehicle, 'error')
end
end
else
if inZone then
inZone = false
HideTextUI()
end
end
else
-- Si se aleja pero estaba en zona, limpiamos UI
if inZone then
inZone = false
HideTextUI()
end
end
else
-- Si cambia de trabajo y estaba en zona, limpiamos
if inZone then
inZone = false
HideTextUI()
end
end
Citizen.Wait(wait) -- Usamos el tiempo variable
end
end)