Lusty94
Tebex StoreSupport DiscordGitHubCFX Profile
  • 👋 Lusty94 Scripts
  • 💵Store Discounts
  • 📥 Script Installation
  • 🤝Supported Scripts
  • 📜Paid Resouces
    • 🍻Bars
      • 🔧Changelogs
      • 💼 Jobs
      • 📦Stashes
      • 👁️Blips
      • 🧩Props
      • 👆Interaction Locations
      • 📸CCTV
      • 🍳Recipes
      • 📬Supplies
      • 🥦Ingredients
    • 🍁Weed Shops
      • 🔧Changelogs
      • 💼 Jobs
      • 📦Stashes
      • 👁️Blips
      • 🧩Props
      • 👆Interaction Locations
      • 🍃Picking
      • 📸CCTV
      • 🍳Recipes
      • 📬Supplies
      • 🥦Ingredients
      • 🚬Consumables
    • 💲Money Wash
    • 💰Pawn Shop
      • 🔧Changelogs
      • 🛒Pawnshop Locations
    • 📲Drug Sales
      • 🔧Changelogs
      • 📲Selling
      • 💻Default Configuration
    • 🚗Chop Shop
      • 🔧Changelogs
      • 📅SQL
      • 🗣️Commands
      • 📋Reputation
      • 💰Selling
      • 🚗Chop Shops
      • 💻Default Configuration
    • 🚘Vehicle Shop
      • 🔧Changelogs
      • 📅SQL
      • 🗣️Commands
      • 📥Database
      • 🚘Vehicle Shops
      • 💻Default Configuration
    • 🚗Rental
    • 🚙Towing
    • 🍲Restaurants
    • 💊Drugs
    • 🍁Weed
  • 📜Free Resources
    • 🛒Shops
      • 🔧Changelogs
      • 🛒Adding Shops
      • 🪛Configuration
    • 🖥️Boss Menu
      • 🔧Changelogs
      • 💻Adding Job Locations
    • ✅Green Zones
      • 🔧Changelogs
      • 📌Adding Zones
Powered by GitBook
On this page
  1. Paid Resouces
  2. Vehicle Shop

Database

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

Last updated 17 days ago

📜
🚘
📥
Page cover image