Skip to content

Dealership Creator — Hooks & Events ​

Hooks let you add your own rules to the script, or react when something happens, without editing the escrowed code. They work like ox_inventory's registerHook.

  • Before hooks run before something happens. Return false to stop it.
  • After events run once it has happened. Use them for logs, XP, rewards, taxes, MDTs or phone apps.

All hooks run on the server.

WhereFor
bridge/hooks/server.luaServer owners. This file is not escrowed and has an empty function for every hook. Fill in the ones you need.
exports.fwb_dealerships:registerHook(...) and AddEventHandler('fwb_dealerships:...')Other resources

NOTE

Developer note: these open functions are for your own rules and integrations. FWB Studio does not support third-party code written inside them.


Stopping Something ​

In bridge/hooks/server.lua ​

lua
function before.buy(data)
    if data.model == 'rhino' then
        return false, 'This one is not for sale to civilians'   -- the player sees this text
    end
    return true
end

From another resource ​

lua
local id = exports.fwb_dealerships:registerHook('buy', function(data)
    if not exports.my_licenses:Has(data.source, 'driver') then
        return false, 'You need a driving licence first'
    end
end, {
    shopFilter = { 'pdm' },             -- only these dealerships (their id)
    modelFilter = { 'adder', 't20' },   -- only these cars (spawn names)
    print = true,                       -- print each time it runs (for testing)
})

exports.fwb_dealerships:removeHooks(id)   -- that hook
exports.fwb_dealerships:removeHooks()     -- every hook of your resource

How they run ​

Rule
OrderThe open file first, then registered hooks in the order they were added.
StoppingThe first hook that returns false stops it. Its second return value is shown to the player; without one they see "You cannot do that right now".
Going onReturning nothing or true lets it go on.
ErrorsA hook that throws an error lets the action go on, and the error is printed.
Moneybuy, financePay, buyShop, stockOrder and truckTake run before any money is taken, so stopping them never costs anything.
Clean-upWhen your resource stops, its hooks are removed.
SpeedKeep hooks quick: they run inside the action. The console warns when one takes longer than 100 ms.

Before Hooks ​

HookWhendata
buyBefore a car is paid: in full, financed, or through an employee's sale slipsource, identifier, name, shop, shopLabel, model, label, price (car + paint), payNow (taken now), method (cash / bank), paid (cash / bank / finance / society / free), financed, seller
spawnVehicleBefore the bought car appears at the delivery spot. false = it stays in the player's garage (it is already theirs).source, shop, model, label, plate
testDriveBefore any test drive starts (alone, with friends, or an employee's drive)source (driver), shop, model, label, seconds, people (server ids)
financePayA player pays ahead in My finance (timed payments don't ask)source, contract, plate, model, amount, method, payOff
buyShopA player buys a dealership from the city or from its ownersource, shop, shopLabel, price, method, from (city / player), seller
stockOrderA boss or employee orders stock (the shop account pays)source, shop, cars ({ model, copies }), copies, cost
truckTakeA driver takes a truck deliverysource, shop, order, from (board / pickup)

Examples ​

lua
-- cars above 500 000 only for players with a VIP role
function before.buy(data)
    if data.price > 500000 and not exports.my_vip:IsVip(data.source) then
        return false, 'This car is for VIP members'
    end
end

-- no test drives at night
function before.testDrive(data)
    local hour = tonumber(os.date('%H'))
    if hour < 6 then return false, 'Test drives start at 6 in the morning' end
end

After Events ​

Each one runs after.<event>(data) in the open file, then fires the server event fwb_dealerships:<event>.

EventWhendata
vehicleBoughtA car was sold, paid and written to the player's vehiclessource, identifier, name, shop, shopLabel, model, label, plate, price, payNow, paid, financed, seller, commission
vehicleSpawnedThe bought car appeared with the buyer in it (keys given)source, shop, model, label, plate, entity, netId
testDriveStartedA test drive startedsource, shop, model, label, seconds
testDriveEndedA test drive ended (time, left, area, staff, damaged)source, shop, model, label, reason
financePaidA finance payment was paid (timed, or ahead)source, identifier, contract, plate, model, amount, paidOff, ahead
financeMissedA timed payment failedsource, identifier, contract, plate, model, missed, left
vehicleRepossessedA financed car was taken backsource (nil when offline), identifier, contract, plate, model
shopBoughtSomeone bought a dealershipsource, identifier, name, shop, shopLabel, price, from, seller
stockOrderedStock was orderedsource, shop, cars, cost
truckDeliveredA truck driver delivered a load and was paidsource, shop, order, cars, pay, deposit, trip, trips

Examples ​

lua
-- give the buyer a registration paper
AddEventHandler('fwb_dealerships:vehicleBought', function(data)
    exports.ox_inventory:AddItem(data.source, 'car_papers', 1, { plate = data.plate, model = data.label })
end)

-- a full tank in every car driven out of the dealership
function after.vehicleSpawned(data)
    Entity(data.entity).state:set('fuel', 100, true)
end

FWB Studio documentation.