[realease][esx] dublicated cars from any garages scripts solved

client.lua

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

If you have any questions, feel free to let me know
I will be glad if you see my other scripts
car remote system
custom marker
new rp radio ui
police cloackroom
advanced flight job
advanced pc
advanced laptop
my first script
trivor rop house script

4 Likes

So what does tis do exactly? I use esx_eden_garage

1 Like

why does this say standalone when it clearly relies on esx

1 Like

this function from esx_eden_garage

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

and dont forgot to add

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

This is not standalone.

1 Like

Do not complicate it, this is just a word that can be changed according to the files you have

“it’s standalone you just have to convert it to not be esx”

2 Likes

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 :sparkling_heart:

3 Likes

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

2 Likes

What would be the code for esx_drp_garage?

or Give me the script garage and I’ll fix it for you :heart:
@Lavan

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. :heart: @strianodev

esx_drp_garage.rar (12.6 KB)

Thanks for fixing it mate!

@Lavan
esx_drp_garage.rar (12.8 KB)

1 Like

thanks!

1 Like

qb-core just needs to replace ESX.Game.GetVehicles with QBCore.Functions.GetVehicles

1 Like