Skip to content

Server Exports ​

Call these from any server script.

Name in this pageWhat to pass
srcA player's server id
whoA server id (online player) or a framework identifier (char1:..., citizenid, license)
plateOrVehicleA plate ('AB 123'), or a vehicle entity or its network id

Plates and owners are read from the owned-vehicles table set in Settings → After a sale (ESX owned_vehicles, QBCore / Qbox player_vehicles, or your own). GTA's padding spaces don't matter.


Plates & Owners ​

GenerateVehiclePlate

A new plate in the format of Settings → Plates that no owned vehicle has yet.

lua
local plate = exports.fwb_dealerships:GenerateVehiclePlate()  -- 'AB 123', or nil when none was found
PlateAlreadyExists

Is this plate already on an owned vehicle?

lua
if exports.fwb_dealerships:PlateAlreadyExists('AB 123') then ... end
GetVehicleOwner

The identifier that owns the vehicle, or nil. A job vehicle answers the job / gang name (as set in Settings → After a sale).

lua
local owner = exports.fwb_dealerships:GetVehicleOwner(plateOrVehicle)
IsVehicleOwnedBy

Does this player own the vehicle?

lua
local mine = exports.fwb_dealerships:IsVehicleOwnedBy(plateOrVehicle, who)
GiveVehicle

Gives an online player a vehicle, written to the owned-vehicles table like a purchase (no money, no dealership). It is logged with the admin actions (Logs page).

lua
local plate, err = exports.fwb_dealerships:GiveVehicle(src, 'adder', {
    plate = 'PRIZE 1',      -- optional: your own plate (max 8 characters); default = a new one
    garage = true,          -- true = parked in the garage (default), false = marked as out
    paint = { primary = 27, secondary = 0, livery = 1 },  -- optional
})

Returns the plate, or nil and a reason: no_player, no_model, bad_plate, plate_taken, insert_failed. Nothing is spawned.


Dealerships & Cars ​

GetDealerships / GetDealership

Every dealership, or one by id.

lua
local list = exports.fwb_dealerships:GetDealerships()
local pdm = exports.fwb_dealerships:GetDealership('pdm')
-- { id, label, enabled, kind = 'server' | 'job' | 'player', owner = { identifier, name },
--   forSale, price, open, balance (player-owned shops) }
GetDealershipVehicles

What a dealership sells, with its own prices.

lua
local cars = exports.fwb_dealerships:GetDealershipVehicles('pdm')
-- { { model, label, brand, category, type, price, stock (nil = unlimited) }, ... }
GetVehiclePrice / GetVehicleData

A car's price at a dealership (its own prices), or the catalogue price without a dealership. And a car's catalogue entry.

lua
local price = exports.fwb_dealerships:GetVehiclePrice('adder', 'pdm')
local data = exports.fwb_dealerships:GetVehicleData('adder')  -- { model, label, brand, category, type, price }

Shop Accounts ​

GetShopMoney

The money in a player-owned dealership's account, or nil when it isn't player-owned.

lua
local balance = exports.fwb_dealerships:GetShopMoney('pdm')
AddShopMoney / RemoveShopMoney

Money in or out of a player-owned dealership's account (taxes, fines, rewards). It shows in the boss menu's account log with your reason.

lua
exports.fwb_dealerships:AddShopMoney('pdm', 5000, 'City grant')
local ok = exports.fwb_dealerships:RemoveShopMoney('pdm', 2500, 'Business tax')  -- false: not enough money

Both return false when the dealership is not player-owned.


Staff ​

For player-owned dealerships. who can be a server id or an identifier.

IsEmployee

The player's rank at the dealership, or false. The owner's rank id is 'owner'.

lua
local rank = exports.fwb_dealerships:IsEmployee(who, 'pdm')  -- { id, label, boss } or false
HasPermission

May the player do this at the dealership? Permissions: sell, finance, testdrive, display, orders, discounts, announce. Bosses and the owner may do everything.

lua
if exports.fwb_dealerships:HasPermission(src, 'pdm', 'orders') then ... end
GetEmployees

Everyone who works at the dealership, the owner first. nil when it isn't player-owned.

