
π₯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
},--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 ))
endLast updated