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.
exports.cuxial_supply:GetCentrals()Returns: { id: string, label: string, area: 'city'|'county' }[].
GetProducts
Lists every active product.
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.
exports.cuxial_supply:GetStock(central, product)| Parameter | Type | Description |
|---|---|---|
central | string | Market id. |
product | string | Product 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.
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.
exports.cuxial_supply:GetPrices(central)Returns: table<string, { buy, sell, wholesale, retail, stock, cap }> keyed by product id, or nil.
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))
endPurchase
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.
exports.cuxial_supply:Purchase(central, product, amount, meta)| Parameter | Type | Description |
|---|---|---|
central | string | Market id. |
product | string | Product id. |
amount | number | Crates, from 1 to 10000. |
meta | table? | Optional { citizenid, name } written to the ledger. |
Returns: true, cost on success, or false, reason ('payload', 'error_not_ready', 'error_stock').
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
endAddStock
Adds crates to a market, up to its cap.
exports.cuxial_supply:AddStock(central, product, amount, reason)| Parameter | Type | Description |
|---|---|---|
central | string | Market id. |
product | string | Product id. |
amount | number | Crates, from 1 to 100000. |
reason | string? | 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.
| Parameter | Type | Description |
|---|---|---|
central | string | Market id. |
product | string | Product id. |
stock | number | New stock. |
delta | number | Change, positive or negative. |
reason | string | 'deliver', 'purchase', 'admin', 'add', 'consume' or 'restock'. |
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.
| Parameter | Type | Description |
|---|---|---|
src | number | Server id of the player. |
store | string | Supermarket id. |
data.units | number | Units in the basket. |
data.total | number | Value of the basket. |
data.lost | number | Units that could not go back to a shelf. |
data.restocked | boolean | Whether the products were put back on the shelves. |
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.
function CuxialSupply.hooks.onFinish(src, data)
-- your code
end| Parameter | Type | Description |
|---|---|---|
src | number | Server id of the player who was paid. |
data.runId | number | Id of the run in cuxial_jobs_runs. 0 if it could not be saved. |
data.region | number | Line id from data/regions.lua. |
data.score | number | Tasks done by this player. |
data.money | number | Money paid to this player. |
data.xp | number | XP given to this player. |
data.owner | string | Character 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'.
| Table | Content |
|---|---|
cuxial_jobs_players | One row per character: level, xp, daily progress. |
cuxial_jobs_runs | Finished runs: region, owner, crew_size, outcome, start and end time. |
cuxial_jobs_run_members | What each member did and earned in a run. |
cuxial_supply_stock | Stock per market and product. |
cuxial_supply_ledger | Ledger of deliveries, purchases and stock changes. |
cuxial_supply_history | Price history of the markets. |
