qbcore-framework / qb-garages

Garage System Used With QB-Core :car:
GNU General Public License v3.0
48 stars 260 forks source link

[BUG] Changing licenceplate in qb-vehicleshop gives "You cant store this vehicle in your garage" #234

Closed linus-jansson closed 2 years ago

linus-jansson commented 2 years ago

Describe the bug The qb-vehicleshop has a generatePlate() function. I changed that to get Swedish format on the licence plate

local function GeneratePlate()
    local plate = QBCore.Shared.RandomStr(3) .. '_' .. QBCore.Shared.RandomInt(3)
    -- local plate = QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(2)
    local result = MySQL.scalar.await('SELECT plate FROM player_vehicles WHERE plate = ?', {plate})
    if result then
        return GeneratePlate()
    else
        return plate:upper()
    end
end

The changed plates work when buying a vehicle however, when trying to store it in qb-garages it says "This vehicle can't be stored" (the not_owned error)

To Reproduce Steps to reproduce the behavior:

  1. Change the plate generator located here to the one shown in the description
  2. Restart the server or resources (qb-garages & qb-vehicleshop)
  3. Buy a car
  4. Try to store it

Expected behavior You should be able to store the vehicle no matter what licenceplate format you have

Questions (please complete the following information):

Additional context I have also remove the check for a specific garage when a player takes out a vehicle to make the garages global which shouldn't affect this issue.

linus-jansson commented 2 years ago

I found the problem. GTA treats underscores as a space. Therefore when checking ownership before storing it thinks the licenseplate is HQK 111 instead of HQK_111 which is stored in the database.. I need to store the licenceplate with a space in the database.

changing the generate plate function to this solves the issue

local function GeneratePlate()
    local plate = QBCore.Shared.RandomStr(3) .. ' ' .. QBCore.Shared.RandomInt(3)
    -- local plate = QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(2)
    local result = MySQL.scalar.await('SELECT plate FROM player_vehicles WHERE plate = ?', {plate})
    if result then
        return GeneratePlate()
    else
        return plate:upper()
    end
end