#Replace default ox_lib notify with a custom one

1 messages · Page 1 of 1 (latest)

merry ginkgo
#

Hello! People keep asking this question, so I decided to make a small tutorial for it. This depends on the notification system you are using, but for this demo purposes we will be using okokNotify.

The file we want to edit is located at ox_lib/resource/interface/client/notify.lua
Line 33 should contain function lib.notify(data)

This function is called whenever we want to display a notification. It accepts data table, more info can be found on COX docs page: https://coxdocs.dev/ox_lib/Modules/Interface/Client/notify#libnotify

In our case, we want to replace ox_lib notify with okokNotify. According to okok docs (https://docs.okokscripts.io/scripts/okoknotify#client-side), we should use this client side export:
exports['okokNotify']:Alert('Title', 'Message', Time, 'type', playSound)

Now we just have to insert this part to the lib.notify function:

function lib.notify(data)
    local sound = settings.notification_audio and data.sound
    data.sound = nil
    data.position = data.position or settings.notification_position

    -- We comment this part out because it's the part that shows the default notification
    --[[ SendNUIMessage({
        action = 'notify',
        data = data
    }) ]]

    -- And we insert the okokNotify code below it
    exports['okokNotify']:Alert(data.title, data.description, data.duration or 5000, data.type or 'info', false) 
    -- Notice that we have replaced "text" with real data passed to this function
    -- or is added in case you didn't specify data value
    -- "false" at the end means that we won't be playing sound since this is done below by ox

    if not sound then return end

    if sound.bank then lib.requestAudioBank(sound.bank) end

    local soundId = GetSoundId()
    PlaySoundFrontend(soundId, sound.name, sound.set, true)
    ReleaseSoundId(soundId)

    if sound.bank then ReleaseNamedScriptAudioBank(sound.bank) end
end```

I hope instructions were clear and that you also learned something new 🙂
gloomy void
#

you are amazing buddy, thank you so much!

lean dust
#

Thank you so much for this post! Please continue to make these! They're so helpful!

deft linden
#

Thank you for the contribution @merry ginkgo ! - i do got one i did for brutal_notify if you want to post it for the community, i can send it over or post it here if its okay.

merry ginkgo
deft linden
weak harbor
#

what if theres no export can we use a trigger like TriggerEvent("bit-notifications:open", title, message, time, type)

#

?

lime wadi
merry ginkgo
lime wadi
merry ginkgo
#

So the problem is that your notification probably looks like this:
lib.notify({ description = "This is a notification" })
Notice that duration isn't specified.
To fix this issue, we add or 5000 which means, if duration is not provided, make it last 5 seconds by default

merry ginkgo
tight mountain
cold night
#

i want to change my server notifications to bulletin notify

merry ginkgo
#

I think my tutorial is pretty simple and good explained. Have you tried to follow it and make the changes for your notification system?

cold night
#

but i think that how can i put the custom image on it?

#

bc bulletin notify has many different images to put so how can i choose which one?

normal kiln
#

Can this be working?

merry ginkgo
#

Of course!

From my code, replace this:
exports['okokNotify']:Alert(data.title, data.description, data.duration or 5000, data.type or 'info', false)
with this:
exports['v42-notify']:notify(data.description, data.type or 'info', data.duration or 5000)

weak harbor
#

i tried adding TriggerEvent("bit-notifications:open", title, message, time, type) and it didnt work?

merry ginkgo
# weak harbor

Of course, because title, message, time and type don't exist

#

Do this instead:
TriggerEvent("bit-notifications:open", data.title, data.description, data.duration or 5000, data.type or 'info')

I mentioned this in tutorial.

Notice that we have replaced "text" with real data passed to this function
exports['okokNotify']:Alert('Title', 'Message', Time, 'type', playSound)
became
exports['okokNotify']:Alert('Title', 'Message', Time, 'type', playSound)

cold night
merry ginkgo
cold night
merry ginkgo
cold night
#

oh, what you recommend for me?

#

something that is free and modern?

merry ginkgo
#

It depends on the style you are looking for. There are plenty out there. Check Subjects #1388252931899396186 edit

cold night
#

i dont like it

tight mountain
lean dust
tight mountain
#

my design i think

lean dust
#

Oooh that's okay!

#

I was like ox_lib for the winnnnnnnn

tight mountain
#

nah flip_you_john him

tight mountain
cold night
#

s ss sorry n nno...

tight mountain
#

yeah why im saying

cold night
#

@merry ginkgo sorry for the ping

#

but can i ask a fast guestion

#

to work on ox_inventory progresbar

#

or some custom proggresbar

jovial masonBOT
#

@cold night Please move to #🙋〡general-support or #1020532754426904697 for support.

solar coral
#

Thanks ❤️

kind mesa
steel wave
steel wave
#

yeah I also tried wasabi and used his replacement code for ox lib and it did not work properly so I have also gone back to ox_lib but now I need to know what export to use for rtx gym script and I can not find one

merry ginkgo
#

Bros how.. Instructions are clear

merry ginkgo
#

So in your case you could do something like this:
exports['okokNotify']:Alert(data.title or 'No title' , data.description or 'No description' , data.duration or 5000, data.type or 'info', false)

#

So the issue is not my code but the fact that your notificafions are missing stuff. Unsure how okok handles that. @steel wave @kind mesa

steel wave
#

I haven’t asked him yet but they worked fine in QBcore

merry ginkgo
# steel wave I haven’t asked him yet but they worked fine in QBcore

Ah look, they do it like this:
exports['okokNotify']:Alert("", text, length, ttype)

So it means you need this: exports['okokNotify']:Alert(data.title or '' , data.description or 'No description' , data.duration or 5000, data.type or 'info', false)
@kind mesa this will also solve your problem

steel wave
#

Okay thank I’ll try that

unique cedar
#

For c8re notify you can use this:

    if data.type == 'success' then
        exports.core_notify:ShowSuccess(message, true, duration)
    elseif data.type == 'error' then
        exports.core_notify:ShowError(message, true, duration)
    elseif data.type == 'warning' then
        exports.core_notify:ShowWarning(message, true, duration)
    else
        exports.core_notify:ShowInfo(message, true, duration)
    end
lucid junco
#

Thank you!