Dependencies on Notification Resources

Hello folks,

I’ve seen a number of resources of late that create dependencies on specific notification resources. It is rather simple to create an event which allows you to give users the ability to select from a number of different notification systems, or add their own. This is mostly designed for paid resource developers however for ease of development it can be added to open-source resources as well.

Add this code to a client-side file in your resource, ideally one that is not escrow encrypted:

RegisterNetEvent('example:client:notify')
AddEventHandler('example:client:notify', function(notifText, notifType)
    if Config.Notification == 'ox_lib' then
        lib.notify({
            description = notifText,
            type = notifType
        })
    elseif Config.Notification == 'esx' then
        ESX.ShowNotification(notifText, notifType, 3000)
    elseif Config.Notification == 'okokNotify' then
        exports['okokNotify']:Alert('Notification', notifText, 3000, notifType, false)
    elseif Config.Notification == 'custom' then
        -- Add custom event here
    end
end)

Then in a config.lua (or similar file) add a config option similar to below:

Config.Notification = 'ox_lib' -- 'ox_lib', 'esx', 'okokNotify' or `custom`.

Once this is done, all you need to do is add this anywhere you want to send a notification:

Client-side

TriggerEvent('example:client:notify', 'Test Text', 'inform')

Server-side

TriggerServerEvent('example:client:notify', source, 'Test Text', 'inform')

If you want to parse different config options (such as duration) this is easy enough to do. On the client event, add a new variable to the event then call it anywhere within the event that you want to use the information. If you look at how notifText and notifType work you’ll get the gist of it. This style will also work for any funtions/exports that share similar styles, such as DrawTextUI resources and such.

1 Like