Global garage

Is there a way to turn QB-garages into a city wide system? So say if i put a car in the garage at legion square then make my way over to the airport garage take it out there?

1 Like

Hey :slight_smile:
I’m not using QB very often so I add to check how the garage works. You have multiple options to do so, an easy one would be to change the SQL query for the ā€˜GetUserVehicles’ callBack in the server side script, like that :

[/[qb]/qb-garages/server/main/lua] (lines 76 to 87):

QBCore.Functions.CreateCallback("qb-garage:server:GetUserVehicles", function(source, cb, garage)
    local src = source
    local pData = QBCore.Functions.GetPlayer(src)
	local state = 1
    exports.oxmysql:execute('SELECT * FROM player_vehicles WHERE citizenid = ? AND state = ?', {pData.PlayerData.citizenid, state}, function(result)
        if result[1] then
            cb(result)
        else
            cb(nil)
        end
    end)
end)

I give it a try after I made the modification, it works on my end.
You can clean a little bit the code by removing the ā€˜garage’ argument that is given to the callBack etc… if you want.

1 Like

Legend thanks dude, ill give it a try when j get back from work and let you know

1 Like

This didnt work for me mate, i use a modified version of qb garages but that just gave me an error instantly

1 Like

I did it on a vanilla version of qb-garage, if yours is modified it must be why it didn’t work.
Can you show me the error ?

1 Like

I dont currently have access to the error code as im at work however here is the code for this:

main.lua (5.1 KB)

I’ll wait until you get back, so you can send me the error screenshot and the whole qb-garage ressource.

If you wish for me to send you the entire qb garage resource i can send you this as i have access to it?

Hi, so ive done it and its working, but im getting the error of

Can you show me the lines between 290 and 310 in the client/main.lua file ?

Sure, this is code from 293 to 310
Menu.addButton(Garages[currentGarage].label, ā€œVehicleListā€, Garages[currentGarage].label)

        for k, v in pairs(result) do
            enginePercent = round(v.engine / 10, 0)
            bodyPercent = round(v.body / 10, 0)
            currentFuel = v.fuel
            curGarage = Garages[v.garage].label


            if v.state == 0 then
                v.state = "Out"
            elseif v.state == 1 then
                v.state = "Garaged"
            elseif v.state == 2 then
                v.state = "Impound"
            end

These are the only 2 resources that actually have anything in, which is server:main.lua and client:main.lua
main.lua (5.1 KB)
main.lua (36.1 KB)