forked from snyx95/esx_eden_garage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
334 lines (267 loc) · 9.5 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
-- 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 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)
end
end
-- Fin Gestion des Blips
--Fonction Menu
function OpenMenuGarage()
ESX.UI.Menu.CloseAll()
local elements = {
{label = "Liste des véhicules", value = 'list_vehicles'},
{label = "Rentrer vehicules", value = 'stock_vehicle'},
{label = "Retour vehicule ("..Config.Price.."$)", value = 'return_vehicle'},
}
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)
--local coords = societyConfig.Zones.VehicleSpawnPoint.Pos
end,
function(data, menu)
menu.close()
--CurrentAction = 'open_garage_action'
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
if(v.state)then
labelvehicle = vehicleName..': Rentré'
else
labelvehicle = vehicleName..': Sortie'
end
table.insert(elements, {label =labelvehicle , value = v})
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()
SpawnVehicle(data.current.value.vehicle)
else
TriggerEvent('esx:showNotification', 'Votre véhicule est déjà sorti')
end
end,
function(data, menu)
menu.close()
--CurrentAction = 'open_garage_action'
end
)
end)
end
-- Fin Afficher les listes des vehicules
-- Fonction qui permet de rentrer un vehicule
function StockVehicleMenu()
local playerPed = GetPlayerPed(-1)
if IsAnyVehicleNearPoint(this_Garage.DeletePoint.Pos.x, this_Garage.DeletePoint.Pos.y, this_Garage.DeletePoint.Pos.z, 3.5) then
local vehicle = GetClosestVehicle(this_Garage.DeletePoint.Pos.x, this_Garage.DeletePoint.Pos.y, this_Garage.DeletePoint.Pos.z, this_Garage.DeletePoint.Size.x, 0, 70)
local vehicleProps = ESX.Game.GetVehicleProperties(vehicle)
ESX.TriggerServerCallback('eden_garage:stockv',function(valid)
if(valid) then
TriggerServerEvent('eden_garage:debug', vehicle)
DeleteVehicle(vehicle)
TriggerServerEvent('eden_garage:modifystate', vehicleProps, true)
TriggerEvent('esx:showNotification', 'Votre véhicule est dans le garage')
else
TriggerEvent('esx:showNotification', 'Vous ne pouvez pas stocker ce véhicule')
end
end,vehicleProps)
else
TriggerEvent('esx:showNotification', 'Il n\' y a pas de vehicule à rentrer')
end
end
-- Fin fonction qui permet de rentrer un vehicule
--Fin fonction Menu
--Fonction pour spawn vehicule
function SpawnVehicle(vehicle)
ESX.Game.SpawnVehicle(vehicle.model, {
x = this_Garage.SpawnPoint.Pos.x ,
y = this_Garage.SpawnPoint.Pos.y,
z = this_Garage.SpawnPoint.Pos.z + 1
},120, function(callback_vehicle)
ESX.Game.SetVehicleProperties(callback_vehicle, vehicle)
end)
TriggerServerEvent('eden_garage:modifystate', vehicle, false)
end
--Fin fonction pour spawn vehicule
--Action das les markers
AddEventHandler('eden_garage:hasEnteredMarker', function(zone)
if zone == 'garage' then
CurrentAction = 'garage_action_menu'
CurrentActionMsg = "Appuyer sur ~INPUT_PICKUP~ pour ouvrir le garage"
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..': Sortie'
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
TriggerServerEvent('eden_garage:pay')
SpawnVehicle(data.current.value)
else
ESX.ShowNotification('Vous n\'avez pas assez d\'argent')
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.Marker, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
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
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.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
isInMarker = true
this_Garage = v
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 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 == 'garage_action_menu' then
OpenMenuGarage()
end
CurrentAction = nil
GUI.Time = GetGameTimer()
end
end
end
end)
-- Fin controle touche