Skip to content

NUI contract (Lua ⇄ web) ​

This is the single source of truth for messages between the Lua client and the NUI. Both sides must implement exactly this. The source file lives in the resource at docs/nui-contract.md; keep both in sync. Types are TypeScript-ish; every field marked ? is optional. All hud:* payloads are partial merges: send only what changed, the NUI keeps the rest.

Lua → NUI: SendNUIMessage({ action = <name>, data = <payload> }) ​

action payload notes
hud:config HudConfig sent once after the NUI posts ready, and again on config change
hud:visible { visible: boolean, reason?: string } hide whole HUD (pause menu, cinematic, /hud)
hud:claims { zones: HudZone[] } zones other UIs claimed (ClaimZones); they hide, toasts move to the free top corner
hud:player Partial<PlayerState> ~4×/s while changing; only diffs
hud:vehicle Partial<VehicleState> inVehicle=false hides the vehicle zone
hud:weapon Partial<WeaponState> armed=false hides the weapon card
theme { brand?: string, strength?: 'accent'|'tiles'|'glass' } brand empty/nil → neutral
notify Notification push a toast; same id replaces an existing one
notify:dismiss { id: string }
notify:clear {}
notify:key { key: string } a bound key (e.g. Y/N) was pressed in-game; NUI resolves it against the newest actionable toast
prompt:show Prompt interaction prompt (centre); same id replaces
prompt:hide { id?: string } no id → hide all
progress:start Progress one at a time; NUI animates for duration ms
progress:cancel { id: string }

NUI → Lua: fetch('https://np_hud/<name>', { method:'POST', body: JSON }) ​

name body response
ready {} { ok: true } — Lua then sends hud:config + full state
notifyAction { id: string, action: string } { ok: true } — Lua fires local event np_hud:notifyAction (id, action) and, if the toast came from the server, TriggerServerEvent('np_hud:server:notifyAction', id, action)
progressDone { id: string, cancelled: boolean } { ok: true }

Types ​

ts
type Tint = 'neutral'|'red'|'orange'|'rust'|'pink'|'olive'|'lilac'|'green'|'blue'|'aqua'|'brand';
type HudZone = 'top-right'|'top-left'|'top-center'|'center'|'bottom-left'|'bottom-right'|'bottom-center';

interface HudConfig {
  locale: string;                       // 'en' | 'de' ...
  units: 'kmh' | 'mph';
  server: { name: string; logo?: string /* single char or URL */ };
  theme: { brand?: string; strength?: 'accent'|'tiles'|'glass' };
  scale: number;                        // 1 = designed for 1920x1080; NUI multiplies by viewport height / 1080
  streamerMode: boolean;                // hides server id
  maxToasts: number;                    // default 4
  components: {                         // which zones render
    topBar: boolean; money: boolean; job: boolean; players: boolean; weather: boolean;
    status: boolean; voice: boolean; street: boolean; compass: boolean; minimapFrame: boolean;
    vehicle: boolean; weapon: boolean; notifications: boolean;
  };
  status: Array<'health'|'armor'|'hunger'|'thirst'|'stamina'|'stress'|'oxygen'>; // order + selection
  lowThreshold: number;                 // percent, default 20 → .is-low
  minimap: { x: number; y: number; w: number; h: number }; // frame rect in px @1080p, matches native minimap placement
}

interface PlayerState {
  id: number; players: number; maxPlayers: number;
  health: number; armor: number; hunger: number; thirst: number; stamina: number; stress: number; oxygen: number; // 0..100
  underwater: boolean; dead: boolean;
  cash: number; bank: number; job: { label: string; grade?: string; icon?: string };
  time: string;            // "09:14" (in-game)
  weather: { label: string; icon: string /* fa name, no prefix */ };
  street: string; zone: string; heading: number; // degrees 0..360, 0 = north
  voice: { range: 1|2|3; label: string; talking: boolean; radio?: string|null; radioTalking?: boolean; muted?: boolean };
}

interface VehicleState {
  inVehicle: boolean; name: string; plate: string;
  kind: 'car'|'bike'|'boat'|'heli'|'plane'|'other'; // legacy 'air' is still accepted and shown as 'plane'
  speed: number;           // already converted to config units, or knots when speedUnit = 'kts'
  maxSpeed: number;        // for the arc (same unit as speed)
  speedUnit?: string;      // 'kts' → label "KTS"; anything else ('' or missing) → config.units (KM/H / MPH)
  rpm: number;             // 0..1 inner arc: engine rpm (car/bike), rotor speed (heli), throttle (plane/boat)
  gear: number|string;     // 0 → 'R', 'N'; boats send 'F'|'N'|'R'. Aircraft show no gear tile
  fuel: number; engine: number; // 0..100
  fuelType?: string;       // np_fuel type: 'petrol'|'premium'|'diesel'|'kerosene'|'electric', '' = unknown. 'electric' → battery tile
  seatbelt: boolean;       // true = buckled
  lights: boolean; cruise: boolean; locked: boolean; showBelt: boolean; // showBelt=false for bikes etc.

