OverflowOverflow
UI Library

Alert

A confirm / cancel dialog. Blocking: the export waits for the player and returns their answer, so it must be called from a thread.

A dialog titled "Sell vehicle" with markdown body and Cancel / Confirm buttons

alert

local answer = exports.of_ui:alert(data, timeout)
FieldTypeDescription
headerstringDialog title.
contentstringBody text. Markdown is rendered.
sizestring?xs, sm, md, lg, xl.
cancelboolean?Show a cancel button next to confirm. Without it the dialog is a notice with one button.
labelstable?{ confirm?: string, cancel?: string }: override the button text.
ArgumentTypeDescription
timeoutnumber?of_ui: auto-close after this many milliseconds.

Returns 'confirm', 'cancel', or nil when the dialog was closed some other way.

CreateThread(function()
    local answer = exports.of_ui:alert({
        header = 'Sell vehicle',
        content = 'Sell this vehicle for **$12,500**? This cannot be undone.',
        cancel = true,
    })

    if answer == 'confirm' then
        TriggerServerEvent('myresource:sellVehicle')
    end
end)

closeAlert

exports.of_ui:closeAlert(reason)

Closes the open dialog from code: a timer expiring, the player driving away, a job ending.

ArgumentTypeDescription
reasonstring?of_ui: rejects the waiting alert call with this string instead of resolving it to nil.

Without a reason the pending alert returns nil. With one it raises an error in the waiting thread, so wrap the call if you use it:

CreateThread(function()
    -- auto-closes with reason 'timeout' after 10s
    local ok, answer = pcall(function()
        return exports.of_ui:alert({
            header = 'Accept the job?',
            content = 'The dispatcher is waiting.',
            cancel = true,
        }, 10000)
    end)

    if not ok then
        print('dialog closed early:', answer) -- 'timeout'
        return
    end

    if answer == 'confirm' then ... end
end)

Notes

  • One dialog at a time. Calling alert while another is open returns nil immediately instead of queuing.

  • Notices. Leave cancel out for a one-button acknowledgement:

    exports.of_ui:alert({ header = 'Notice', content = 'The garage is closed.', size = 'sm' })
  • From the server, trigger the of_ui:alert client event. The answer stays on the client: if you need it back, send it yourself:

    TriggerClientEvent('of_ui:alert', source, { header = 'Warning', content = 'Last chance.' })

On this page