NUI contract ​
The contract between the Lua client, the web UI (web/) and the server. You only need this page to change the UI or
write your own front end; resources that start games use the exports.
The NUI only sends what the player did. The verdict always comes from the judge: the server's for server sessions, the client's own for local ones.
Messages ​
Lua → NUI: SendNUIMessage({ action, data }). Messages sent before the NUI is ready are queued.
| Action | Data |
|---|---|
boot |
{ locale, prefs } (the answer to ui.ready) |
theme |
{ brand, strength, material }: np_admin's central server theme |
game:open |
{ token, puzzle, meta, prefs }: the public puzzle and the card's meta |
game:result |
{ token, result }: a game that ended on the server side (a submit gets its verdict as the RPC reply) |
game:team |
{ id, window, self, members = { { src, name, state, progress } } }: the team status strip |
arcade:open / arcade:close |
{ prefs } / {} |
NUI → Lua: one callback, https://np_minigames/rpc, with { method, params }. It answers { ok = true, data } or
{ ok = false, error }.
| Method | Side | Params → data |
|---|---|---|
ui.ready |
client | → flushes the queue, sends boot and the theme |
game.shown |
client → server | { token }: the game is on screen (must happen within Security.startTimeoutMs) |
game.submit |
client → server (or the local judge) | { token, answer } → the verdict |
game.cancel |
client → server | { token, reason } → the verdict |
game.progress |
client → server when meta.progress (local games: onProgress on the client) |
{ token, p } |
game.fx |
client | { kind }: a frontend sound from Config.Sounds |
arcade.list / arcade.play / arcade.board |
server | the arcade's games and stats, a practice run { game, difficulty } → { token }, a leaderboard { game } |
arcade.close / prefs.set |
client | {} / { prefs } |
profile.play ({ name, label?, sub?, title? } → { token, game }) is called by the client PlayProfile export,
not by the NUI.
Server → client net events: np_minigames:open, np_minigames:close (token, result), np_minigames:team,
np_minigames:rpc:reply. Client → server: np_minigames:rpc (id, method, params), np_minigames:prefs.
Session lifecycle ​
resource exports.np_minigames:Play(src, 'thermite', { difficulty = 'hard', maxMove = 3, item = { ... } })
server busy → beforeStart hooks → item check ('no_item') → build (puzzle, seed) → token
→ 'np_minigames:open' (public puzzle) → event 'np_minigames:started' (np_phone blocked, np_menu closed)
client NUI 'game:open' → focus ('keys' = keyboard only, 'full' = + cursor) → 'np_minigames:client:started'
(np_hud zones claimed, np_phone client block)
NUI rpc game.shown → the server marks it shown
NUI … the player plays … rpc game.progress { token, p } when asked for
NUI rpc game.submit { token, answer }
server maxMove check → judge(puzzle, answer, now - startedAt) → finish:
items settled → profile receipt → stats, np_admin observe → afterResult hooks
→ event 'np_minigames:result' (np_phone released) → Play returns (ok, result)
client claims and blocks released → PlayProfile waiter → 'np_minigames:client:result'
NUI shows the verdict (grade and score, or the reason) for 1.6 s, then hides
Every way a session ends (cancel, dead, moved, not_shown, timeout, replaced, dropped, team_failed,
api) runs finish once, so the release always happens.
The phone app ​
web/dist/phone.html runs inside np_phone's app iframe. Its server RPCs are registered with np_phone as
arcade.list (games, stats, locale, theme, command), arcade.board { game } and arcade.play { game, difficulty }
(puts the phone away, then starts the practice run). Its client RPCs prefs and setPrefs { prefs } read and write
the same preferences as the big-screen arcade. The prefix is Config.Phone.app.id.