Skip to content

NUI contract (Lua ⇄ web) ​

The message contract between the Lua client, the web UI and the server. The source of truth is docs/ARCHITECTURE.md in the resource (§3 data shapes, §5 NUI protocol, §12 web); 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 sends a slot, an amount, an id. Purity, grades, prices, counts, durations, outcomes and metadata are computed on the server from its own stores, positions are read on the server, and the client view of the body has phases and timers, never purity or dependence scores.

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

Through NpDrugs.sendNui(action, data) (queued until the NUI called ui.ready); from the server NpDrugs.nui(src, action, data).

action data
init { locale, strings, substances, grades, items, player: { identifier, name, job, grade, police, medic, admin }, config: { keys, inventory, metadata, imagePath }, sync, modules }
sync { key, value }: one per-player state value changed (body, effects, hud, nearby, overdose, production, rehab, street, trash, k9)
open / close { screen, data } / { screen? }: a focus screen
hud:notify { type, title?, message, icon?, tint?, duration? } (only without np_hud)
hud:progress / hud:progressCancel { id, label, icon?, tint?, duration, cancelKey? } / { id } (only without np_hud)
hud:prompt / hud:promptHide { id, icon?, tint?, keys } / { id } (only without np_hud)
<module>:<name> Anything a module sends, declared in NuiMessageMap

openScreen takes NUI focus and claims the HUD zones; opening another screen closes the first. The client closes the screen when the player dies, gets cuffed or unloads; ESC calls ui.close.

Web → Lua: one callback ​

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

Client-local methods are answered by the client (ui.ready, ui.close, action.run, batch.bag, carry.cut, carry.bench, conceal.*, ems.run, production.pickup, rehab.vitals, vitals.waypoint, search.check, search.k9, street.offer, street.accept, terminal.refresh, trash.dig, trash.start, trash.stop, use.take); everything else goes to the server dispatcher.

Server check order: known method → token bucket (Config.RateLimit) → ready → a sane params table → loaded character → job / admin → alive → one call per player and method in flight → schema → cooldown → handler. Errors are codes: unknown_method rate_limited not_ready invalid_params no_player forbidden downed busy cooldown internal_error timeout invalid_token too_early expired too_far not_found not_available no_space item_missing unknown_action not_allowed failed cancelled, plus each module's own.

Timed actions ​

Anything that takes time is a timed action: action.start { name, params } → { token, duration, … }, the client plays the bar, action.finish { token }. The server sets the duration, checks the elapsed time and the distance, and re-validates everything in the finish step. Work actions (batch, conceal, carry, production, trash) are divided by the body's work speed.

Screens ​

Screen Module
batch The batch table
conceal, carry The concealment bench, the carry card
production The lab
use, effects (+ the substance board) The method picker, "right now"
ems The medic's case (record inside)
rehab, vitals The clinic desk, the doctor's Vitals screen; web/phone.html is the np_phone app
search, evidence, terminal The careful look (K9 inside), evidence view, police terminal
tests_kit Breath, swab, blood, lab report
trash, street Bins and the sanitation board; the street sale card
HUD pieces Substance tiles, load meter, overdose, withdrawal (web/src/screens/<module>/hud.tsx)

UI rules ​

  • React 18 + TypeScript strict + Vite, zustand, Nimbus CSS imported unchanged. The stage is 1920×1080, scaled to the window with CSS zoom.
  • Colour sits on tiles. One tint and glyph per substance, the same in the HUD, phone, EMS screen and test kit. State colours stay fixed: green ok, orange warning, red danger, blue police.
  • Tokens only in custom CSS (the test suite rejects hex colours, rgb() and literal font sizes under src/screens/). No light line along a bottom edge; no backdrop-filter (FiveM cannot do it, the build fails without the guard).
  • Item pictures come from the inventory's icon pack (Config.ImagePath), else a drawing, else the item's glyph.