NUI natives
Talk to your HTML pages in the Neighborly overlay: send messages, give them focus and answer their callbacks.
Developer Preview. Scripting is live on Neighborly servers – everything on these pages works today. The API is young, so tell us what you need next on Discord.
Talk to your HTML pages in the Neighborly overlay: send messages, give them focus and answer their callbacks. See the NUI guide.
Open in the natives browser Search all 199 natives at once.
SendNUIMessage
void SendNUIMessage(table message)Sends a message to this resource's NUI page. The page receives it as a message event.
The message is turned into JSON, so functions and userdata are dropped and vector3 becomes { x, y, z }. Messages are queued until the page has loaded, so it is safe to send them right after the resource starts.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | table | Any table that can be turned into JSON. |
Returns
Nothing (void).
Example
RegisterNetEvent('rtx_phone:newMessage', function(from, text)
SendNUIMessage({ action = 'message', from = from, text = text, time = os.time() })
PlaySoundFrontend('phone_buzz', 0.6)
end)SetNuiFocus
void SetNuiFocus(boolean hasFocus, boolean hasCursor)Gives this resource's NUI page keyboard and mouse input, or hands it back to the game.
Forgetting to release focus is the most common NUI bug – players are stuck with a cursor. Release it when the page closes, and in onResourceStop.
Parameters
| Parameter | Type | Description |
|---|---|---|
hasFocus | boolean | Give the page the keyboard. |
hasCursor | boolean | Show the mouse cursor and let the page receive clicks. |
Returns
Nothing (void).
Example
local open = false
RegisterCommand('tablet', function()
open = not open
SetNuiFocus(open, open)
SendNUIMessage({ action = open and 'show' or 'hide' })
end, false)
RegisterNUICallback('close', function(_, cb)
open = false
SetNuiFocus(false, false)
SendNUIMessage({ action = 'hide' })
cb({ ok = true })
end)IsNuiFocused
boolean IsNuiFocused()Checks whether a NUI page currently has keyboard focus – useful to ignore key mappings while the player is typing in a UI.
True for any resource's page, not just yours – so your key bindings stay quiet while the player types in someone else's UI too.
Parameters
This native takes no parameters.
Returns
boolean true while any NUI page has focus.
Example
RegisterCommand('+radio', function()
if IsNuiFocused() or IsChatOpen() then
return
end
TriggerServerEvent('rtx_radio:talking', true)
end, false)
RegisterCommand('-radio', function()
TriggerServerEvent('rtx_radio:talking', false)
end, false)RegisterNUICallback
void RegisterNUICallback(string name, function handler)Handles a request from this resource's NUI page.
Runs as a thread, so you may wait – for example for TriggerServerCallback – before calling cb. The page's fetch stays pending until you do. NUI callbacks run on the player's PC: anything that costs money or changes the world must be decided by the server.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Callback name – the page POSTs to https://<resource>/<name>. |
handler | function | function(data, cb) – data is the decoded JSON body; call cb(response) exactly once. |
Returns
Nothing (void).
Example
RegisterNUICallback('deposit', function(data, cb)
local amount = tonumber(data.amount)
if not amount then
return cb({ ok = false, error = 'Enter an amount' })
end
local ok, result = TriggerServerCallback('rtx_bank:deposit', amount)
cb({ ok = ok == true, savings = ok and result or nil, error = not ok and result or nil })
end)