NUI contract ​
The contract between the Lua client, the web UI (web/) and the server RPCs behind it. The wire types are in
web/src/lib/types.ts (main NUI) and web/src/phone/api.ts (phone app). You only need this page to change the UI or
write your own front end; resources that work with matches use the exports.
The NUI is server-authoritative: it only sends inputs and intents. The server owns the rack, the turn token, the physics, the rules, the score and the money. The client never sends an outcome, a ball position after a shot, or a price.
Lua → NUI messages ​
SendNUIMessage({ action, data }). Messages sent before the NUI posted ready are queued (up to 128).
| Action | Data |
|---|---|
boot |
{ currency, thousands, scale, keys, reactions, modes, phases, achievements, theme, debug, physics, replay, drunk }, sent once after ready |
theme |
{ brand?, strength, material }: np_admin's server theme (sent by bridge/np_admin.lua as { action = 'theme', type = 'theme', data }) or the resource's own Config.Material / Config.Brand |
toast |
{ type, title, message, icon, tint, duration }, only while np_hud isn't running |
markers |
{ list = { { id, x, y, label, status, fee, size, dist, queue, challenges, playing, near } } }: floating table markers in screen coordinates |
prompt |
{ visible, key, label, table }, only while np_hud isn't running |
screen |
{ screen = 'lobby' | 'case' | 'profile' | 'owner' | nil, data }: focused menus (nil closes) |
invite / inviteGone |
A challenge invite card { id, name, mode, race, stake, table, bar, remote, expires } (without np_hud) / { id } |
match |
MatchState: the match snapshot for this player, with view = 'play' | 'wait' | 'spectate', camera, spec |
shot |
ShotMsg: the replay frames and events of a shot, its outcome, log line, board and final positions |
rack |
{ match, banner, board }: a rack was won |
ended |
{ match, result, board }: the match result |
aim |
{ match, aim = { angle, power, target, spinX, spinY, cam }, shooter, name }: the shooter's aim (spectators, opponent) |
react / reactCooldown |
A crowd reaction { match, src, name, id, crowd, heckle } / { id } |
chatter |
{ match, entry = { icon, tint, text, at } } |
bets / betsPanel |
{ match, board } (the bet board) / { open } |
spectateEnd / spectateCam |
{ match } / { mode = 'follow' | 'overhead' | 'player' | nil } |
chalked |
{ ok, chalk, item } |
NUI → Lua callbacks ​
POST https://np_billiards/<name> with a JSON body. Every callback answers { ok: true, ... } or
{ ok: false, code, error }; error is the English text of the code.
| Callback | Body | Notes |
|---|---|---|
ready |
– | Handshake: Lua answers with boot and flushes the queue |
close |
– | Closes the focused screen or the bet panel |
sound |
{ id } |
Plays a Config.Sounds frontend sound |
lobbyRefresh |
{ table } |
→ lobby RPC |
challenge |
{ table, mode, race, stake, target?, open? } |
→ challenge |
practice, takeOpen, cancelChallenge, queue, cupStart, cupClaim, startScheduled, respond |
see the RPCs | Closes the lobby on success where a match starts |
equip, retip, nickname, profile, openCase, openProfile |
see the RPCs | Cue case and profile |
ownerData, ownerHouse, ownerCloth, ownerVoid, ownerPause, cupCreate, cupBegin, cupJoin |
see the RPCs | Owner tablet |
aim |
{ angle, power, spinX, spinY, elevation, target, ghost, objDir, cueDir, pull, guide, stub } |
Client-local: moves the cue prop, the shoulder cam and the ped; forwards the aim to the server every aimBroadcastMs |
placeMove |
{ x, y } |
Client-local: moves the cue ball prop while placing |
place |
{ x, y } |
→ place with the match id and turn token |
shoot |
{ angle, power, spinX, spinY, elevation, wobble, safety, call = { ball, pocket }? } |
→ shoot with the match id and turn token |
camera |
{ mode = 'overhead' | 'shoulder' } |
Client-local; answers the mode actually used |
extend, leave, chalk |
– | → the RPCs of the same name (chalk also plays the chalk animation) |
replay |
– | Client-local: re-simulates the last shot record → { frames, events, slow } |
bet |
{ market, outcome, amount } |
→ bet |
Server RPCs ​
Client → server: TriggerServerEvent('np_billiards:rpc', id, name, payload); the answer comes back as the client
event np_billiards:rpc (id, result). Every call passes a global token bucket per player, a payload sanity check
(depth, keys, string sizes, finite numbers), a loaded character, the permission, a rate limit per RPC, one call in
flight per player and RPC, and a schema that drops unknown keys. Shot RPCs re-check the turn token and the distance
to the table.
tables -> { tables }
lobby { table } -> { lobby }
challenge { table, mode, race?, stake?, target?, open? } -> { id }
cancelChallenge { id }
respond { id, accept } -> { match? | accepted? }
takeOpen { id } -> { match }
startScheduled { id, table } -> { match }
practice { table, mode? } -> { match }
queue { table, join } -> { position? }
cupStart | cupClaim { table }
place { match, token, x, y }
shoot { match, token, angle, power, spinX, spinY, elevation, wobble?, safety?, call? } -> { n }
aim { match, token, angle, power, target, spinX, spinY, cam }
extend { match }
leave {}
chalk {} -> { chalk, item? }
state {} -> { match?, last? }
react { id } -> { crowd }
bet { match, market, outcome, amount } -> { board }
profile { cid? } -> { profile }
case {} -> { case }
equip { slot = cue|shaft|chalk|glove|breakCue|wrap|preset, value } -> { case }
retip { serial } -> { case }
nickname { nickname }
owner { bar? } -> OwnerData
ownerHouse { bar, house } -> { house }
ownerCloth | ownerVoid | ownerPause { table }
cupCreate { bar, name, mode, size, entry, rake, race, split, announce } -> { cup }
cupBegin | cupJoin { id } -> { cup }
calibrate {} (np_billiards.admin)
Error codes include invalid, too_far, busy, table_busy, table_closed, funds, funds_player,
stake_limit, no_target, not_found, stale (old turn token), not_your_turn, not_now, bad_spot,
no_extension, own_match, bets_locked, bet_limit, cooldown, not_owned, locked, in_match,
no_tip_kit, no_permission, rate_limited, not_ready, no_character. Each has a text in
shared/locales/en.lua (err_<code>).
Server → client events ​
| Event | Payload |
|---|---|
np_billiards:push |
{ action, data }, relayed into the NUI (toast, invite, inviteGone) |
np_billiards:client:tables |
Every public table (sent at load and on every status change, coalesced) |
np_billiards:client:match |
The match snapshot for this player |
np_billiards:client:shot |
The shot record: { match, n, start, strike, params, final, duration, shooter, call, outcome, log, board } |
np_billiards:client:rack / ended |
Rack banner / match result |
np_billiards:client:aim / react / chatter / bets |
Spectator streams |
np_billiards:client:spectateEnd |
You left the spectating range |
np_billiards:client:ownerBars |
The bars you own (for the np_menu option) |
np_billiards:client:openCase / chalked / calibrate |
Item use, chalk result, the staff overlay |
The client re-simulates strike from start with params (bit-identical: fixed 5 ms steps, only + - * / sqrt in
the loop), animates the ball props and sends the frames to the NUI (shot), then snaps to final.
Phone app ​
web/phone.html → web/dist/phone.html, loaded by np_phone as a custom app. It calls np_phone's app RPCs, which
np_billiards registers with registerAppRpc:
home -> { me, server, bar, barLabel, badges }
standings { scope = 'server' | 'bar' } -> { list }
cups -> { cups }
cup:join | cup:leave { id }
challenges -> { incoming, outgoing, rivals, tables, modes, bars }
challenge { cid, bar, mode, race, stake } -> { id }
challenge:respond { id, accept }
challenge:cancel { id }
tables -> { bars }
watch { table } -> { match, spec }
unwatch
Pushes to the app (sendAppMessage): changed (reload), shot ({ start, final, board, log } while watching),
ended ({ score, winner }). Tabs: League, Cups, Challenges, Tables. See Pool League app.