Pro Tip: Don’t create dependencies on notification resources. It is easy enough to create your own event and use config options for users to select what notification system they want their community to use. You can even add an option to allow people to add their own notification events/exports in.
Here’s a suggestion. 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('House Robbery', notifText, 3000, notifType, false)
elseif Config.Notification == 'custom' then
-- Add custom event here
end
end)
Then add a config option to config.lua
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:
TriggerEvent('example:client:notify', 'Test Text', 'inform') -- Client-side event
TriggerServerEvent('example:client:notify', source, 'Test Text', 'inform') -- Server-side event
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.