Notifications

CLIENT & SERVER

A unified system for managing multiple notification resources. Each supported resource is organized into a table of handlers, with a trigger function and type mapping.

This approach enables easy integration and switching between resources. Developers can simply extend the handlers table to add support for additional resources if required.

Handlers

Table of handlers for notification resources. Covered by default: boii_ui, ox_lib, qb-core, es_extended, okokNotify

Client

local handlers = {
    default = function(options)
        TriggerEvent('boii_utils:notify', { type = options.type, header = options.header, message = options.message, duration = options.duration })
    end,
    boii_core = function(options)
        TriggerEvent('boii_core:notify', { type = options.type, header = options.header, message = options.message, duration = options.duration })
    end,
    boii_ui = function(options)
        TriggerEvent('boii_ui:notify', { type = options.type, header = options.header, message = options.message, duration = options.duration })
    end,
    ox_lib = function(options)
        TriggerEvent('ox_lib:notify', { type = options.type, title = options.header, description = options.message })
    end,
    es_extended = function(options)
        TriggerEvent('ESX:Notify', options.type, options.duration, options.message)
    end,
    ['qb-core'] = function(options)
        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)
    end,
    okokNotify = function(options)
        TriggerEvent('okokNotify:Alert', options.header or 'Notification', options.message, options.type, options.duration or 5000)
    end
}

Server

Server side notifications require a source player

local handlers = {
    default = function(_src, options)
        TriggerClientEvent('boii_utils:notify', _src, { type = options.type, header = options.header, message = options.message, duration = options.duration })
    end,
    boii_core = function(_src, options)
        TriggerClientEvent('boii:notify', _src, { type = options.type, header = options.header, message = options.message, duration = options.duration })
    end,
    boii_ui = function(_src, options)
        TriggerClientEvent('boii_ui:notify', _src, { type = options.type, header = options.header, message = options.message, duration = options.duration })
    end,
    ox_lib = function(_src, options)
        TriggerClientEvent('ox_lib:notify', _src, { type = options.type, title = options.header, description = options.message })
    end,
    es_extended = function(_src, options)
        TriggerClientEvent('ESX:Notify', _src, options.type, options.duration, options.message)
    end,
    ['qb-core'] = function(_src, options)
        local type_mapping = { information = 'primary', info = 'primary' }
        options.type = type_mapping[options.type] or options.type
        TriggerClientEvent('QBCore:Notify', _src, options.message, options.type, options.duration)
    end,
    okokNotify = function(_src, options)
        TriggerClientEvent('okokNotify:Alert', _src, options.header or 'Notification', options.message, options.type, options.duration or 5000)
    end
}

Client Functions

notify

Sends a notification to client player.

--- Utils object
utils.ui.notify({
    header = 'Test Notification',
    message = 'Just another test notification..',
    type = 'info',
    duration = 3500
})

--- Direct export
exports.boii_utils:notify(...)

Server Functions

notify

The same as client side, except here we pass the players source.

--- Utils object
utils.ui.notify(_src, {
    header = 'Test Notification',
    message = 'Just another test notification..',
    type = 'info',
    duration = 3500
})

--- Direct export
exports.boii_utils:notify(...)

Last updated