opx_infinitydealership
Server
Last updated on
The dealership contract on the server — sell, offer, accept, and read stock, dealers and company balances.
local dealership = OPX.Api.Get('dealership')From server code inside opx_infinity.
Buy
A counter sale. Takes the money. Yields.
dealership.Buy(source, dealerKey, entryKey, garageKey)Parameters
- source:
integer - dealerKey?:
string— nil: the dealer underfoot. - entryKey:
string— aSTOCKkey. - garageKey?:
string— the garage to file it under; nil: the vehicles default. Unknown:dealership.noSuchGarage.
Returns
Result{ plate, entry, model, dealer, label, garage?, price, currency, spawned, keyed }spawned: handed over.keyed: a key was cut or already held.
- Errors: the refusal codes.
local sold = dealership.Buy(source, nil, 'hella')
if sold.ok then print(sold.value.plate) endOffer
Records an offer and sends it to the buyer. Charges nothing. One pending offer per buyer; a new one replaces it.
dealership.Offer(seller, buyer, entryKey)Parameters
- seller:
integer - buyer:
integer - entryKey:
string
Returns
Result{ buyer, token, entry, price, cut, company, dealer }
Accept
The buyer's answer to an offer; where the money moves. Re-checks everything. Charges the buyer, banks the company share, pays the seller. Yields.
dealership.Accept(buyer, token, yes, destKey)Parameters
- buyer:
integer - token:
number— the offer's own token; a stale one answersdealership.noOffer. - yes:
boolean— anything buttruedeclines. - destKey?:
string— the buyer's garage, resolved in the buyer's bucket; nil: the vehicles default. Unknown:dealership.noSuchGarage.
Returns
Result— theBuyvalue pluscommission,banked,paid
local done = dealership.Accept(buyer, token, true, 'watson_garage')
if not done.ok then print(done.error) endBalance
A company's balance. Yields.
dealership.Balance(kind, group)Parameters
- kind:
'job' | 'gang' - group:
string
Returns
Result{ kind, group, balance }—0when no row.
local account = dealership.Balance('job', 'ncpd')
if account.ok then print(account.value.balance) endStock
dealership.Stock()Returns
Result{ currency, stock }—stock[key] = { label, class, price, av }
Previews
dealership.Previews()Returns
Result{ previews }—{ key, dealer, entry, model, standing }[]
Spots
Every dealer by key. Not a Result.
dealership.Spots()Returns
table
State
dealership.State()Returns
Result{ dealers, stock, currency, previews, standing }dealers[key] = { kind, label, adopted };stock,previews,standingare counts.