  // heli + plane
  altitude?: number;       // ft above mean sea level ("ALT 1,255 FT")
  agl?: number;            // ft above ground level (plane alerts)
  climb?: number;          // ft/min, signed, + = climbing
  pitch?: number;          // degrees, nose up +
  roll?: number;           // degrees, right wing down +
  // boat compass (vehicle bearing, NOT player.heading): 0..359, 0 = N, 90 = E
  course?: number;
  // heli
  rotor?: number;          // rotor health 0..100
  searchlight?: boolean; hover?: boolean;
  // plane
  hasGear?: boolean;       // retractable landing gear fitted
  gearDown?: boolean; autopilot?: boolean;
  // boat
  anchor?: boolean;
  depth?: number;          // metres of water under the boat, -1 = unknown ("—")
  hull?: number;           // hull health 0..100
}

interface WeaponState { armed: boolean; name: string; icon?: string; clip: number; clipSize: number; reserve: number; }

interface Notification {
  id?: string;             // generated by NUI if missing
  type?: 'info'|'success'|'warning'|'error';   // default info
  variant?: 'default'|'compact'|'announce'|'staff'|'call';
  app?: string; title?: string; message?: string; // message supports **bold** only (no HTML)
  icon?: string; tint?: Tint; badge?: number;
  duration?: number;       // ms, default 5000; 0 = sticky
  progress?: number;       // 0..100 → shows static bar instead of timer
  meta?: Array<{ icon: string; label: string }>;
  actions?: Array<{ id: string; label: string; key?: string /* 'Y' */; style?: 'default'|'primary'|'success' }>;
  sound?: boolean;
}

interface Prompt { id: string; icon?: string; tint?: Tint; keys: Array<{ key: string; label: string }>; }
interface Progress { id: string; label: string; icon?: string; duration: number; tint?: Tint; cancelKey?: string; }

Public Lua API ​

See Exports. Client exports: Notify(data | title, message?, type?, duration?) → id, DismissNotify(id), ShowPrompt(prompt), HidePrompt(id?), Progress(data) → boolean (blocking, returns true if finished), SetTheme(brand, strength), SetVisible(bool), SetSeatbelt(bool), IsVisible(). Server exports: Notify(src, data), NotifyAll(data), Announce(data). Events: client np_hud:client:notify (data), local np_hud:notifyAction (id, action), server np_hud:server:notifyAction (id, action).

Lua notes ​

Clarifications from the Lua side (client/). They don't change the contract above.

  • Diffing. hud:player, hud:vehicle and hud:weapon only carry top-level keys whose value changed. Nested objects (job, weather, voice) are compared deeply and always sent complete. After ready, Lua sends hud:config, theme, the full cached state of all three channels, hud:visible, all shown prompts and any toasts queued before the NUI was ready.
  • voice.radio. Lua sends false (not null) when the player isn't on a radio, because a Lua nil field disappears from JSON. Treat any falsy value as "no radio".
  • heading. Compass bearing (0 = N, 90 = E, clockwise). It follows the gameplay camera by default (-GetGameplayCamRot(2).z), or the ped/vehicle (360 - GetEntityHeading) with Config.CompassFollowsCamera = false. It's sent by the vehicle loop (100 ms) in a vehicle and by the player loop (500 ms) on foot.
  • minimap. Lua uses the same rect as the NUI: 1080p px from the top-left, scaled by screen height / 1080 only (see Development → NUI implementation notes). The native minimap is placed to fill the whole rect, under the 5px ring.
  • Standalone. Without a framework, components.money and components.job are false, and hunger, thirst and stress are removed from status. Those fields are never sent. ESX without esx_status drops hunger and thirst, and ESX drops stress unless an esx_status entry named stress shows up.
  • hud:visible.reason is one of pause, loading (character not loaded or player switch), user (/hud) or api (SetVisible(false)). It is omitted when the HUD is visible.
  • Ids. Toasts created on the client get cl:* ids and toasts from the server get sv:* ids. notifyAction for an sv:* id is forwarded to the server, which checks it. Progress ids are pg:* when the caller doesn't supply one.
  • notify:key is only sent while an actionable toast may still be on screen. key is the configured logical key (Config.NotifyKeys), even if the player rebound it.
  • progress:start.cancelKey is always Config.Progress.cancelKey (the hudcancel key mapping's default) and is left out when canCancel = false.
  • Vehicle kinds. kind comes from GetVehicleClass: 8 and 13 → bike, 14 → boat, 15 → heli, 16 → plane, 21 → other, everything else car. Lua no longer sends air.
  • Knots. With Config.Vehicle.knots, boats, helicopters and planes get speed and maxSpeed in knots and speedUnit = 'kts'. Every vehicle entry sends speedUnit ('' for km/h / mph), because a nil never reaches the NUI through the diff and a stale 'kts' would survive a kind change.
  • Per-kind fields. Only the natives for the current kind run. Planes and boats overwrite rpm with the throttle (0..1); helicopters keep the engine RPM, which follows the rotor spin-up. course is the vehicle's own bearing even when the compass follows the camera. depth is probed every 500 ms at most. hover and autopilot mirror LocalPlayer.state.hover / LocalPlayer.state.autopilot.