Skip to content

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

ExportReturns
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.
lua
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)) end

Courier 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.

ExportArgumentsReturns
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, contractok, 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, contractok, paid, err
AbandonContract(src, id)courier, contractok

A contract view is:

lua
{
    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:expired

After every completed action (also delivered as hooks of the same name):

EventPayload
cc_supply:server:soldsource, depot, item, units, total
cc_supply:server:boughtsource, depot, item, units, total
cc_supply:server:orderPostedsource, order, business, depot, item, units, total
cc_supply:server:orderFilledsource, order, business, depot, item, units, total
cc_supply:server:greySoldsource, 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.

HookCancellablePayload
beforeSellyessource, depot, item, units, total
beforeBuyyessource, depot, item, units, total
beforeOrderPostyessource, business, depot, item, units, total
beforeFillyessource, order, business, depot, item, units, total
beforeHijackyessource, contract, item, units
beforeGreySaleyessource, depot, crates, value
sold, bought, orderPosted, orderFilled, greySoldnoas the events above
lua
-- 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 / keyWhat it decides
server/business.lua (open)What a business is, who may order, labels, owners, delivery bays, delivery
ServerConfig.Integrations.cad.sendSending police alerts to your CAD/MDT
ServerConfig.Integrations.gangs.*Gang sanctions on hijacks, turf tax and respect on back-door sales