Koja Scripts
KOJA-LIB

DUI

DUI (Dynamic UI) allows you to render a web page as a texture on any in-game surface — screens, billboards, laptops, phones, etc.

DUI

DUI (Dynamic UI) allows you to render a web page as a texture on any in-game surface — screens, billboards, laptops, phones, etc.

CreateDui

Creates a new DUI instance.

local dui = KOJA.Client.CreateDui(opts)
FieldTypeDefaultDescription
urlstringURL to load inside the DUI
widthnumber1280Texture width in pixels
heightnumber720Texture height in pixels

Returns DuiInstance

DuiInstance

Properties

PropertyTypeDescription
idstringUnique identifier
urlstringCurrent URL
handlelongNative DUI handle
txdstringTexture dictionary name
txnstringTexture name

Methods

setUrl

Navigate the DUI to a new URL.

dui:setUrl(newUrl)

sendMessage

Send a JSON-serialisable message into the DUI's JavaScript.

dui:sendMessage(message)

The web page receives it as a message event. In your JS/TS:

window.addEventListener('message', (event) => {
    console.log(event.data)
})

getHandle / getTextureDict / getTextureName

dui:getHandle()       -- long
dui:getTextureDict()  -- string (txd name)
dui:getTextureName()  -- string (txn name)

replaceTexture

Replace an existing game texture with this DUI's texture.

dui:replaceTexture(originalTxd, originalTxn)

removeReplaceTexture

Restore the original texture.

dui:removeReplaceTexture(originalTxd, originalTxn)

destroy

Destroy the DUI and free resources.

dui:destroy()

Examples

Replace a game texture (e.g. a TV screen)

local dui = KOJA.Client.CreateDui({
    url    = 'https://www.youtube.com/embed/dQw4w9WgXcQ',
    width  = 1280,
    height = 720,
})

-- Replace the TV screen texture
dui:replaceTexture('prop_tv_flat_01', 'prop_tv_flat_01_emissive')

-- When done:
dui:removeReplaceTexture('prop_tv_flat_01', 'prop_tv_flat_01_emissive')
dui:destroy()

Draw DUI on a custom surface using scaleform

local dui = KOJA.Client.CreateDui({ url = 'nui://my-resource/screen.html' })

CreateThread(function()
    while true do
        Wait(0)
        DrawSprite(dui:getTextureDict(), dui:getTextureName(), 0.5, 0.5, 1.0, 1.0, 0.0, 255, 255, 255, 255)
    end
end)

Send live data to the DUI

local dui = KOJA.Client.CreateDui({ url = 'nui://my-resource/hud.html' })

CreateThread(function()
    while true do
        Wait(1000)
        dui:sendMessage({
            action = 'updateSpeed',
            speed  = GetEntitySpeed(GetPlayerPed(-1)) * 3.6,
        })
    end
end)
  • Callbacks — koja-lib provides a callback system that lets client scripts request data from the server and vice versa.
  • Inventory — Client-side inventory functions let you check what items the local player has without a server round-trip.
  • Money — Retrieve the local player's money balance from the client side via a server callback.
  • Keybinds — Register persistent key bindings that players can rebind in the GTA V settings menu.
  • Notifications — koja-lib provides two notification interfaces: SendNotify (routes through the configured backend) and LibNotify (built-in koja-lib notification).
  • Player — Functions for reading the local player's data on the client side.
  • Client API — back to the section overview