Skip to content

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. You only need this page to change the UI or write your own front end; resources that work with rounds use the exports.

The NUI is server-authoritative: it only sends intents. The swing sends click times, never a power or a distance; the server re-computes everything and sends back the ball's path.

Messages ​

Lua → NUI: SendNUIMessage({ action, data }). Messages sent before the NUI posted ready are queued (up to 80).

Action Data
boot { locale, currency, scale, yardsPerMetre, meter, putt, clubs, shapes, lofts, lies, balls, formats, rules, sideBets, propBets, course = { label, sub, holes, water, boundary }, betting, economy, me }: everything the HUD needs to draw the preview with the server's physics
theme { brand?, strength, material }: np_admin's server theme (Config.Material 'frosted' / 'liquid' wins over 'server'), sent as { action = 'theme', type = 'theme', data } at ready and on every change
screen { name, data } opens a focused screen, { name = false } closes it
hud The in-world HUD state (hole, chips, club, meter, shot plan), or false to hide it
round The round view after every change
lobby The player's group in the clubhouse, or false
result The shot summary for the launch-monitor card
score A hole score for the score toast (birdie, eagle …)
caddie A caddie tip bubble (NPC or player)
caddieJob / caddieView The caddie's assignment and their view of the golfer's shot
prop A prop bet offer or update
flyover { on, … } while a hole flyover plays
toast A toast while np_hud isn't running

Screens ​

web/src/screens/: clubhouse, scorecard, bets, bag, caddie. They take NUI focus; Esc (and TAB on the scorecard) posts close. The tee, putt, result, walk and spectate views are the HUD layer (web/src/hud/Hud.tsx) without focus. While the HUD or a screen is up, np_golf claims np_hud's screen corners (ClaimZones).

Callbacks ​

NUI → Lua, https://np_golf/<name>:

Callback Body What
ready – The NUI is up: Lua sends theme, boot and the queued messages
close – Close the focused screen
action { type = 'bag' | 'bets' | 'scorecard' | 'clubhouse' | 'waypoint', round?, x?, y? } Local actions without a server round trip
rpc { name, payload } Forwarded to the server RPC of that name, if the client allows it (below). Answers the result table

Server RPCs ​

Wire: TriggerServerEvent('np_golf:rpc', id, name, payload), answered with TriggerClientEvent('np_golf:rpc', src, id, result); 10 s timeout. Every result is a table with ok; errors carry a code. The server checks, in this order: a global token bucket per player (Config.Security.rpcPerSecond), payload sanity, a loaded character, the permission node, a per-RPC rate limit, one call in flight per player and name, then the schema (unknown keys are dropped).

The NUI may call (whitelist in client/02_nui.lua):

lobby.state    { cart?, caddie?, range? }                    tee sheet, my group, open groups, checkout, caddies, fees
lobby.create   { slot, public?, format?, holes? }
lobby.join     { group }      lobby.leave      lobby.invite { target }
lobby.set      { kind = 'rule'|'stake'|'format'|'public'|'holes', key?, value… }
lobby.checkout { cart?, caddie?, range? }
lobby.ready    { cart?, caddie?, range?, tip? }              Pay & lock (yields while the np_payments sheet is open)
lobby.unready  lobby.start   lobby.member   lobby.practice
round.state    round.pickup  round.concede { cid }  round.gimme  round.mulligan  round.quit
round.ball     { ball }       round.rateCaddie { stars }
bag.state      bag.prefs { ball?, tracer? }
bets.state     { round? }
bets.place     { round, market = 'winner'|'hole'|'longdrive', selection, stake }
bets.propose   { template, to, stake }
bets.respond   { id, accept?, counter? }
spectate.list  spectate.join { round?, on? }
caddie.duty    { on, fee? }   caddie.act { power?, heading?, club?, text? }   caddie.tip { pct }
me.state       me.limit { amount }   me.break { days }

Called by the Lua client only: boot, round.shot { token, club, shape?, loft?, heading?, t = [t1, t2, t3?] }, round.settle { hint?, z? }, cart.request and course.survey { hole, samples } (np_golf.survey).

The Fairway app reaches a subset through np_phone's registerAppRpc: home → lobby.state, join → lobby.join, live → spectate.list, watch → spectate.join, bets → bets.state, place → bets.place, me → me.state, limit → me.limit, break → me.break, round → round.state.

Server → client events ​

np_golf:round, np_golf:turn (with the one-shot shot token), np_golf:hole, np_golf:shot (the simulated path, to the group and spectators), np_golf:settled, np_golf:holeDone, np_golf:finished, np_golf:lobby, np_golf:invite, np_golf:prop, np_golf:caddieTip, np_golf:caddieJob, np_golf:caddieView, np_golf:cart, np_golf:toast. They are internal: listen to the server events instead.