NUI contract (Lua ⇄ web) ​
The message contract between the server, the Lua client, the web UI and the np_phone app. The full source of truth is
docs/ARCHITECTURE.md in the
resource (§3 TypeDef, §4 view models, §5 NUI protocol, §6 events, §10 phone app); 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.
web/scripts/check-contract.mjs (part of npm test) checks the parts that can be checked statically: RPC names, NUI
actions, net events and error codes on both sides.
Lua → web: SendNUIMessage({ action, data }) ​
The client sends these itself (Ident.sendNui / Ident.openView), or the server pushes them with
Ident.nui(src, action, data) through the np_identification:nui net event.
| action | data | view |
|---|---|---|
init |
{ locale, dateFormat, types: TypeDef[], config: { keys, showDistance, photoMethod, requireItem, economy }, player?: { citizenid, name, job, grade, admin, police } } |
store |
types |
{ types: TypeDef[] } after a publish or delete |
store |
picker:open |
{ documents: DocSummary[], targets: Target[] } |
Picker |
picker:targets |
{ targets } every 750 ms while open |
Picker |
viewer:open |
{ doc: DocView, from?: { name, distance }, self, canUv, canPhoto, preview?: typeKey } |
Viewer |
badge:open |
{ badge: { design, label, rank, number, name }, card?: DocView, from?: { name } } |
Badge |
desk:open |
{ desk: { id, label, icon, tint }, offers: Offer[], character, money: { cash, bank } } |
Desk |
desk:photo |
{ image }: the raw screenshot; the web crops it to 300 × 364 JPEG (desk and forger) |
Desk / Forger |
issue:open |
{ issuer: { job, label }, types: Offer[], targets } |
Issue |
issue:targets |
{ targets } every 1.5 s while open |
Issue |
check:open |
{ result: CheckResult } |
Check |
forger:open |
{ qualities: { id, label, price, hologram }[], types: string[], character } |
Forger |
designer:open |
{ types: AdminType[], exams, hosts, jobs: { name, label }[], desks: AdminDesk[], select?: typeKey } |
Designer |
request:show |
{ id, from: { name, job }, timeout, keys } (no focus) |
toast |
request:hide |
{ id } |
toast |
notify |
{ type, title, message, icon? }, only when np_hud isn't running |
toasts |
close |
– | all |
init.config.requireItem is Config.RequireItem and an inventory with item metadata; economy is false on the
standalone bridge.
Focus ​
Views opened by *:open take NUI focus; opening one closes the previous one (camera and desk state are cleaned up).
The client closes the view when the player dies, gets cuffed or unloads. A viewer:open / badge:open pushed by
another player (data.from set) is dropped while the player is busy in the desk, issue, forger, designer or check view.
The request toast never takes focus; the Y / N key mappings answer it.
Designer preview: designer.preview sends viewer:open with preview = key. When that viewer closes, the client
runs designer.list again and opens the designer with select = key.
Web → Lua: one RPC callback ​
fetch('https://np_identification/rpc', { method: 'POST', body: JSON.stringify({ method, params }) })
// → { ok: true, data } | { ok: false, error: 'code' }
Client-local methods are answered by the Lua client; everything else is forwarded to the server dispatcher over the
np_identification:rpc net event. desk.submit, issue.submit and forger.buy carry photos (about 120 KB) and use a
latent event with a 30 s timeout instead of 10 s.
Client-local methods ​
| Method | Params | Result |
|---|---|---|
ui.ready |
– | true. The web is mounted; the client resends the last init |
ui.close, viewer.close, badge.close |
– | true |
picker.action |
{ serial, action: 'show' | 'give' | 'self', target? } |
true. self opens the viewer, show plays the animation |
viewer.photo |
– | true. Screenshot of the card → np_phone gallery |
desk.camera |
{ angle: 'front' | 'left' | 'right' | 'off' } |
true |
desk.capture |
{ angle } |
true, then desk:photo |
designer.position |
– | { x, y, z, w }: the player position, rounded to 0.01 |
request.respond |
{ id, accept } |
true. Forwards to the server method of the same name |
Server RPC methods ​
Every call is rate limited (token bucket 8/s, burst 16, a cost per method) and its parameters are validated. Admin and police methods are gated by the dispatcher; grade, ownership and distance are checked by the handler.
| Method | Params | Result |
|---|---|---|
docs.list |
– | DocSummary[]: carried items (stolen and forged ones too) plus own records (not replaced) |
docs.get |
{ serial } |
DocView: a carried card or an own record |
docs.show |
{ serial, target } |
true. Within ShowDistance, card carried (or digital mode), 1.5 s cooldown |
docs.showDigital |
{ serial, target? } |
true. Own record, no item; nearest player when no target |
docs.give |
{ serial, target } |
true. Moves the item; the record's owner doesn't change |
docs.reportLost |
{ serial } |
true. Owner only |
docs.replace |
{ serial } |
DocView. Lost → new serial, ReplacementFee, new item, old card removed |
docs.renew |
{ serial } |
DocView. rules.renewOnline, valid or expired, paid from the bank |
docs.applications |
– | (Offer & { desks })[]: types obtainable at desks |
desk.offers |
{ desk } |
{ desk, offers, character, money, economy }, within 5 m |
desk.submit |
{ desk, type, photo?, signature?, inputs, payment: 'cash' | 'bank', answers? } |
DocView |
issue.offers |
{ target? } |
{ issuer, types: Offer[], targets }, with the target's requirement status |
issue.submit |
{ target, type, inputs, validityDays?, photo?, signature? } |
DocView. The target pays from the bank |
check.run |
{ target?, serial? } |
CheckResult (police) |
police.points |
{ serial, points, reason } |
CheckResult |
police.suspend |
{ serial, days, reason } |
CheckResult |
police.revoke |
{ serial, reason } |
true |
police.seize |
{ serial, reason } |
true. Removes the item from nearby holders (forged too), revokes the record |
police.request |
{ target } |
true. The target gets request:show (10 m) |
request.respond |
{ id, accept } |
true. Accept presents the ID card (or the first document) to the officer |
badge.show |
– | true. badge:open to self and players within 2 × ShowDistance, 3 s cooldown |
forger.offers |
– | { qualities, types, character }, within 5 m of the forger |
forger.buy |
{ type, quality, inputs, photo? } |
true. Cash; item with forged metadata, no record |
weapons.list |
{ serial } |
WeaponEntry[]: owner, police or admin |
items.has |
{ item } |
boolean. Config.Items.* and document items only |
viewer.photoTarget / viewer.photoSave |
– / { url } |
np_phone upload target / true |
log.list |
{ serial?, limit? } |
LogEntry[]: admins; police only with a serial |
designer.list |
– | the designer:open payload |
designer.save |
{ key, def } |
AdminType (draft) |
designer.publish |
{ key, migrate: 'update' | 'keep' | 'reissue', reissueDays? } |
AdminType |
designer.discard |
{ key } |
AdminType, or { key, removed = true } for draft-only types |
designer.delete |
{ key } |
true. For config types the override is removed |
designer.rollback |
{ key, version } |
AdminType. Republishes the old definition as a new version (0 = back to config) |
designer.version |
{ key, version } |
TypeDef: an archived definition (0 = config) |
designer.import |
{ json } |
AdminType (draft) |
designer.export |
{ key } |
JSON string { format = 'np_identification/type', version = 1, type, exam? } |
designer.exam |
{ key, exam } |
true |
designer.preview |
{ key } |
true, then viewer:open with the draft |
designer.deskSave |
{ desk = { id, label, icon?, tint?, coords, ped, blip?, types? } } |
{ desks = AdminDesk[] } |
designer.deskDelete |
{ id } |
{ desks = AdminDesk[] }. Designer desks only |
Error codes ​
Handlers return a code (not_found, too_far, forbidden, not_allowed, not_enough_money, busy,
rate_limited, …). A code may carry a path after a colon (invalid_definition:fields.2.id,
invalid_exam:questions.1.correct, invalid_desk:ped); the text lookup falls back to the part before the colon. Every
code has a translation in shared/locales.lua and in the web dictionaries; the contract check enforces it.
View models ​
DocView = { serial, type, version, typeDef?, values, photo?, signature?,
state: 'valid' | 'expired' | 'suspended' | 'revoked' | 'lost' | 'replaced',
statusReason?, statusUntil?, points?, pointsMax?, issuedAt, expiresAt?,
meta?: { weapons? }, holder?: { name },
forged?: { quality: 'low' | 'mid' | 'high', typos: string[] } }
DocSummary = { serial, type, state, expiresAt?, label, subtitle, owned?, item? }
Target = { id, name, distance }
Offer = { type, label, price, requirements: { id, label, ok }[], inputs: Field[], exam? }
CheckResult = { doc?, found, checks: { id, label, ok: boolean | 'warn', detail }[],
actions: { points, suspend, seize, revoke } }
AdminType = { key, label, source: 'config' | 'db', status: 'live' | 'draft' | 'config', version, hasDraft,
def, draft?, versions: { version, publishedAt?, publishedBy, issued }[], issued }
AdminDesk = { id, label, icon, tint, source: 'config' | 'db', coords: { x, y, z, w }, ped, blip, types }
typeDefis set when the document's version isn't the live one (kept old design, deleted type, preview).- Requirement ids:
document:<key>,no_warrant,min_age,exam:<key>,max_active. Check ids:registry,holder,state,expiry,points,classes,warrants. Labels and details are localised by the server. - Exam answers are 1-based;
correctis stripped before an exam is sent to players.
Phone app ​
web/dist/phone.html is registered with np_phone. Its RPCs (registerAppRpc, called as phone.rpc('<name>') in the
app) run the same server handlers, with the same validation and permissions:
| Method | Result |
|---|---|
docs.list |
DocSummary[]: own records, no replaced ones |
docs.cards |
DocView[]: the same records as full views (card stack) |
docs.get { serial } |
DocView |
docs.reportLost / docs.renew / docs.replace { serial } |
true / DocView / DocView |
docs.showDigital { serial } |
true: nearest player within Config.ShowDistance |
types.get |
{ types, locale, dateFormat, replacementFee } |
offers.get |
{ type, label, price, requirements, desks = { { id, label } } }[] |
offers.renewable |
{ serial, type, label, price, state, expiresAt? }[] |
Push events (sendAppMessage, coalesced per player): docs:changed { serial? } after an issue or a status change,
types:changed {} after a publish.