class Nui
package fivem.client.core
The bridge to a resource's NUI layer — the embedded browser used for HTML user interfaces.
Nui.send({action: "openMenu", items: menuItems});
Nui.setFocus(true, true);
Nui.on("closeMenu", (data, respond) -> {
Nui.setFocus(false, false);
respond({ok: true});
});
Every callback must call respond. The browser side awaits the HTTP
response from fetch, and a callback that never responds leaves that
promise pending forever — the usual cause of a UI that stops reacting after
one interaction.
Focus is global to the game, not to your resource. Always clear it when your UI closes, including from a resource stop handler, or the player is left unable to move.
Static methods
staticclose():Void
Clears focus and tells the UI to close.
Register this as a resource stop handler so a restart can't strand the player with a captured cursor and no way to move:
Resource.onStop(Nui.close);staticon(name:String, handler:(data:Dynamic, respond:(response:Dynamic) ‑> Void) ‑> Void):Void
Registers a handler for a callback the NUI frame invokes by POSTing to
https://<resource>/<name>.
The handler receives the decoded request body and a respond function
to send the reply back.
staticinlinesend(payload:Dynamic):Void
Sends a message to the NUI frame. Received in JavaScript as a
message event, with the payload on event.data.
The value is JSON-encoded, so pass plain data — anonymous structures, arrays, numbers and strings.
staticinlinesetFocus(hasFocus:Bool, hasCursor:Bool):Void
Grants or removes NUI input focus.
Parameters:
hasFocus | Whether the browser receives keyboard input. While true the player cannot move or act. |
|---|---|
hasCursor | Whether the mouse cursor is shown and captured. |
staticinlinesetFocusKeepInput(keepInput:Bool):Void
Lets game input keep working while NUI has focus — for a HUD overlay that shows a cursor but shouldn't stop the player moving.