Skip to content

Exports & events

Public API of Cuxial Supply: server exports of the wholesale markets, server events and the hook that runs when a run is paid.

Read the wholesale markets from your own resources, react to stock changes and to unpaid baskets, and run your code when a run is paid. Everything here is server side. Cuxial Supply has no client exports.

The market exports only see active wholesale markets. The included ones come disabled, so GetCentrals() returns an empty list until staff turn one on in the editor.

Server exports ​

GetCentrals ​

Lists the active wholesale markets.

lua
exports.cuxial_supply:GetCentrals()

Returns: { id: string, label: string, area: 'city'|'county' }[].

GetProducts ​

Lists every active product.

lua
exports.cuxial_supply:GetProducts()

Returns: { id, label, category, unit, item, units, origin }[]. item is the inventory item and units the units of it per crate.

GetStock ​

Returns the crates of a product a market holds.

lua
exports.cuxial_supply:GetStock(central, product)
ParameterTypeDescription
centralstringMarket id.
productstringProduct id.

Returns: number, or nil when the market does not hold that product or is not ready.

GetPrice ​

Returns the current prices of one crate.

lua
exports.cuxial_supply:GetPrice(central, product)

Returns: { buy, sell, wholesale, retail }, or nil. buy is what the market pays for a crate now, sell what it charges, wholesale and retail the prices at its terminal for wholesale jobs and in shops.

GetPrices ​

Returns the prices and stock of every product of a market.

lua
exports.cuxial_supply:GetPrices(central)

Returns: table<string, { buy, sell, wholesale, retail, stock, cap }> keyed by product id, or nil.

lua
local prices = exports.cuxial_supply:GetPrices('paleto')
if prices and prices.eggs then
    print(('Eggs: %d crates, paid at $%d'):format(prices.eggs.stock, prices.eggs.buy))
end

Purchase ​

Takes crates out of a market's stock at its sell price, crate by crate, and records the sale. It does not charge the player or give items: your resource does that with the returned cost.

lua
exports.cuxial_supply:Purchase(central, product, amount, meta)
ParameterTypeDescription
centralstringMarket id.
productstringProduct id.
amountnumberCrates, from 1 to 10000.
metatable?Optional { citizenid, name } written to the ledger.

Returns: true, cost on success, or false, reason ('payload', 'error_not_ready', 'error_stock').

lua
local ok, cost = exports.cuxial_supply:Purchase('paleto', 'flour', 2, { citizenid = cid, name = name })
if ok then
    -- charge `cost` to the buyer and give the goods
end

AddStock ​

Adds crates to a market, up to its cap.

lua
exports.cuxial_supply:AddStock(central, product, amount, reason)
ParameterTypeDescription
centralstringMarket id.
productstringProduct id.
amountnumberCrates, from 1 to 100000.
reasonstring?Text written to the ledger.

Returns: true, stock with the new stock, or false, reason.

Server events ​

Local server events, listened to with AddEventHandler.

cuxial_supply:server:StockChanged ​

Fires every time the stock of a product changes in a wholesale market.

ParameterTypeDescription
centralstringMarket id.
productstringProduct id.
stocknumberNew stock.
deltanumberChange, positive or negative.
reasonstring'deliver', 'purchase', 'admin', 'add', 'consume' or 'restock'.
lua
AddEventHandler('cuxial_supply:server:StockChanged', function(central, product, stock, delta, reason)
    if stock == 0 then
        print(('%s ran out of %s'):format(central, product))
    end
end)

cuxial_supply:server:BasketUnpaid ​

Fires when a customer leaves a supermarket with an unpaid basket.

ParameterTypeDescription
srcnumberServer id of the player.
storestringSupermarket id.
data.unitsnumberUnits in the basket.
data.totalnumberValue of the basket.
data.lostnumberUnits that could not go back to a shelf.
data.restockedbooleanWhether the products were put back on the shelves.
lua
AddEventHandler('cuxial_supply:server:BasketUnpaid', function(src, store, data)
    -- send a police alert, add a wanted level...
end)

Hook: onFinish ​

server/hooks.lua is an open file. Its onFinish function runs once for each paid crew member when a run ends. Write your code inside it.

server/hooks.lua
lua
function CuxialSupply.hooks.onFinish(src, data)
    -- your code
end
ParameterTypeDescription
srcnumberServer id of the player who was paid.
data.runIdnumberId of the run in cuxial_jobs_runs. 0 if it could not be saved.
data.regionnumberLine id from data/regions.lua.
data.scorenumberTasks done by this player.
data.moneynumberMoney paid to this player.
data.xpnumberXP given to this player.
data.ownerstringCharacter identifier of the crew owner.

An error inside the hook is caught and printed to the server console. The payment is not affected.

Database ​

Read-only queries are safe on these tables. Rows of this job in the cuxial_jobs_* tables have job = 'supply'.

TableContent
cuxial_jobs_playersOne row per character: level, xp, daily progress.
cuxial_jobs_runsFinished runs: region, owner, crew_size, outcome, start and end time.
cuxial_jobs_run_membersWhat each member did and earned in a run.
cuxial_supply_stockStock per market and product.
cuxial_supply_ledgerLedger of deliveries, purchases and stock changes.
cuxial_supply_historyPrice history of the markets.

© Cuxial