NUI contract (Lua ⇄ web) ​
The message contract between the Lua client, the web UI and the server. The full source of truth is
docs/ARCHITECTURE.md in the resource
(§2 core objects, §4 NUI protocol, §5 server and RPC); this page summarises §2.6, §4 and §5.3. You only need it to
change the web UI or write a different front end. Resources that use the exports never touch it.
The rule: the server owns every inventory. The web predicts whether a move fits (to colour the drop target) but never applies one on its own: it asks Lua, Lua forwards to a server RPC, and the server answers with fresh views.
Views ​
type Tint = 'neutral' | 'red' | 'orange' | 'rust' | 'pink' | 'olive' | 'lilac' | 'green' | 'blue' | 'aqua'
interface SlotItem {
slot: number; name: string; label: string; count: number
weight: number // total grams of the slot
metadata: Record<string, unknown>
durability?: number // 0..100: durability or freshness
icon?: string; tint?: Tint; image?: string
isNew?: boolean // arrived since the player last closed the inventory
}
interface InvView {
id: string; type: string; label: string; sublabel?: string; icon?: string; tint?: Tint
slots: number; maxWeight: number; weight: number; items: SlotItem[]
readonly?: boolean
filter?: string[] // pat-down: only these categories are real items
equipSlots?: string[] // equipment: slot names in order
hotbar?: number // player: hotbar size
acceptCategories?: string[]
}
In a pat-down, items outside Config.Police.friskCategories arrive as placeholders
({ slot, name: '__hidden', label: '?', count: 1, weight: 0 }); the real item never leaves the server.
Lua → web: SendNUIMessage({ action, data }) ​
Messages sent before the web posted ready are queued (up to 128, oldest dropped) and flushed after boot.
| action | data |
|---|---|
boot |
{ locale, strings, material, brand?, strength?, scale?, items, categories, config }. items are client-safe item definitions; config carries hotbar size, image path, np_hud on / off, cash mode, give distance, keys, weapon clip sizes, trade countdown and offer slots, extra metadata keys (showMetadataKeys) and their labels (metadataLabels), player limits and rename length. Sent again after a web reload, after displayMetadata and when the framework usable list changes |
inventory:open |
{ player, equipment, secondary?, container?, mode: 'default' | 'rob' | 'frisk' | 'admin', character: { name, id, job? }, money: { cash, bank, black? } } |
inventory:update |
{ inventories: InvView[], money? }: replace those inventories by id |
inventory:container / inventory:secondary |
{ container | secondary: InvView | null }: open, swap or close the bag / right panel |
inventory:close |
{} |
shop:open |
{ shop: { id, label, sublabel?, icon, tint, discount?, items }, player, money } (also after every purchase) |
crafting:open / crafting:update |
{ bench, recipes, queue, now, player, queueMax, maxCount } (update: any subset) |
give:open |
{ item, inv, count, targets: { id, name, known, desc?, distance }[] } |
trade:request |
{ id, from: { name }, distance, expiresIn } |
trade:open / trade:update |
{ id, partner, mine, theirs, countdown?, player } with { items, money, locked, confirmed } per side |
trade:close |
{ reason?, done? } |
document:show |
{ item, from }: ID card popup (8 s or ESC) |
hud:hotbar |
{ slots, selected?, visible, hideAfter? } |
hud:feed |
{ entries: { name, label, icon, tint, delta, money? }[] } (merged within 1.5 s) |
hud:progress / hud:progressCancel |
Fallback progress bar without np_hud |
hud:prompt / hud:promptHide |
Fallback interaction prompt without np_hud |
hud:weight |
{ weight, maxWeight, level: 0 | 1 | 2 }: overload chip |
notify |
{ type, title, message, icon?, tint?, duration? }: fallback toast |
settings |
{ material, locale, strings? } |
Web → Lua: fetch('https://np_inventory/<name>', { method: 'POST', body }) ​
Every callback answers JSON exactly once: { ok: true, … } or { ok: false, code, error } (error = localised
text). After a successful change the server pushes inventory:update; answers can carry inventories too.
| name | body |
|---|---|
ready |
{} → Lua sends boot |
close |
{} |
move |
{ from: { inv, slot }, to: { inv, slot? }, count, expect: { name, count } }. No to.slot = automatic placement, count 0 = whole stack, to.inv = 'ground' = drop |
quick |
{ inv, slot, count? } (Shift-click) |
use |
{ inv, slot } |
action |
{ inv, slot, action, value?, count? }: show, open, unload, detach, rename, split, drop, use or an item action id |
give:targets / give |
{ inv, slot, count } / + target |
sort |
{ inv, by: 'category' | 'weight' | 'name' } |
stack / takeAll / seen |
{ inv } / { from, to } / {} |
container:close |
{} |
frisk:full |
{} (Lua plays the search progress first) |
shop:buy |
{ shop, cart: { index, count }[], pay: 'cash' | 'bank' } |
crafting:start / crafting:cancel / crafting:collect |
{ bench, recipe, count } / { bench, id } / { bench } |
crafting:storage |
{ bench }: Lua closes the bench and opens the inventory with the stash bench:<id> (the Storage button, shown when bench.storage is set) |
trade:respond / trade:offer / trade:lock / trade:confirm / trade:cancel |
{ id, accept } / { slot, count } | { remove } | { money } / { locked } / {} / {} |
settings:set |
{ material?, locale? } (stored in client KVP) |
hud:progressCancel |
{ id } |
expect must match the source slot (name and at least that count), otherwise the move fails with stale and the
client gets fresh views. That's what keeps a lagging client from duplicating items.
Server RPC (client ⇄ server) ​
The client calls NpInv.rpc(name, payload): a request id over the np_inventory:rpc net event, answered on the same
event, with a 10 s timeout. Each RPC is registered with a payload schema, a rate limit and optionally "needs an open
session". The check order: global token bucket (Config.RateLimit) → payload sanity (depth ≤ 4, ≤ 256 keys, strings
≤ 1024, maxPayload) → loaded character → permission node (perm, checked with npAdmin.can) → per-RPC rate → one call in flight per player and name → schema
(unknown keys dropped) → open session → handler (errors answer internal).
| RPC | Purpose |
|---|---|
inventory:open |
{ target?: { type, id?, netid?, player?, coords?, class?, pin? } }. The server re-checks distance, groups, owner, PIN, vehicle entity, plate, lock and seat, rob / frisk rules and beforeOpen hooks |
inventory:close / inventory:state |
Close / own state after a client restart |
inventory:move, quick, use, action, sort, stack, takeAll, seen, container:close, frisk:full |
The callbacks above |
give:targets / give |
Nearby players by server-side ped distance |
shop:open / shop:buy |
Shop session and purchase |
crafting:open / start / cancel / collect |
Bench session and queue |
trade:request / respond / offer / lock / confirm / cancel |
Trade |
hotbar:use |
Use a hotbar slot without an open session |
use:finish |
{ token, cancelled?, target? }: completes a timed use. target = { netid?, player?, wheel?, amount? } for built-in items; the answer carries builtin data the client applies (engine health, tyre, fuel, unlocked doors) |
weapon:sync / weapon:reload / weapon:holster |
Ammo and wear (can only go down), reload, weapon lost |
armour:sync |
Vest durability follows lost armour |
search:prop |
Search a world prop |
drop:pickup |
Pick up a drop (E) |
Every server session lives on the server (player, equipment, secondary?, container?, mode). Moves are only
allowed between inventories of the caller's session (plus ground), and access to the secondary and the bag is
re-checked on every move; a failed check closes the panel.