FindVehicleByPlate = function(plate)
local gameVehicles = ESX.Game.GetVehicles()
for i = 1, #gameVehicles do
local vehicle = gameVehicles[i]
if DoesEntityExist(vehicle) then
if Config.Trim(GetVehicleNumberPlateText(vehicle)) == Config.Trim(plate) then
return vehicle
end
end
end
return nil
end
config.lua
Config.Trim = function(value)
if value then
return (string.gsub(value, "^%s*(.-)%s*$", "%1"))
else
return nil
end
end
ok lets check the car existing in your script garage
make a local like local doesVehicleExist = FindVehicleByPlate(ESX.Math.Trim(data.current.value.plate))
in function listmneu of your owned cars
befor spawn car add this
if not doesVehicleExist then
--- spawn car name codes
else
--add here any notify like your car is exist
end
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..': '.._U('return')
table.insert(elements, {label =labelvehicle , value = v})
end
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'return_vehicle',
{
title = _U('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(_U('not_enough_money'))
end
end)
end,
function(data, menu)
menu.close()
--CurrentAction = 'open_garage_action'
end
)
end)
end
replace
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..': '.._U('return')
table.insert(elements, {label =labelvehicle , value = v})
end
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'return_vehicle',
{
title = _U('garage'),
align = 'top-left',
elements = elements,
},
function(data, menu)
if not doesVehicleExist then
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(_U('not_enough_money'))
end
end)
else
--add notify here
end
end,
function(data, menu)
menu.close()
--CurrentAction = 'open_garage_action'
end
)
end)
end
FindVehicleByPlate = function(plate) -- in client.lua
local gameVehicles = ESX.Game.GetVehicles()
for i = 1, #gameVehicles do
local vehicle = gameVehicles[i]
if DoesEntityExist(vehicle) then
if Config.Trim(GetVehicleNumberPlateText(vehicle)) == Config.Trim(plate) then
return vehicle
end
end
end
return nil
end
Config.Trim = function(value) -- inconfig.lua
if value then
return (string.gsub(value, "^%s*(.-)%s*$", "%1"))
else
return nil
end
end
You can use this code in any garage script if you know it
any frame works have a some native like ESX.Game in esx frame work
QB.Game in qbcore you can see this natives in your server files
For me, the car problem, this is a general problem. If a programmer sees it and understands it, he will use this code and put it in his script, do not complicate it
I really don’t understand why we are all so rude last time, this are 2 function and it’s a free fix, first of all you need to say thank you to this guy and later “can you help me with qb?” We are not robot and not flag, sometimes some kind words can do better this forum.
Anyway Thank you Konar, I think I had also this problem so I will check your code and test it, thanks man
Thank you very much, man. I was trying to explain this to them. This problem was always facing me, and when I found a solution to it, I did not always hesitate to share this solution to the audience of FiveM. @strianodev