lua
local staff = exports.fwb_dealerships:GetEmployees('pdm')
-- { { identifier, name, rank, rankLabel, onDuty }, ... }

Stock ​

For dealerships with limited stock. On unlimited stock, or for a car the shop doesn't sell, GetVehicleStock gives nil and the others give false.

GetVehicleStock / AddStock / RemoveStock / SetStock
lua
local have = exports.fwb_dealerships:GetVehicleStock('pdm', 'adder')
exports.fwb_dealerships:AddStock('pdm', 'adder', 2)     -- returns the new count
exports.fwb_dealerships:RemoveStock('pdm', 'adder', 1)  -- never below 0
exports.fwb_dealerships:SetStock('pdm', 'adder', 5)

The shop's "n left" updates for everyone.


Sales ​

GetSalesHistory / GetTotalSales
lua
local last = exports.fwb_dealerships:GetSalesHistory('pdm', 20)  -- newest first, 1-500 (default 50)
-- { { at, model, plate, buyer, buyerName, seller, sellerName, price, paid, commission }, ... }
local all = exports.fwb_dealerships:GetTotalSales('pdm')         -- { count, total }

Finance & Test Drives ​

GetPlayerFinances

Every active finance contract of a player, soonest payment first.

lua
local list = exports.fwb_dealerships:GetPlayerFinances(who)
-- { { id, player, plate, model, dealership, total, paid, instalment, count, done, next, missed }, ... }
PayFinance

The player pays on their own contract for this car, as in My finance (the financePay hook and financePaid event run).

lua
-- count: a number or 'all' (pay it off); 'bank' (default) or 'cash'
local ok, why = exports.fwb_dealerships:PayFinance(src, plateOrVehicle, 1, 'bank')
IsVehicleFinanced / GetVehicleFinance

Is the car still being paid off? Car sale and scrap scripts can refuse it.

lua
if exports.fwb_dealerships:IsVehicleFinanced(plateOrVehicle) then return end
local f = exports.fwb_dealerships:GetVehicleFinance(plateOrVehicle)
-- { id, identifier, model, plate, total, paid, left, instalment, done, count, nextDue, missed, shop }
IsTestDriving / IsTestDriveVehicle

Is the player in a test drive, and is this car a test drive car? Garages and car theft scripts can skip them.

lua
exports.fwb_dealerships:IsTestDriving(src)
exports.fwb_dealerships:IsTestDriveVehicle(entityOrNetId)
EndTestDrive

Ends the player's test drive: they are taken back and the car goes. by is the name they see ("ended by ...").

lua
exports.fwb_dealerships:EndTestDrive(src, 'Police')  -- false when they are not in one
IsDeliveryVehicle

Is this vehicle a delivery truck, its trailer or a car on it?

lua
exports.fwb_dealerships:IsDeliveryVehicle(entityOrNetId)

Hooks ​

registerHook

Adds a before hook: your function runs before something happens and can stop it. The list of hooks and their data is on Hooks & Events.

lua
local id = exports.fwb_dealerships:registerHook(name, fn, options)
  • name: buy, spawnVehicle, testDrive, financePay, buyShop, stockOrder or truckTake
  • fn(data): return false (and a text for the player) to stop it; anything else lets it go on
  • options (optional): shopFilter = { 'pdm' } (dealership ids), modelFilter = { 'adder' } (spawn names), print = true

Returns the hook's id, or nil when the name is unknown.

lua
exports.fwb_dealerships:registerHook('buy', function(data)
    if exports.my_licenses:Has(data.source, 'driver') then return true end
    return false, 'You need a driving licence first'
end)
removeHooks
lua
exports.fwb_dealerships:removeHooks(id)  -- that hook
exports.fwb_dealerships:removeHooks()    -- every hook of your resource

A resource can only remove its own hooks, and they are also removed when it stops.

Events ​

React with AddEventHandler('fwb_dealerships:<event>', function(data) ... end): vehicleBought, vehicleSpawned, testDriveStarted, testDriveEnded, financePaid, financeMissed, vehicleRepossessed, shopBought, stockOrdered, truckDelivered. See Hooks & Events.

FWB Studio documentation.