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, §3 appearance, §4 NUI protocol, §5 server RPC); this page summarises §4 and §5 and adds the decisions
the web made where the contract leaves room (web/README.md). 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: ped natives live in Lua, editor state lives in the web. The web owns the working appearance, undo / redo, randomise and lock, and sends each change to Lua. Lua applies the natives to the ped and answers with new option counts when they change. The server is authoritative for slots, CIDs, names, deletes, money, the starter pack, blacklists, look codes and spawns.
Lua → web: SendNUIMessage({ action, data }) ​
Messages sent before the web posted ready are queued (up to 128) and flushed after boot.
| action | data | meaning |
|---|---|---|
boot |
{ locale, strings, material, brand, strength, scale?, config } |
Once after ready (again after a web reload). config carries name and age rules, nationalities, walk styles, voices, height range, parents, hair and makeup palettes, arrivals, starter pack, thumbnails, deleteGraceDays, renameCost, steps. strings overrides the web's ui.* strings |
select:open |
{ characters, slots, server, selectedCid?, map? } |
Show the select screen |
select:update |
partial { characters?, slots?, server? } |
After delete / reorder / default or a staff action. Never moves the selection |
creator:open |
{ mode: 'create' | 'store', slot?, steps, step?, gender, appearance, identity?, options, price?, title?, allowPed, pedModels? } |
Open the creator or a store |
creator:options |
CreatorOptions |
Optional push of the option counts |
creator:result |
{ ok, error? } |
Optional asynchronous answer to creator:finish |
creator:headshot |
{ url: 'https://nui-img/<txd>/<txd>' } |
ID card photo |
spawn:open |
{ character, spawns, weather, selectedId?, map? } |
Show the spawn picker |
admin:open |
{ target: { src?, name, license }, characters, slots } |
Staff panel (characters include deleted ones and rename requests) |
hide |
{ ui: boolean } |
Lua-initiated hide / show of the whole stage |
notify |
{ type, title, message, icon?, tint?, duration?, app? } |
Toast |
settings |
{ material, locale, strings? } |
Player settings changed |
close |
{} |
Close everything |
map is Config.Map with only the enabled layers: { style, cayoPerico, tiles, layers: [{ id, label, bounds, image | images, opacity }] }.
CreatorOptions holds, per model: drawable and texture counts for every component and prop, hair styles, overlay style
counts, the blacklist for the player (component / prop / hair drawables), whether job uniforms are locked, and the
tattoo list per zone with the hash for the current gender.
Web → Lua: fetch('https://np_character/<name>', { method: 'POST', body }) ​
Every callback answers JSON exactly once: { ok: true, … } or { ok: false, code?, error }. error is a display
string or { field, message } (form errors). Server errors pass through unchanged; Lua turns its own codes (busy,
slot_locked, timeout, …) into text and keeps the raw code in code.
| name | body | Lua does |
|---|---|---|
ready |
{} |
Sends boot, flushes the queue |
select:focus |
{ cid } |
Swaps the preview ped |
select:play |
{ cid } |
char:load → spawn picker (or a direct forced spawn) |
select:new |
{ slot } |
char:new → creator:open in create mode |
select:delete |
{ cid, confirm } |
char:delete (the server checks confirm against the full name) |
select:reorder |
{ cid, slot } |
char:reorder |
select:default |
{ cid, on } |
char:default |
select:rename |
{ cid, firstname, lastname, reason } |
char:rename (staff review request) |
select:lookcode |
{ cid } |
char:lookcode → { code } |
select:logout |
{} |
session:quit: drops the player (Quit button) |
creator:set |
{ path, value } |
Applies one change. Answers { ok, options?, appearance?, arms? } |
creator:apply |
{ appearance } |
Applies a whole appearance (undo / redo / randomise / reset / preset / import / gender tabs). Answers { ok, options, modelChanged? } |
creator:camera |
{ preset } | { zoom } | { heading } | { orbit } |
Moves the camera. Answers { ok, heading } (180 = the ped faces the camera) |
creator:pose |
{ handsUp? , light?, hideUi? } |
Hands up, studio light (hideUi is informational) |
creator:validateName |
{ firstname, lastname } |
name:validate on the server |
creator:importCode / creator:saveCode |
{ code } / { appearance } |
look:import / look:save |
creator:headshot |
{} |
Registers a ped headshot, then sends the creator:headshot action |
creator:finish |
{ identity, appearance, arrival } (create) / { appearance } (store) |
char:create → spawn picker, or store:finish |
creator:cancel |
{} |
Create → back to select; store → store:cancel, restores the look |
spawn:focus |
{ id } |
Sky camera over the spawn |
spawn:choose |
{ id, onDuty? } |
spawn:choose on the server, then teleport, appearance, arrival |
spawn:back |
{} |
Back to select |
admin:action |
{ action, cid?, value? } |
admin:action on the server; Lua adds the target |
settings:set |
{ material?, locale? } |
Stores in KVP, pushes settings |
close |
{} |
Store → cancel, admin → close; select and create ignore it |
creator:set paths: model (Ped tab), headBlend or headBlend.<key>, faceFeatures.<key>,
headOverlays.<name> (whole overlay; "none" = opacity 0), hair, eyeColor, components.<id>
(components.11 carries autoArms), props.<id> (-1 = none), tattoos (whole zone map),
identity.walkstyle / identity.voice / identity.height.
Server RPC (client ⇄ server) ​
The client calls NpChar.rpc(name, payload): a request id over np_character:rpc, answered on the same event, with a
10 s timeout. Each RPC is registered with a state, a rate limit, a payload schema and optionally a permission
(perm: an np_admin node, or a function returning one, checked through npAdmin.can on every call). The check order
is: global token bucket (Config.RateLimit) → payload sanity (depth, keys, sizes) → session state → permission node → per-RPC rate →
one call in flight per player and name → schema (unknown keys dropped).
| RPC | State | Purpose |
|---|---|---|
session:start |
connecting, select, creator, spawn | Select payload; also the way back to select |
session:logout |
loaded | Back to select |
session:quit |
select | Drop the player |
char:preview / char:load |
select | Preview appearance / pick a character → spawn list |
char:new / char:create |
select, creator | Slot check / create the character |
name:validate |
select, creator, loaded | Name rules |
char:delete / char:reorder / char:default / char:rename / char:lookcode |
select | Manage characters |
look:save / look:import |
select, creator, loaded | Look codes |
spawn:choose |
spawn | Validate the id, framework login, starter pack |
store:open / store:finish / store:cancel |
loaded | Store mode |
appearance:save |
loaded | Save the playing character's appearance (sanitised) |
position:save |
loaded | Last location (throttled to half of Config.SavePositionInterval) |
admin:list / admin:action |
any + np_character.admin |
Staff panel |
Web implementation notes ​
creator:setis coalesced to one call per frame per path; orbit drags are summed per frame.- Gender tabs send
creator:applywith the whole new appearance (new model, starter outfit, face kept). The Ped tab sendscreator:set { path = 'model' }. - Arms auto-match travels as
autoArmsoncomponents.11; Lua answersarms, which the web writes into its working appearance.components.3is only sent when the player changes the arms by hand. - Heritage: first = mother, second = father,
shapeMix/skinMix= resemblance towards the father; the skin-tone strip setsskinFirst = skinSecond. - Each step change sends its camera preset (identity, clothing, summary → body, the others → head).
spawn:choosesendsonDutyonly for spawns with a booleanonDuty. A spawn withforced = truenever reaches the web: Lua chooses it directly.- Optional fields the web reads when present:
boot.config.minAge/maxAge/gameYear/arrivalDefault,creator:open.pedModels,notify.duration(ms, 0 = sticky) andnotify.app.