NUI contract ​
The contract between the Lua client, the web UI (web/) and the server RPCs behind it. The wire types are mirrored in
web/src/lib/types.ts and checked by web/scripts/check-contract.mjs. You only need this page to change the UI or
write your own front end; resources that work with machines use the exports.
The NUI is server-authoritative: it only sends intents. Positions come from the server, prices, stock, money and items from the stores and bridges. The client never sends an outcome or a price, and the client's spacing check only draws.
Messages ​
Lua → NUI: SendNUIMessage({ action, data }).
| Action | Data |
|---|---|
init |
{ locale, strings?, config: { currency, drinkNow, breakIn, phone: boolean } } |
screen:open / screen:update / screen:close |
{ id, data } / { id, data } / { id? } |
toast / prompt:show / prompt:hide / progress:start / progress:cancel |
Fallbacks while np_hud isn't running. prompt:show { id, icon?, tint?, keys = { { key, label } }, hold? }, progress:start { id, label, icon?, tint?, duration (ms), value? } |
theme |
{ brand?, strength, material }: np_admin's server theme, sent as { action = 'theme', type = 'theme', data } by bridge/np_admin.lua at start, on every change and again on ui.ready |
NUI → Lua: one callback, https://np_vending/rpc, with { method, params }. It answers { ok: true, data } or
{ ok: false, error }. ui.* methods (and a few others below) are client-local; everything else is forwarded to the
server RPC dispatcher, rate-limited per player (Config.Rpc). Every error code has a text in English and German.
Screens ​
web/src/screens/<id>:
| id | Focus | Data |
|---|---|---|
machine |
full | MachineView |
peek |
none (overlay) | PeekView (the prompts are drawn by Lua / np_hud) |
service |
full | ServiceView |
placement |
pick: full, place: none |
PlacementView |
dashboard |
full | DashboardView |
admin |
full | AdminView (staff red glass) |
noise |
none | { hold: number, noise: number, alarm: boolean } |
Esc on a focused screen sends ui.close; the pick step's Cancel sends place.cancel.
RPC methods ​
ui.ready | ui.close {id?} client-local
machine.buy { machine, slot, qty, pay, consume? } -> Receipt (consume = "drink now")
machine.watch { machine, slot } -> true (notify me, toggles)
machine.tray { machine } -> number (take tray items)
world.buy { machine } -> MachineView (buy a listed / city machine)
service.open { machine } -> ServiceView
service.setSlot { machine, slot, item?, price?, offer?, locks?, capsule? } -> ServiceView
service.fill { machine, slot, amount } -> ServiceView (items from the player's inventory)
service.unload { machine, slot } -> ServiceView
service.collect { machine } -> number
service.settings { machine, patch } -> ServiceView (name, pay toggles, status on/off)
service.upgrade { machine, upgrade } -> ServiceView (lock | alarm | camera | insurance)
service.repair { machine } -> ServiceView
service.pickup { machine } -> true (machine -> crate item, stock -> inventory)
owner.overview { operator? } -> DashboardView
owner.toggle { machine, key: 'active'|'card'|'cash'|'phone', value } -> MachineRow
owner.price { machine, slot, price, offer? } -> true
owner.route { operator?, ids? } -> Route
owner.gps { machine } -> true
owner.postRoute { operator?, reward, ids? } -> JobRow
owner.cancelJob { job } -> true
owner.keyGrant { machine|0, operator?, target (server id or identifier), perms } -> KeyRow[]
owner.keyRevoke { machine|0, operator?, identifier } -> KeyRow[]
owner.list { machine, price, kind, hours?, stock } -> Listing
owner.unlist { machine } -> true
owner.payRent { machine } -> number
market.list {} -> { listings: Listing[], spots: { zone, label, free, rent, traffic }[] }
market.buy { machine } -> true
market.bid { machine, amount } -> Listing
jobs.list {} -> JobRow[]
jobs.take { job } -> JobRow
place.models {} -> PlacementView (step 'pick')
place.select { model } -> true (client-local: start the ghost, step 'place')
place.check { model, coords, heading } -> { checks: Check[], spot, cost, freeSpot }
place.confirm { model, coords, heading } -> MachineRow
place.cancel {} -> true (client-local + server tidy)
admin.view {} -> AdminView
admin.setRules { rules } -> AdminView (applies live, stored in vend_meta)
admin.saveZone { zone } -> AdminView
admin.deleteZone { id } -> AdminView
admin.zonePoint {} -> { x, y } (the admin's current position)
admin.machine { id, action: 'tp'|'reset'|'remove'|'repair'|'restock'|'sell', price? } -> AdminView
admin.export {} -> string (config.lua snippet)
Clearing a value (service.setSlot item / offer / locks, owner.price offer) is sent as false, never null: JSON
null arrives in Lua as nil, which means "not sent". Offers travel as { price, until } (unix seconds).
The client-local machine.buy wraps the server call: after the receipt it refreshes the machine screen, or, when the
purchase jammed, closes it and shows the jam prompt.
Lua-side RPCs ​
The client Lua calls these on key presses in the world. They are not called by the NUI.
machine.open { machine } -> MachineView (E at a machine)
machine.peek { machine } -> PeekView (walking up)
machine.again { machine } -> Receipt (G "same again")
machine.last { machine } -> { slot, qty, pay, label, price } | false
machine.shake { machine } -> { fell, tray?, item?, label? }
machine.refund { machine } -> number
world.claim { model, coords } -> { id, code } (first contact with a map prop)
crime.begin { machine, kind = 'breakin'|'vandalism' } -> { token, duration, noiseMs, alarm, kind }
crime.finish { token } -> { kind, loot?, alarmed }
crime.cancel { token } -> true
crime.canSkim { machine } -> boolean (may this player install a skimmer here)
crime.skim { machine } -> true
owner.withdraw { operator, amount } -> number
dashboard.place { model? } -> true (client-local: close the dashboard, start placement)
dashboard.route { operator?, ids? } -> Route (client-local: owner.route + GPS to the first stop)
admin.close {} -> true (client-local)
Server → client events: np_vending:init | machine | removed | rules | access | notify | waypoint | teleport | drink | dashboard | placement | nui. Player machines are client-side props (not networked), spawned within
Config.Ui.streamDistance from a synced list of public data only (no cash, no operator identifiers).
Types ​
type Tint = 'red'|'orange'|'rust'|'pink'|'olive'|'lilac'|'green'|'blue'|'aqua'|'neutral'
type Pay = 'cash'|'card'|'phone'
interface SlotView { slot: string; item: string|null; label: string; icon: string; tint: Tint; amount: number; capacity: number;
price: number; offer?: { price: number; until: number } | null; locked?: string | null /* reason for THIS player */;
effect?: string /* 'Thirst +25' */; weight?: number; capsule?: boolean; watching?: boolean }
interface MachineView { id: number; code: string; label: string; model: string; icon: string; tint: Tint;
operator: { key: string; name: string; city: boolean }; status: 'active'|'off'|'broken'|'unpaid';
restockedAt?: number; rows: number; cols: number; slots: SlotView[]; pay: Record<Pay, boolean>;
player: { cash: number; thirst?: number; hunger?: number }; stamps?: { count: number; every: number } | null;
tray: { item: string; label: string; icon: string; tint: Tint; count: number; until: number }[];
drinkNow: boolean; isOwner: boolean; maxQty?: number /* Config.Purchase.maxQty */; forSale?: PeekView['forSale'];
jam?: { item: string; label: string; icon: string; tint: Tint; count: number; paid: number; slot: string } | null }
interface Receipt { machine: number; slot: string; label: string; qty: number; total: number; pay: Pay;
stamp?: { count: number; every: number; free: boolean }; tray?: number; jammed?: boolean;
item?: string; unit?: number; consumed?: 'inventory'|'effect' }
interface ServiceView extends MachineView { cash: number; cashMax: number; cardPending: number; settings: any; upgrades: any;
inventory: { item: string; label: string; icon: string; tint: Tint; count: number }[] /* stockable items carried */;
allowed: string[]; perms: { restock: boolean; collect: boolean; price: boolean; owner: boolean };
sale: any | null; log: LedgerRow[]; items?: { item: string; label: string; icon: string; tint: Tint; price: number;
floor?: number; ceiling?: number }[]; repairCost?: number; rent?: number; rentUntil?: number; world?: boolean }
interface PeekView { id?: number; code?: string; label: string; icon: string; tint: Tint; operator: string; status: string;
pay: Record<Pay, boolean>; soldOut: number; offers: number;
forSale?: { price: number; rent: number; traffic: 1|2|3; avg7: number; kind: 'sale'|'auction'; ends?: number; bid?: number;
stock?: boolean } | null; model?: string; slots?: number; buying?: boolean }
interface Check { rule: 'sameOwner'|'otherOwner'|'sameTypeOther'|'worldMachine'|'shop'|'zone'|'limit'|'surface'|'staffZone';
ok: boolean; need?: number; have?: number; label: string; detail?: string; near?: { x: number; y: number; z: number } }
interface PlacementView { step: 'pick'|'place'; models: ModelInfo[]; selected?: string; owned: number; max: number;
checks: Check[]; spot?: { traffic: 1|2|3; est: number; rivals: number };
cost: { machine: number; permit: number; rent: number; due: number };
freeSpot?: { x: number; y: number; z: number; dist: number } | null; operator?: string;
operators?: { key: string; name: string }[]; enabled?: boolean; ok?: boolean;
zone?: { id: string; label: string; placement: string } | null }
interface MachineRow { id: number; code: string; label: string; model: string; icon: string; tint: Tint; zone: string;
stock: number /* % */; empty: number; slots: number; cash: number; cashPct: number; today: number;
status: 'active'|'off'|'broken'|'unpaid'; note?: string; coords: { x: number; y: number; z: number };
slotList?: SlotView[]; pay?: Record<Pay, boolean> }
interface DashboardView { operator: { key: string; name: string; role: string }; operators: { key: string; name: string }[];
account: number; kpis: { today: number; yesterday: number; cash: number; fullBoxes: number; empty: number; slots: number;
lostPerDay: number; margin: number }; machines: MachineRow[]; max: number; sales14: { day: string; amount: number }[];
best?: string; peak?: string; route: Route | null; keys: KeyRow[]; ledger: LedgerRow[]; listings: Listing[]; jobs: JobRow[] }
interface Rules { sameOwner: number; otherOwner: number; sameTypeOther: number; worldMachine: number; shop: number;
groupCountsAsOwner: boolean; perPlayer: number; perCompany: number; permitFee: number; tighten: 'keep'|'flag';
modelSpacing?: Record<string, Partial<Pick<Rules,'sameOwner'|'otherOwner'|'sameTypeOther'|'worldMachine'|'shop'>>> }
interface Zone { id: string; label: string; points: { x: number; y: number }[]; placement: 'allowed'|'staff'|'off';
maxMachines?: number; rent?: number; traffic?: 1|2|3;
spacing?: Partial<Pick<Rules,'sameOwner'|'otherOwner'|'sameTypeOther'>>; used?: number }
interface AdminView { rules: Rules; zones: Zone[]; models: ModelInfo[]; machines: MachineRow[];
operators: { key: string; name: string; machines: number }[]; audit: LedgerRow[];
breaches: { id: number; rule: string; have: number; need: number }[]; shops: { label: string; x: number; y: number }[] }
ModelInfo, Route, KeyRow, LedgerRow, Listing and JobRow are in web/src/lib/types.ts.
Phone app ​
web/phone.html → web/dist/phone.html, loaded by np_phone as a custom app. It calls np_phone's app RPCs
(vending.overview, vending.toggle, vending.route, vending.gps, vending.payRent, vending.market,
vending.bid, vending.buy, vending.jobs, vending.take), which run the server RPCs above. Tabs: Machines, Route,
Market, Sales. See Vending app.