NUI contract ​
The contract between the Lua client, the web UI (web/) and the server RPCs behind it. TypeScript mirrors of the
shared shapes are in web/src/lib/types.ts (SceneView, SceneTask, BoardEntry, ReportEntry, CitizenInfo,
MarkerData). You only need this page to change the UI or write your own front end; other resources use the
exports and events.
The NUI is server-authoritative. Positions are read on the server, jobs come from the framework, items from the inventory, times from the server clock. The client never sends an outcome.
Messages ​
Lua → NUI: SendNUIMessage({ action, data }) (from the server: the net event np_environmental:nui). NUI → Lua: one
callback, fetch('https://np_environmental/rpc', { method: 'POST', body: JSON.stringify({ method, params }) }) →
{ ok: true, data } | { ok: false, error: 'code' }. Client-local methods are handled on the client, everything else
is forwarded to the server RPC dispatcher.
Actions ​
| Action | Data | Effect |
|---|---|---|
theme |
{ brand?, strength?, material? } |
The np_admin server theme on the .nb-ui root (npAdmin.onTheme) |
init |
{ locale, config, player, factions, kinds, synced } |
Store (also re-sent after ui.ready) |
state |
PlayerState |
Store player |
sync |
{ key, data } |
Store synced[key] (citizen, closures, …) |
screen:open |
{ id, data, focus } |
Shows a screen with data |
screen:update |
{ id, data } |
Replaces the data of an open screen |
screen:close |
{ id? } |
Removes one / all |
markers |
MarkerData[] |
The world markers on screen right now ([] hides them) |
toast |
ToastData |
Fallback toast (only without np_hud) |
prompt:show / prompt:hide |
{ id, icon, tint?, keys } / { id? } |
Fallback prompt |
progress:start / progress:cancel |
{ id, label, icon, tint, duration, canCancel } / { id } |
Fallback progress bar |
init.config = { framework, inventory, phone, hud, menu, services, radii = { stream, discover, inspect, task }, commands = { board, boardKey, admin } }. PlayerState = { identifier, name, admin, director, editor, job = { name, label, grade, onduty }, factions = { key }, duty = { key = true } }.
Screens ​
| Screen | Opened by | Focus | Data |
|---|---|---|---|
scene |
Discovery (card and prompts) | none / keys | SceneView |
work |
The work flow (clean-up HUD) | none | { scene: SceneView, crew, task?: { id, label, progress, count }, left? } |
report |
The report flow when np_phone is absent | full | { scene?: SceneView, services, nearby: SceneView[] } |
board |
/scenes, F6 |
full | BoardData |
editor |
/envadmin, np_admin tool |
full | { templates, spawns, factions, kinds, items, walk? } |
director |
/envdirector, np_admin tool |
full | DirectorState |
Focus 'full' = mouse and keyboard, one screen at a time; 'keys' = keyboard to the NUI while the game keeps its
input; none = overlay. Focused screens close when the player dies, is cuffed or unloads; Escape closes the top
'full' screen.
Client-local methods ​
ui.ready -> true NUI mounted; the client re-sends the last init
ui.close { id? } -> true
progress.done { id, cancelled } -> true fallback progress finished
editor.preview { template | false, stage?, here? } -> true local ghost props for the editor
editor.walk { tool } -> true leave the editor and walk: 'point' | 'zone' | 'object'
report.photo -> url | false
editor.walk returns into the editor with walk = { tool, points = { { x, y, z, w, offset? } } }: 'point' → one
spawn point per point (heading = w), 'zone' → one zone with the points as corners, 'object' → new objects of the
selected template at offset relative to the preview anchor.
Server RPC methods ​
Params are validated, every call is rate limited (token bucket Config.Rpc), errors are codes. The dispatcher checks
staff nodes, faction membership and duty before the handler.
scene.discover { id } -> SceneView within discoverRadius, marks 'seen'
scene.inspect { id } -> SceneView (clues) within inspectRadius
scene.view { id } -> SceneView known scenes only
scene.report { id?, service, kind?, hurt?, text?, photo? } -> { report, scene?, precise }
scene.mine -> { reports, citizen } the phone's Reports tab
scene.nearby -> SceneView[] known live scenes, nearest first
scene.closures -> Closure[]
task.begin { scene, task } -> { token, duration, label, icon, anim? }
task.finish { token, cancelled } -> { task, progress, count, done, share, cleared }
board.get { faction? } -> BoardData faction member
board.accept { id } -> BoardEntry (+ waypoint) faction member, on duty
board.handover { id, faction } -> true faction member, on duty
board.backup { id } -> true faction member, on duty
citizen.get -> CitizenInfo
admin.templates -> { templates, kinds, factions, items } editor
admin.template.save { template, previousId? } -> Template editor
admin.template.delete { id } / admin.template.duplicate { id } editor
admin.validate { template } -> { ok, errors = { { field, code } } } editor
admin.spawns { template? } -> SpawnPoint[] editor
admin.spawn.save { spawn } / admin.spawn.delete { id } editor
admin.spawn.here { template?, label, kinds? } -> SpawnPoint (your position and heading) editor
admin.director.get / .set { rules } / .roll / .pause { paused } director
admin.scene.spawn { template, spawn?, here? } -> { id } director
admin.scene.remove { id } / admin.scene.clearAll / admin.scene.teleport { id } director
Shapes ​
SceneView = { -- what a player who discovered the scene may know
id, template, label, kind, icon, tint, coords, heading, stage, stageLabel, severity, state,
level = 'seen' | 'inspected', distance?,
clues = { { object, label, text } }, -- only after inspect
tasks = { SceneTask }, -- with `blocked` = why THIS player cannot do it now
hazards = { { id, kind, coords, radius, damage, protected, protect? } },
objects = { { id, label, coords, task?, clue?, done?, carry? } },
factions = { key }, crew = { { name, faction, share, points, me? } },
reported, canReport, progress, stages, street?, area?, calls, left?, foundAgo?,
}
BoardEntry = { id, template?, label, icon, tint, kind?, severity, stage, pin, precise, wrongService, handedTo?,
reports = { { name, service, text, at, precise, voice?, photo?, hurt? } },
timeline = { { step = 'spawned' | 'reported' | 'accepted' | 'onscene' | 'cleared', at } },
units = { { identifier, name, faction, onScene, coords? } }, payout, distance, progress, photos, street? }
-- a vague entry (no precise report) hides template and kind: label "Something reported", icon circle-question
BoardData = { faction, label, service, entries = { BoardEntry }, shift = { cleared, payout, onScene },
onDuty, closures, me? }
Closure = { id, label, icon, tint, coords, radius }
Error codes ​
| Source | Codes |
|---|---|
| Dispatcher | unknown_method, rate_limited, not_ready, invalid_params, no_player, forbidden, not_allowed, off_duty, cooldown, internal_error |
| Client | timeout, stopped |
| Core | vetoed, not_available, dead, invalid_faction, invalid_coords |
| Modules | not_found, too_far, needs_item, needs_vehicle, needs_people, locked, busy, not_live, nothing_here, bad_token, too_fast, invalid_template, no_spawn, already_reported, already_done, wrong_service, not_listed |
A code may carry a detail after a colon (invalid_template:tasks.cut.object, vetoed:<hook text>). Every code has a
localised text (error.<code> in shared/locales/en|de).
The phone app ​
A second Vite entry: web/phone/index.html → web/dist/phone/index.html, shown by np_phone in an iframe. It uses the
np_phone SDK copied to web/phone/np-phone/ (phone.rpc('<name>'), phone.on, phone.notify, phone.pickPhoto()).
App RPCs map to the server methods above: mine, nearby, closures, report, board, accept, handover,
citizen. The page refetches when Lua sends an app message changed with { what = 'mine' | 'nearby' | 'closures' | 'board' }.
Net events ​
| Event | Direction | Payload |
|---|---|---|
np_environmental:rpc / :rpcResult |
client ↔ server | reqId, method, params / reqId, ok, dataOrError |
np_environmental:hello |
client → server | The client is up |
np_environmental:init / :state / :sync |
server → client | See Actions |
np_environmental:nui |
server → client | action, data |
np_environmental:notify |
server → client | Fallback toast |
np_environmental:waypoint |
server → client | { x, y, z } |
np_environmental:admin:open |
server → client | 'editor' | 'director' (np_admin tools) |
np_environmental:scenes |
server → client | The per-player stream: public data of the scenes within the stream radius, only changes |
np_environmental:view |
server → client | sceneId, SceneView | false (a known scene changed) |
np_environmental:closures |
server → all | Closure[] |
np_environmental:task:cancel |
server → client | token, reason (scene gone, moved away) |
np_environmental:alert |
server → client | { scene, label, icon, tint, service, pin, precise } (on-duty members of routed factions) |
Never listen to these from other resources; use the server events.