Hello guys,
i’m on to modify the garage script from esx_drp_garage, to only display selected type of vehicle.
I changed the config.lua to this:
Config = {
Garages = {
{
type = "car",
Marker = vector3(215.80, -810.06, 29.73),
Spawner = vector3(229.70, -800.12, 29.57),
Deleter = vector3(223.80, -760.42, 29.65),
heading = 157.84
},
},
}
How could I now access the Config.Garages.type in the TriggerServerCallback for the list which displays the vehicles?
How my client.lua looks:
function ListVehiclesMenu()
local elements = {}
ESX.TriggerServerCallback('eden_garage:getVehicles', function(vehicles)
for _,v in pairs(vehicles) do
local hashVehicle = v.vehicle.model
local vehicleName = GetDisplayNameFromVehicleModel(hashVehicle)
local labelvehicle
if(v.state)then
labelvehicle = _U('status_in_garage', GetLabelText(vehicleName))
else
labelvehicle = _U('status_out_garage', GetLabelText(vehicleName))
end
table.insert(elements, {label =labelvehicle , value = v})
end
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'spawn_vehicle',
{
title = _U('garage'),
align = 'top-left',
elements = elements,
},
function(data, menu)
if(data.current.value.state)then
menu.close()
SpawnVehicle(data.current.value.vehicle)
else
end
end,
function(data, menu)
menu.close()
end
)
end)
end
And now my server.lua, how far i got:
ESX.RegisterServerCallback('eden_garage:getVehicles', function(source, cb)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if Config.Garages.type == 'car' then
local ownedCars = {}
MySQL.Async.fetchAll("SELECT * FROM owned_vehicles WHERE owner=@identifier AND type=@type",{['@identifier'] = xPlayer.getIdentifier(), ['@type'] = 'car'}, function(data)
for _,v in pairs(data) do
local vehicle = json.decode(v.vehicle)
table.insert(ownedCars, {vehicle = vehicle, state = v.state, plate = v.plate})
end
cb(ownedCars)
end)
end
end)
Maybe someone is able to understand my issue and could help me to solve this!