Skip to content

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 (§4 data shapes, §5 NUI protocol, §13 NUI rules); this page summarises it. You only need it to change the web UI. Resources that use the exports never touch it.

The rule: the server decides. The client never sends an outcome. Positions are read on the server, membership, rank and bandana come from the stores, items from the inventory. The client state only draws things and hides prompts the server would refuse anyway.

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

From the server: TriggerClientEvent('np_gangs:nui', src, action, data).

action data effect
init { locale, config, turfs, player, gang, synced } Store (also re-sent after ui.ready)
state / gang / turfs PlayerState / GangState | false / TurfShape[] Store
sync { key, data } Store synced[key] (module state)
screen:open { id, data, focus } Shows screens/<module> with data
screen:update { id, data } Replaces the data of an open screen
screen:close { id? } Removes one / all
toast ToastData Fallback toast (only when np_hud is absent)
prompt:show / prompt:hide { id, icon, keys } / { id? } Fallback prompt
progress:start / progress:cancel { id, label, icon, tint, duration, canCancel } / { id } Fallback progress
lester:session / lester:sessionEnd LesterSession / { id, reason } The crew screen at Lester's

Web → Lua: one callback ​

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

Client-local methods are handled on the client (ui.ready, ui.close, progress.done, street.pick, street.toggle, lester.pick, trusted.reply, admin.walk, admin.goto, admin.preview); everything else is forwarded to the server RPC dispatcher. Params are validated, every call is rate limited (Config.Rpc), errors are codes (unknown_method rate_limited not_ready invalid_params no_player forbidden not_in_gang rank_too_low bandana_off cooldown internal_error; the client adds timeout).

Screens and focus ​

focus Meaning
'full' Mouse + keyboard, one at a time. Escape closes it
'keys' The NUI gets the keyboard, the game keeps its input (menus driven with number keys while walking)
false Overlay

Focused screens close when the player dies, is cuffed or unloads. Fallback toasts sit top right; screens that fill both top corners (the corner shift, the trial, the protected shop) move them to the top centre while they are open.

View models ​

ts
PlayerState = { identifier, name, admin,
                gang: { id, name, tag, color, print, rank, perms } | false,
                bandana: { on, own, carried, worn: { gang, color, print, style } | false } }
GangState   = { id, name, tag, color, print, status, og, members: { identifier, name, rank, online, perms? }[], online,
                turfs: { id, name, grip, contested, heldSince }[], hasStashout,
                stashout: { id, name, turf, door } | false,      // only for trusted individuals and the OG
                trusted: { used, max } }
TurfShape   = { id, name, polygon, noGang? }                     // released turfs; never the holder
StreetMenu  = { bandana, gang, rows: { id, key, icon, tint, title, sub, state: 'ready' | 'locked' | 'off' }[], key, note }
TurfToast   = { id, name, relation: 'own' | 'rival' | 'unclaimed', contested, tint, title, message, seconds, panelSeconds, panel }

Clients get turf polygons, never holders. Who holds a turf, where a stash is and where Lester stands is only told to the players the design names.

UI rules ​

  • React 18 + TypeScript strict + Vite, a Zustand store, Nimbus CSS imported unchanged. The stage is drawn for 1080p and zooms with the window height.
  • Colour only where it is the information: a tint on a tile, the drawn bandana, a turf on the map. In np_gangs that colour is the gang's bandana colour. Surfaces stay grey glass, text stays white, selection is a white ring.
  • Tokens only in custom CSS; no backdrop-filter of its own (FiveM can't do it, the build guards it).
  • Keyboard first: every screen shows its keys.