Notifications

The utils.ui module contains some useful bridge functions for common NUI resources. You should choose your resource choice within server/config.lua.

You can add additional resources to cover also if required.

Functions

notify()

Sends a notification using chosen resource.

Function

local function notify(options)
    if not options or not options.type or not options.message then
        print('Invalid notification data provided')
        return
    end

    if NOTIFICATIONS == 'boii_ui' then
        TriggerEvent('boii_ui:notify', { type = options.type, header = options.header, message = options.message, duration = options.duration })
    elseif NOTIFICATIONS == 'ox_lib' then
        TriggerEvent('ox_lib:notify', { type = options.type, title = options.header, description = options.message })
    elseif NOTIFICATIONS == 'es_extended' then
        TriggerEvent('ESX:Notify', options.type, options.duration, options.message)
    elseif NOTIFICATIONS == 'qb-core' then
        local type_mapping = { information = 'primary', info = 'primary' }
        options.type = type_mapping[options.type] or options.type
        TriggerEvent('QBCore:Notify', options.message, options.type, options.duration)
    elseif NOTIFICATIONS == 'okokNotify' then
        TriggerEvent('okokNotify:Alert', options.header or 'Notification', options.message, options.type, options.duration or 5000)
    else
        TriggerEvent('boii_ui:notify', { type = options.type, header = options.header, message = options.message, duration = options.duration })
    end
end

exports('ui_notify', notify)
utils.ui.notify = notify

Example

--- Send notifications.
utils.ui.notify({ 
    type = 'success',
    header = 'Test Notification',
    message = 'Test notification message.',
    duration = 3500
})

Last updated