# qb-garages

1. Navigate to the **qb-garages/client/main.lua**
2. Find the `qb-garages:client:setHouseGarage` event and replace:

```lua
RegisterNetEvent('qb-garages:client:setHouseGarage', function(house) -- event sent periodically from housing
    if not house then return end
    local formattedHouseName = string.gsub(string.lower(house), ' ', '')
    local zoneName = 'house_' .. formattedHouseName
    local hasKey = exports['vms_housing']:HasPermissions(house, 'garage')
    
    if Config.Garages[formattedHouseName] then
        if hasKey and not ZoneExists(zoneName) then
            CreateHouseZone(formattedHouseName, Config.Garages[formattedHouseName], 'house')
        elseif not hasKey and ZoneExists(zoneName) then
            RemoveHouseZone(zoneName)
        end
    else
        if not hasKey then
            return
        end
        local property = exports['vms_housing']:GetProperty(house)
        if not property or not property.metadata or not property.metadata.garage then return end
        local garageCoords = property.metadata.garage
        Config.Garages[formattedHouseName] = {
            houseName = house,
            takeVehicle = vector3(garageCoords.x, garageCoords.y, garageCoords.z),
            spawnPoint = {
                vector4(garageCoords.x, garageCoords.y, garageCoords.z, garageCoords.w)
            },
            label = property.name,
            type = 'house',
            category = Config.VehicleClass['all']
        }
        CreateHouseZone(formattedHouseName, Config.Garages[formattedHouseName], 'house')
    end
end)
```

2. Navigate to the **qb-garages/server/main.lua**
3. Find the `qb-garages:server:getHouseGarage` callback and replace:

```lua
QBCore.Functions.CreateCallback('qb-garages:server:getHouseGarage', function(_, cb, house)
    local property = exports['vms_housing']:GetProperty(house)
    cb(property)
end)
```

4. Find the `qb-garages:server:GetGarageVehicles` callback and replace:

```lua
QBCore.Functions.CreateCallback('qb-garages:server:GetGarageVehicles', function(source, cb, garage, type, category)
    local Player = QBCore.Functions.GetPlayer(source)
    if not Player then return end
    local citizenId = Player.PlayerData.citizenid

    local vehicles
    if type == 'depot' then
        vehicles = MySQL.rawExecute.await('SELECT * FROM player_vehicles WHERE citizenid = ? AND depotprice > 0', { citizenId })
    elseif type == 'house' then
        vehicles = MySQL.rawExecute.await('SELECT * FROM player_vehicles WHERE garage = ?', { garage })
    elseif Config.SharedGarages then
        vehicles = MySQL.rawExecute.await('SELECT * FROM player_vehicles WHERE citizenid = ?', { citizenId })
    else
        vehicles = MySQL.rawExecute.await('SELECT * FROM player_vehicles WHERE citizenid = ? AND garage = ?', { citizenId, garage })
    end
    if #vehicles == 0 then
        cb(nil)
        return
    end
    if Config.ClassSystem then
        local filteredVehicles = filterVehiclesByCategory(vehicles, category)
        cb(filteredVehicles)
    else
        cb(vehicles)
    end
end)
```

5. Find the `qb-garages:server:canDeposit` callback and replace:

```lua
QBCore.Functions.CreateCallback('qb-garages:server:canDeposit', function(source, cb, plate, type, garage, state, propertyId)
    local Player = QBCore.Functions.GetPlayer(source)
    local isOwned = MySQL.scalar.await('SELECT citizenid FROM player_vehicles WHERE plate = ? LIMIT 1', { plate })
    if isOwned ~= Player.PlayerData.citizenid and type ~= 'house' then
        cb(false)
        return
    end
    if state == 1 then
        MySQL.update('UPDATE player_vehicles SET state = ?, garage = ? WHERE plate = ?', { state, garage, plate })
        cb(true)
    else
        cb(false)
    end
end)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.vames-store.com/assets/vms_housing/compatibility/garages/qb-garages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
