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 = {
    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
    --- Add other resources here
}

Server

Server side notifications require a source player

local handlers = {
    boii_ui = function(_src, options)
        TriggerEvent('boii_ui:notify', _src, {
            type = options.type,
            header = options.header,
            message = options.message,
            duration = options.duration
        })
    end,
    ox_lib = function(_src, options)
        TriggerEvent('ox_lib:notify', _src, {
            type = options.type,
            title = options.header,
            description = options.message
        })
    end,
    es_extended = function(_src, options)
        TriggerEvent('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
        TriggerEvent('QBCore:Notify', _src, options.message, options.type, options.duration)
    end,
    okokNotify = function(_src, options)
        TriggerEvent('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.

Function

local function notify(options)
    if not options or not options.type or not options.message then
        print('Invalid notification data provided.')
        return
    end
    local handler = handlers[NOTIFICATIONS] or handlers['boii_ui']
    handler(options)
end

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

Example

--- 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.

Function

local function notify(_src, options)
    if not options or not options.type or not options.message then
        print('Invalid notification data provided.')
        return
    end
    local handler = handlers[NOTIFICATIONS] or handlers['boii_ui']
    handler(_src, options)
end

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

Example

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

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

Guides

Initial Setup

Currently the utils library requires the UI resources be defined within the config. This may be moved to resource detection in future however for now it has not been needed.

To set your chosen UI resources head to server/config.lua Find the following section and pick your choices.

--- UI Bridge settings
--- @field drawtext: Specifies the active progressbar system. Options: 'boii_ui', 'qb-core', 'es_extended', 'ox_lib', 'okokTextUI', 'custom'.
--- @field notify: Specifies the active notification system. Options: 'boii_ui', 'qb-core', 'es_extended', 'ox_lib', 'okokNotify', 'custom'.
--- @field progressbar: Specifies the active progressbar system. Options: 'boii_ui', 'custom'.
config.ui = {
    drawtext = 'boii_ui',
    notify = 'boii_ui',
    progressbar = 'boii_ui'
}

If your desired resource is not already covered by default follow the instructions below on how to add a new handler.

Adding Handlers

To add support for addition resources you need to add a handler into the handlers table inside .../bridges/notifications.lua

--- Client side
local handlers = {
    ...

    ['your resource name'] = function(options)
        --- Add custom implementation here
    end,
}

--- Server sude
local handlers = {
    ...

    ['your resource name'] = function(source --[[pass source player]], options)
        --- Add custom implementation here
    end,
}

Once you have added your handler, update the config.ui.notify value to what you have set 'your resource name' as and you should be good to go.

If for any reason you are unable to set this up yourself put a support post in the discord.

Last updated