To ensure vehicles are assigned correctly and saved to the database when purchased or financed you can define custom names for the main player vehicles table, and the garage names per type of vehicle in Config.CoreSettings.Database
DataBase = {-- define database information - SOME TABLE NAMES MIGHT BE DIFFERENT LIKE GARAGE_ID INSTEAD OF GARAGE ETC - CHECK THE FUNCTION registerVehicle IN VEHICLESHOP_SERVER.LUA
Vehicles = 'player_vehicles', -- database table name for player vehicles
CarGarage = 'pillboxgarage', -- garage name for cars
BoatGarage = 'lsymc', -- garage name for boats
AirGarage = 'intairport', -- garage name for planes
},
IMPORTANT INFORMATION
If you are using a different garage script you may need to change some of the column names in the registerVehicle() function in vehicleshop_server.lua
You may also need to change the column names to suit your garage script
--save vehicle to DB
function registerVehicle(Player, model, plate, financed, financeData)
local vehicleData = QBCore.Shared.Vehicles[model]
local vehicleType = vehicleData and vehicleData.category or 'car'
local tableName = Config.CoreSettings.DataBase.Vehicles
local garage
if vehicleType == 'boats' then
garage = Config.CoreSettings.DataBase.BoatGarage
elseif vehicleType == 'planes' or vehicleType == 'helicopters' then
garage = Config.CoreSettings.DataBase.AirGarage
else
garage = Config.CoreSettings.DataBase.CarGarage
end
local isFinanced = financed and true or false
local totalPrice = vehicleData and vehicleData.price or 0
local downPercent = financeData and financeData.downPaymentPercent or 0.25
local remainingBalance = isFinanced and math.floor(totalPrice * (1 - downPercent)) or 0
local paymentsLeft = isFinanced and (financeData and financeData.payments or 10) or 0
local paymentAmount = paymentsLeft > 0 and math.floor(remainingBalance / paymentsLeft) or 0
local financeTime = isFinanced and os.time() or 0
MySQL.insert(([[INSERT INTO %s
(license, citizenid, vehicle, hash, mods, plate, garage, fuel, state, balance, paymentamount, paymentsleft, financetime)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]]):format(tableName), {
Player.PlayerData.license,
Player.PlayerData.citizenid,
model,
GetHashKey(model),
'{}',
plate,
garage,
100.0,
0,
remainingBalance,
paymentAmount,
paymentsLeft,
financeTime
})
SVDebug(('^3| Lusty94_VehicleShop | DEBUG | INFO | Vehicle Registered | Plate: %s | Model: %s | Owner: %s | Financed: %s | Balance: %s | Payments: %s | PaymentAmount: %s^7'):format( plate, model, Player.PlayerData.citizenid, tostring(isFinanced), remainingBalance, paymentsLeft, paymentAmount ))
end