πŸ””Notifications

Our built-in notifications support okokNotify, ox notify, mythic notify and qbcore built-in notify. However, maybe you have a different notification system that you would like to use. That's no problem!

Step 1: Finding the notification system

Go to the sg-panning/bridge/client/qb.lua file and search for the function Notify. You will see the following text within the function:

function Notify(title, msg, type)
    if type == 'success' then

        if SharedConfig.Notify == 'okok' then
            exports['okokNotify']:Alert(title, msg, 3000, 'success', true)
        elseif SharedConfig.Notify == 'ox' then
            lib.notify({
                title = title,
                description = msg,
                type = 'success'
            })
        elseif SharedConfig.Notify == 'mythic' then
            exports['mythic_notify']:DoHudText('success', msg)
        elseif SharedConfig.Notify == 'qb' then
            QBCore.Functions.Notify({
                text = title,
                caption = msg,
            }, 'success', 3000)
        end

elseif type == 'error' then

    if SharedConfig.Notify == 'okok' then
        exports['okokNotify']:Alert(title, msg, 3000, 'error', true)
    elseif SharedConfig.Notify == 'ox' then
        lib.notify({
            title = title,
            description = msg,
            type = 'error'
        })
    elseif SharedConfig.Notify == 'mythic' then
        exports['mythic_notify']:DoHudText('error', msg)
    elseif SharedConfig.Notify == 'qb' then
        QBCore.Functions.Notify({
            text = title,
            caption = msg,
        }, 'error', 3000)
    end
    end
    
end

Step 2: Implementing your own

If you'd like to add your own system then you can as long as you know what code to implement. A lot of times you can find the correct code in the documentation of your notification system.

Just add the following to the piece of code:

elseif SharedConfig.Notify == -- Name of notification system in strings -- 
               then
                --Code of your notification system*

Make sure to paste it within the code before the end, otherwise it will not run and things may break. See where to implement in the code below. Also make sure that for type you always use either 'success' or 'error' as these are the two types we identified and are using in the script.

function Notify(title, msg, type)
    if type == 'success' then

        if SharedConfig.Notify == 'okok' then
            exports['okokNotify']:Alert(title, msg, 3000, 'success', true)
        elseif SharedConfig.Notify == 'ox' then
            lib.notify({
                title = title,
                description = msg,
                type = 'success'
            })
        elseif SharedConfig.Notify == 'mythic' then
            exports['mythic_notify']:DoHudText('success', msg)
        elseif SharedConfig.Notify == 'qb' then
            QBCore.Functions.Notify({
                text = title,
                caption = msg,
            }, 'success', 3000)
        -- IMPLEMENT THE CODE HERE
        end

elseif type == 'error' then

    if SharedConfig.Notify == 'okok' then
        exports['okokNotify']:Alert(title, msg, 3000, 'error', true)
    elseif SharedConfig.Notify == 'ox' then
        lib.notify({
            title = title,
            description = msg,
            type = 'error'
        })
    elseif SharedConfig.Notify == 'mythic' then
        exports['mythic_notify']:DoHudText('error', msg)
    elseif SharedConfig.Notify == 'qb' then
        QBCore.Functions.Notify({
            text = title,
            caption = msg,
        }, 'error', 3000)
    -- IMPLEMENT THE CODE HERE  
    end
    end
    
end

Step 3: Make sure to change the server file too!

Not only are we using notifications client-sided, but we are also using a lot of notifications server-sided. Make sure to add your custom notification system in the sg-panning/server/qb.lua file too. Please note that this is a TriggerClientEvent and often different from the client export!

This is where you should add in the server-file:

function Notify(title, msg, type)
    if type == 'success' then

        if SharedConfig.Notify == 'okok' then
            TriggerClientEvent('okokNotify:Alert', source, title, msg, 3000, 'success', true)
        elseif SharedConfig.Notify == 'ox' then
            TriggerClientEvent('ox_lib:notify', source, 
            {
                title = title,
                description = msg,
                type = 'success'
            })
        elseif SharedConfig.Notify == 'mythic' then
            TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'success', text = msg})
        elseif SharedConfig.Notify == 'qb' then
            QBCore.Functions.Notify({
                text = title,
                caption = msg,
            }, 'success', 3000)
        -- INSERT CODE HERE    
        end

elseif type == 'error' then

    if SharedConfig.Notify == 'okok' then
        TriggerClientEvent('okokNotify:Alert', source, title, msg, 3000, 'error', true)
    elseif SharedConfig.Notify == 'ox' then
        TriggerClientEvent('ox_lib:notify', source, 
        {
            title = title,
            description = msg,
            type = 'error'
        })
    elseif SharedConfig.Notify == 'mythic' then
        TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'error', text = msg})
    elseif SharedConfig.Notify == 'qb' then
        TriggerClientEvent('QBCore:Notify', source, {text = title, caption = msg}, 'error')
    -- INSERT CODE HERE
    end
    end
end

Step 4: Testing

Basically you're all done, but make sure that you have tested before officially releasing it in your already airing FiveM server to prevent player inconveniences.

Last updated