Skip to content
GAMPEONCreate
New project
Preview: this works today, but details can still change.

Web interfaces (NUI)

HTML pages of a resource (ui_page) drawn over the game, with messages and callbacks like FiveM NUI.

SendNUIMessage(data) --> boolean

Send data to the page of this resource. Client only.

The page receives it as the data of a message event: window.addEventListener(‘message’, (e) => { … e.data … }). The data is sent as JSON, at most 1 MB.

Parameter Type Description
data table Any value that converts to JSON, usually a table with a type field.

Returns

  • boolean: Always true.
SendNUIMessage({ type = 'open', items = { 'bread', 'water' } })

Compared to FiveM: Same as in FiveM.

SendNuiMessage(jsonString) --> boolean

Send a JSON text to the page of this resource. Client only.

Parameter Type Description
jsonString string A JSON text, for example from json.encode.

Returns

  • boolean: false if the text is not valid JSON.

Compared to FiveM: Same as in FiveM.

RegisterNUICallback(callbackType, callback) --> EventHandle

Answer requests from the page of this resource. Client only.

The page calls fetch(https://${GetParentResourceName()}/name, { method: ‘POST’, body: JSON.stringify(data) }). The handler gets the decoded body and a function cb to answer; the page gets the answer as JSON. If the handler fails or does not answer within 30 seconds, the page gets an error.

Parameter Type Description
callbackType string Name in the URL, for example “close”.
callback fun(data: any, cb: fun(result: any)) Called with the request body; call cb once with the answer.

Returns

  • EventHandle: Handle for RemoveEventHandler.
RegisterNUICallback('close', function(data, cb)
SetNuiFocus(false, false)
cb('ok')
end)

Compared to FiveM: Same as in FiveM. The low-level form with RegisterNuiCallbackType and AddEventHandler(‘__cfx_nui:name’) is not supported.

SetNuiFocus(hasFocus, hasCursor)

Give keyboard and mouse to the pages, or give them back to the game. Client only.

Focus is shared by all resources; the last call wins. When the resource that set the focus stops, the focus goes back to the game. Players can always take the focus back with a fixed key of the game.

Parameter Type Description
hasFocus boolean Pages get the keyboard.
hasCursor boolean Pages get the mouse and the cursor is shown.
RegisterCommand('inventory', function()
SendNUIMessage({ type = 'open' })
SetNuiFocus(true, true)
end)

Compared to FiveM: Same as in FiveM.

SetNuiFocusKeepInput(keepInput)

Let the game keep getting keyboard input while a page has focus. Client only.

Parameter Type Description
keepInput boolean true: player can still move while the page has focus.

Compared to FiveM: Same as in FiveM.

IsNuiFocused() --> boolean

Whether a page has the keyboard focus. Client only.

Returns

  • boolean: true while a page has focus.

Compared to FiveM: Same as in FiveM.

IsNuiFocusKeepingInput() --> boolean

Whether the game keeps keyboard input while a page has focus. Client only.

Returns

  • boolean: The value set with SetNuiFocusKeepInput.

Compared to FiveM: Same as in FiveM.

Report a problem with this pageOther ways to give feedback