cc_supply: exports, events and hooks
Everything another resource can call or listen to. All exports are server side. Read exports never describe a depot that is closed (surveyed = false); they return nil.
Everything another resource can call or listen to. All exports are server side. Read exports never describe a depot that is closed (surveyed = false); they return nil.
Read exports
| Export | Returns |
|---|---|
exports.cc_supply:GetPrice(depot, item) | { bid, ask, band } or nil. depot is a depot id ('ls_docks') or index. ask is nil on a sell-only line. band is one of 'short', 'low', 'ok', 'high', 'glut' (stock against target; never the exact stock). |
exports.cc_supply:GetBoard(depot) | The board rows the counter page shows (label, bid, ask, band, sparkline per line), or nil. |
exports.cc_supply:GetIndex() | Number: 100 = depot prices at base, above 100 the market is short, below glutted. nil while closed or with no open depot. |
local p = exports.cc_supply:GetPrice('ls_docks', 'steel')
if p then print(('steel: bid $%d, ask $%s, %s'):format(p.bid, tostring(p.ask), p.band)) endCourier contract exports
For a courier/trucking resource. Only resources listed in ServerConfig.Contracts.trusted may call the mutating ones (checked with GetInvokingResource). src is the courier's server id, taken from your server event, never from a client payload.
| Export | Arguments | Returns |
|---|---|---|
ListContracts(filter) | filter = { depot?, vehicleClass?, minPay? } | array of contract views |
GetContract(id) | contract id 'SUP-<order>-<depot>' | contract view or nil |
ClaimContract(src, id) | courier, contract | ok, err |
LoadContract(src, id, netId, trailerNetId?) | courier, contract, the carrier vehicle's net id (and trailer for a flatbed) | ok, err |
DeliverContract(src, id) | courier, contract | ok, paid, err |
AbandonContract(src, id) | courier, contract | ok |
A contract view is:
{
id, kind = 'order'|'transfer'|'backhaul', orderId, status = 'open'|'claimed'|'loaded'|...,
origin = { depot, label, coords } or { businessId, label, coords },
destination = { depot, label, coords } or { businessId, label, coords },
cargo = { { item, label, count } }, cargoKg, vehicleClass = 'van'|'box'|'flatbed',
pay, minSeconds, expiresAt, plate, by, paid, condition,
risk = { hijackable, policeAlert },
}Errors you can get back: closed, not_trusted, not_found, not_open, expired, already_active, own_business, no_player, not_yours, not_at_origin, vehicle_not_at_origin, wrong_vehicle, wrong_trailer, no_vehicle, too_fast, not_at_destination, busy, pay_failed, offline. The server enforces the load radius, the delivery radius, the minimum drive time (road distance at maxSpeed plus floorSeconds) and the vehicle class.
Rail exports (a train resource)
railOffers(depotId), railReserve(id, runId), railDeliver(id, runId), railRelease(id, runId, reason): a train hauls open transfer contracts. Only resources in ServerConfig.Rail.trusted. cc_supply pays nothing for a rail haul.
Conversion exports (cc_business)
ReserveForBusiness(businessId, item, qty, ref) -> ok, { unit, total, depot } | err, CommitReservation(ref), ReleaseReservation(ref). Only resources in ServerConfig.Convert.trusted. Used by cc_business to stock catalogue items from depot stock.
Server events (listen with AddEventHandler)
Contract lifecycle, payload = the contract view above:
cc_supply:contract:created cc_supply:contract:claimed cc_supply:contract:loaded
cc_supply:contract:delivered cc_supply:contract:failed cc_supply:contract:hijacked
cc_supply:contract:expiredAfter every completed action (also delivered as hooks of the same name):
| Event | Payload |
|---|---|
cc_supply:server:sold | source, depot, item, units, total |
cc_supply:server:bought | source, depot, item, units, total |
cc_supply:server:orderPosted | source, order, business, depot, item, units, total |
cc_supply:server:orderFilled | source, order, business, depot, item, units, total |
cc_supply:server:greySold | source, depot, crates, paid |
These are server-local events: a client can never trigger them.
Hooks (cc_lib)
Register from your own server code (or custom/server.lua). A before* hook that returns false refuses the action; nothing a hook returns is ever used as a price, amount or permission. Payloads are copies.
| Hook | Cancellable | Payload |
|---|---|---|
beforeSell | yes | source, depot, item, units, total |
beforeBuy | yes | source, depot, item, units, total |
beforeOrderPost | yes | source, business, depot, item, units, total |
beforeFill | yes | source, order, business, depot, item, units, total |
beforeHijack | yes | source, contract, item, units |
beforeGreySale | yes | source, depot, crates, value |
sold, bought, orderPosted, orderFilled, greySold | no | as the events above |
-- In another resource:
exports.cc_supply:registerHook('beforeBuy', function(p)
if p.item == 'tungstenore' and not IsPlayerAceAllowed(p.source, 'supply.vip') then return false end
end)exports.cc_supply:getHooks() lists every hook with its payload; removeHook(id) removes one.
Adapters you can replace
| File / key | What it decides |
|---|---|
server/business.lua (open) | What a business is, who may order, labels, owners, delivery bays, delivery |
ServerConfig.Integrations.cad.send | Sending police alerts to your CAD/MDT |
ServerConfig.Integrations.gangs.* | Gang sanctions on hijacks, turf tax and respect on back-door sales |