Skip to content

NUI contract (Lua ⇄ web) ​

The message contract between the Lua client, the server and the web UI. The full source of truth is docs/ARCHITECTURE.md in the resource; web/src/lib/types.ts holds every view model. This page summarises it. 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 decides, the client draws. Prices, stock, ownership, uniform rules, duty, positions and the ped's sex are read on the server. A try-on or preview is always a server decision; the client only sends intents.

Lua → web: SendNUIMessage({ action, data }) ​

From the server the same messages arrive as TriggerClientEvent('np_clothing:nui', src, action, data).

action data effect
theme { brand?, strength?, material? } The server theme from np_admin (on ui.ready and on every change)
init { locale, config, player, synced } Store. Re-sent after ui.ready
state PlayerState Job, duty or staff changed
sync { key, data } A synced key changed: locks, stores, wardrobe, faction
screen:open { id, data, focus } Shows a screen with its view
screen:update { id, data } Replaces the view of an open screen. Modules send whole views back after a change
screen:close { id? } Closes one screen, or all
toast / prompt:show / prompt:hide / progress:start / progress:cancel Fallbacks, only used when np_hud is not running

Features never add actions: their data goes through screen:open / screen:update or a sync key.

Screens ​

id Opened by Focus View
store stores full StoreView (standard, luxury, counterfeit)
dressing stores, wardrobe, locker, designer overlay DressingData
store.auth /checkfit full AuthCheckData
wardrobe wardrobe full WardrobeView
uniform Universal Uniform full UniformDesignerView
locker lockers full LockerView
packs pack manager full PackManagerView

Only one full-focus screen is open at a time. Focused screens close when the player dies, is cuffed or unloads; Escape closes the top one. Closing always ends the session on the server (store.leave takes the try-on off, wardrobe.revert, uniform.leave, locker.leave).

Web → Lua: one callback ​

ts
fetch('https://np_clothing/rpc', { method: 'POST', body: JSON.stringify({ method, params }) })
// → { ok: true, data } | { ok: false, error: 'code' }

Client-local methods are answered on the client; everything else is forwarded to the server.

Client-local method Params Does
ui.ready / ui.close {} / { id? } Re-sends init; closes a screen
cam.preset { name: 'face' | 'torso' | 'legs' | 'feet' | 'full' } Camera preset
cam.rotate / cam.zoom { delta } Turns the ped / zooms
ped.pose { pose: id | false } Dressing-room pose
dressing.compare { side: 'a' | 'b' } A = the look you came in with, B = the try-on
cam.light { mode: 'daylight' | 'store' | 'night' } Dressing-room light
progress.done { id, cancelled } Fallback progress finished

Server RPC ​

Every call is rate limited (Config.Rpc, with a cost per method) and its params are validated. Errors are codes; a code can carry a detail after a colon (vetoed:<reason>, set_locked:cert:motor). Methods that belong to a place need a session opened by <feature>.open; it ends on close, leave, unload, drop, or 5 m outside the place's radius.

Feature Methods
core look.current, look.toggle, quick.restore
stores store.open, store.pieces, store.inspect, store.try, store.cart.add, store.cart.remove, store.checkout, store.leave, store.authenticate, store.stylist
wardrobe wardrobe.open, wardrobe.pieces, wardrobe.try, wardrobe.save, wardrobe.revert, outfits.list, outfits.save, outfits.rename, outfits.delete, outfits.wear, outfits.quick, outfits.share, outfits.import, outfits.saveShared
Universal Uniform uniform.open, uniform.leave, uniform.pieces, uniform.select, uniform.save, uniform.publish, uniform.delete, uniform.preview, uniform.certs, uniform.certs.grant, uniform.certs.revoke, uniform.log
lockers locker.open, locker.leave, locker.select, locker.choose, locker.toggle, locker.change, locker.civilian
catalogue (staff) catalogue.status, catalogue.scan.begin, catalogue.scan.finish, packs.view, packs.pieces, packs.set, packs.piece.set, packs.scan, packs.scan.confirm, import.status, import.run, import.review, import.resolve

The scan upload uses latent net events (np_clothing:catalogue:chunk) between catalogue.scan.begin and catalogue.scan.finish, with a token. catalogue.scan.begin refuses a scan that doesn't cover every model (scan_models). catalogue.scan.finish answers { pending = true, … } when the scan is held; packs.scan.confirm { confirm } applies or drops it (scan_stale when the catalogue changed since it was held).

The client never reports clothing the server trusts: the appearance written to np_character and the first look of a new character are built on the server.

Wire rules ​

  • A Lua nil can't travel: optional fields usually arrive omitted. The NUI treats undefined and null alike.
  • To clear an override, the NUI sends false or '' (strings), -1 (prices) or 0 (release time), never null.
  • Choice indices are 1-based; grade keys are strings.
  • Server texts mark the one key fact with **…**. The NUI renders it bold, never as HTML.
  • A piece card is never dropped because it's unavailable: it shows grey with an orange warning.