forked from manups4e/esx_eden_garage_updated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
476 lines (388 loc) · 14 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
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
-- Local
local Keys = {
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}
local CurrentAction = nil
local GUI = {}
GUI.Time = 0
local HasAlreadyEnteredMarker = false
local LastZone = nil
local CurrentActionMsg = ''
local CurrentActionData = {}
local times = 0
local this_Garage = {}
-- Fin Local
-- Init ESX
ESX = nil
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
-- Fin init ESX
--- Gestion Des blips
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
--PlayerData = xPlayer
--TriggerServerEvent('esx_jobs:giveBackCautionInCaseOfDrop')
refreshBlips()
end)
function refreshBlips()
local zones = {}
local blipInfo = {}
for zoneKey,zoneValues in pairs(Config.Garages)do
local blip = AddBlipForCoord(zoneValues.Pos.x, zoneValues.Pos.y, zoneValues.Pos.z)
SetBlipSprite (blip, Config.BlipInfos.Sprite)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 1.2)
SetBlipColour (blip, Config.BlipInfos.Color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(zoneKey)
EndTextCommandSetBlipName(blip)
local blip = AddBlipForCoord(zoneValues.MunicipalPoundPoint.Pos.x, zoneValues.MunicipalPoundPoint.Pos.y, zoneValues.MunicipalPoundPoint.Pos.z)
SetBlipSprite (blip, Config.BlipPound.Sprite)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 1.2)
SetBlipColour (blip, Config.BlipPound.Color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Deposito auto")
EndTextCommandSetBlipName(blip)
end
end
-- Fin Gestion des Blips
--Fonction Menu
function OpenMenuGarage(PointType)
ESX.UI.Menu.CloseAll()
local elements = {}
if PointType == 'spawn' then
table.insert(elements,{label = "Lista dei veicoli", value = 'list_vehicles'})
end
if PointType == 'delete' then
table.insert(elements,{label = "Parcheggia veicolo", value = 'stock_vehicle'})
end
if PointType == 'pound' then
table.insert(elements,{label = "Restituisci veicolo 500€", value = 'return_vehicle'})
end
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'garage_menu',
{
title = 'Garage',
align = 'top-left',
elements = elements,
},
function(data, menu)
menu.close()
if(data.current.value == 'list_vehicles') then
ListVehiclesMenu()
end
if(data.current.value == 'stock_vehicle') then
StockVehicleMenu()
end
if(data.current.value == 'return_vehicle') then
ReturnVehicleMenu()
end
local playerPed = GetPlayerPed(-1)
SpawnVehicle(data.current.value)
end,
function(data, menu)
menu.close()
end
)
end
-- Afficher les listes des vehicules
function ListVehiclesMenu()
local elements = {}
ESX.TriggerServerCallback('eden_garage:getVehicles', function(vehicles)
for _,v in pairs(vehicles) do
local hashVehicule = v.vehicle.model
local vehicleName = GetDisplayNameFromVehicleModel(hashVehicule)
local labelvehicle
local plate = v.plate
if(v.state)then
labelvehicle = vehicleName.. ' (' .. plate .. '): Garage'
else
labelvehicle = vehicleName.. ' (' .. plate .. '): Deposito'
end
table.insert(elements, {label =labelvehicle , value = v})
end
local c = 0
for _,a in pairs(vehicles) do
if (a.state) then
c = c + 1
else
c = c - 1
end
end
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'spawn_vehicle',
{
title = 'Garage',
align = 'top-left',
elements = elements,
},
function(data, menu)
if(data.current.value.state)then
menu.close()
if c > 0 then
SpawnVehicle(data.current.value.vehicle, data.current.value.plate)
else
TriggerEvent('esx:showNotification', 'Hai gia un veicolo fuori dal garage o al deposito!')
end
else
TriggerEvent('esx:showNotification', 'Il tuo veicolo è al deposito')
end
end,
function(data, menu)
menu.close()
--CurrentAction = 'open_garage_action'
end
)
end)
end
-- Fin Afficher les listes des vehicules
function reparation(prix,vehicle,vehicleProps)
ESX.UI.Menu.CloseAll()
local elements = {
{label = "Posa il veicolo ("..prix.."€)", value = 'yes'},
{label = "aspetta il meccanico", value = 'no'},
}
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'delete_menu',
{
title = 'vehicule endomagé',
align = 'top-left',
elements = elements,
},
function(data, menu)
menu.close()
if(data.current.value == 'yes') then
TriggerServerEvent('eden_garage:payhealth', prix)
ranger(vehicle,vehicleProps)
end
if(data.current.value == 'no') then
ESX.ShowNotification('aspetta il meccanico')
end
end,
function(data, menu)
menu.close()
end
)
end
function ranger(vehicle,vehicleProps)
ESX.Game.DeleteVehicle(vehicle)
TriggerServerEvent('eden_garage:modifystate', vehicleProps.plate, true)
TriggerEvent('esx:showNotification', 'Il tuo veicolo è nel garage')
end
-- Fonction qui permet de rentrer un vehicule
function StockVehicleMenu()
local playerPed = GetPlayerPed(-1)
if IsPedInAnyVehicle(playerPed, false) then
local playerPed = GetPlayerPed(-1)
local coords = GetEntityCoords(playerPed)
local vehicle = GetVehiclePedIsIn(playerPed,false)
local vehicleProps = ESX.Game.GetVehicleProperties(vehicle)
local current = GetPlayersLastVehicle(GetPlayerPed(-1), true)
local engineHealth = GetVehicleEngineHealth(current)
local plate = vehicleProps.plate
ESX.TriggerServerCallback('eden_garage:stockv',function(valid)
if (valid) then
TriggerServerEvent('eden_garage:debug', vehicle)
if engineHealth < 990 then
local fraisRep= math.floor((1000 - engineHealth)*3)
reparation(fraisRep,vehicle,vehicleProps)
else
ranger(vehicle,vehicleProps)
end
else
TriggerEvent('esx:showNotification', 'Non è possibile parcheggiare il veicolo')
end
end,vehicleProps)
else
TriggerEvent('esx:showNotification', 'Non hai nessun veicolo da posare')
end
end
-- Fin fonction qui permet de rentrer un vehicule
--Fin fonction Menu
--Fonction pour spawn vehicule
function SpawnVehicle(vehicle, plate)
ESX.Game.SpawnVehicle(vehicle.model,{
x=this_Garage.SpawnPoint.Pos.x ,
y=this_Garage.SpawnPoint.Pos.y,
z=this_Garage.SpawnPoint.Pos.z + 1
},this_Garage.SpawnPoint.Heading, function(callback_vehicle)
ESX.Game.SetVehicleProperties(callback_vehicle, vehicle)
SetVehRadioStation(callback_vehicle, "OFF")
TaskWarpPedIntoVehicle(GetPlayerPed(-1), callback_vehicle, -1)
end)
TriggerServerEvent('eden_garage:modifystate', plate, false)
end
--Fin fonction pour spawn vehicule
--Fonction pour spawn vehicule fourriere
function SpawnPoundedVehicle(vehicle, plate)
ESX.Game.SpawnVehicle(vehicle.model, {
x = this_Garage.SpawnMunicipalPoundPoint.Pos.x ,
y = this_Garage.SpawnMunicipalPoundPoint.Pos.y,
z = this_Garage.SpawnMunicipalPoundPoint.Pos.z + 1
},180, function(callback_vehicle)
ESX.Game.SetVehicleProperties(callback_vehicle, vehicle)
end)
TriggerServerEvent('eden_garage:modifystate', plate, true)
ESX.SetTimeout(10000, function()
TriggerServerEvent('eden_garage:modifystate', plate, false)
end)
end
--Fin fonction pour spawn vehicule fourriere
--Action das les markers
AddEventHandler('eden_garage:hasEnteredMarker', function(zone)
if zone == 'spawn' then
CurrentAction = 'spawn'
CurrentActionMsg = "Premi ~INPUT_PICKUP~ per prendere il veicolo"
CurrentActionData = {}
end
if zone == 'delete' then
CurrentAction = 'delete'
CurrentActionMsg = "Premi ~INPUT_PICKUP~ per parcheggiare"
CurrentActionData = {}
end
if zone == 'pound' then
CurrentAction = 'pound_action_menu'
CurrentActionMsg = "Premi ~INPUT_PICKUP~ per accedere al deposito"
CurrentActionData = {}
end
end)
AddEventHandler('eden_garage:hasExitedMarker', function(zone)
ESX.UI.Menu.CloseAll()
CurrentAction = nil
end)
--Fin Action das les markers
function ReturnVehicleMenu()
ESX.TriggerServerCallback('eden_garage:getOutVehicles', function(vehicles)
local elements = {}
for _,v in pairs(vehicles) do
local hashVehicule = v.model
local vehicleName = GetDisplayNameFromVehicleModel(hashVehicule)
local labelvehicle
labelvehicle = vehicleName..': Riprendi'
table.insert(elements, {label =labelvehicle , value = v})
end
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'return_vehicle',
{
title = 'Garage',
align = 'top-left',
elements = elements,
},
function(data, menu)
ESX.TriggerServerCallback('eden_garage:checkMoney', function(hasEnoughMoney)
if hasEnoughMoney then
if times == 0 then
TriggerServerEvent('eden_garage:pay')
SpawnPoundedVehicle(data.current.value, data.current.value.plate)
times=times+1
elseif times > 0 then
ESX.SetTimeout(60000, function()
times=0
end)
end
else
ESX.ShowNotification('Non hai abbastanza soldi')
end
end)
end,
function(data, menu)
menu.close()
--CurrentAction = 'open_garage_action'
end
)
end)
end
-- Affichage markers
Citizen.CreateThread(function()
while true do
Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
for k,v in pairs(Config.Garages) do
if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
DrawMarker(v.SpawnPoint.Marker, v.SpawnPoint.Pos.x, v.SpawnPoint.Pos.y, v.SpawnPoint.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.SpawnPoint.Size.x, v.SpawnPoint.Size.y, v.SpawnPoint.Size.z, v.SpawnPoint.Color.r, v.SpawnPoint.Color.g, v.SpawnPoint.Color.b, 100, false, true, 2, false, false, false, false)
DrawMarker(v.DeletePoint.Marker, v.DeletePoint.Pos.x, v.DeletePoint.Pos.y, v.DeletePoint.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.DeletePoint.Size.x, v.DeletePoint.Size.y, v.DeletePoint.Size.z, v.DeletePoint.Color.r, v.DeletePoint.Color.g, v.DeletePoint.Color.b, 100, false, true, 2, false, false, false, false)
end
if(GetDistanceBetweenCoords(coords, v.MunicipalPoundPoint.Pos.x, v.MunicipalPoundPoint.Pos.y, v.MunicipalPoundPoint.Pos.z, true) < Config.DrawDistance) then
DrawMarker(v.MunicipalPoundPoint.Marker, v.MunicipalPoundPoint.Pos.x, v.MunicipalPoundPoint.Pos.y, v.MunicipalPoundPoint.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.MunicipalPoundPoint.Size.x, v.MunicipalPoundPoint.Size.y, v.MunicipalPoundPoint.Size.z, v.MunicipalPoundPoint.Color.r, v.MunicipalPoundPoint.Color.g, v.MunicipalPoundPoint.Color.b, 100, false, true, 2, false, false, false, false)
DrawMarker(v.SpawnMunicipalPoundPoint.Marker, v.SpawnMunicipalPoundPoint.Pos.x, v.SpawnMunicipalPoundPoint.Pos.y, v.SpawnMunicipalPoundPoint.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.SpawnMunicipalPoundPoint.Size.x, v.SpawnMunicipalPoundPoint.Size.y, v.SpawnMunicipalPoundPoint.Size.z, v.SpawnMunicipalPoundPoint.Color.r, v.SpawnMunicipalPoundPoint.Color.g, v.SpawnMunicipalPoundPoint.Color.b, 100, false, true, 2, false, false, false, false)
end
end
end
end)
-- Fin affichage markers
-- Activer le menu quand player dedans
Citizen.CreateThread(function()
local currentZone = 'garage'
while true do
Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
local isInMarker = false
for _,v in pairs(Config.Garages) do
if(GetDistanceBetweenCoords(coords, v.SpawnPoint.Pos.x, v.SpawnPoint.Pos.y, v.SpawnPoint.Pos.z, true) < v.Size.x) then
isInMarker = true
this_Garage = v
currentZone = 'spawn'
end
if(GetDistanceBetweenCoords(coords, v.DeletePoint.Pos.x, v.DeletePoint.Pos.y, v.DeletePoint.Pos.z, true) < v.Size.x) then
isInMarker = true
this_Garage = v
currentZone = 'delete'
end
if(GetDistanceBetweenCoords(coords, v.MunicipalPoundPoint.Pos.x, v.MunicipalPoundPoint.Pos.y, v.MunicipalPoundPoint.Pos.z, true) < v.MunicipalPoundPoint.Size.x) then
isInMarker = true
this_Garage = v
currentZone = 'pound'
end
end
if isInMarker and not hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = true
LastZone = currentZone
TriggerEvent('eden_garage:hasEnteredMarker', currentZone)
end
if not isInMarker and hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = false
TriggerEvent('eden_garage:hasExitedMarker', LastZone)
end
end
end)
-- Fin activer le menu fourriere quand player dedans
-- Controle touche
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if CurrentAction ~= nil then
SetTextComponentFormat('STRING')
AddTextComponentString(CurrentActionMsg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
if IsControlPressed(0, Keys['E']) and (GetGameTimer() - GUI.Time) > 150 then
if CurrentAction == 'pound_action_menu' then
OpenMenuGarage('pound')
end
if CurrentAction == 'spawn' then
OpenMenuGarage('spawn')
end
if CurrentAction == 'delete' then
OpenMenuGarage('delete')
end
CurrentAction = nil
GUI.Time = GetGameTimer()
end
end
end
end)
-- Fin controle touche