SNIPPETS

For convenience, we will provide examples below demonstrating how to replace a framework's code to use rat-notify by default.

ESX (FiveM)

File: es_extended/client/functions.lua Function: ESX.ShowNotification

function ESX.ShowNotification(message, type, length)
    if (GetResourceState("rat-notify") == "missing") then
        Citizen.Trace("^8ERROR ^7rat-notify is not present or started.")
        return
    end
    local title = "Notify"
    local style = "default"
    if (type == "info" or type == "success" or type == "error") then
        title = type:gsub("^%1", string.upper)
        style = type
    end
    exports["rat-notify"]:Add({
        title = title,
        text = message,
        style = style,
        duration = length or 5000
    })
end

QBCore (FiveM)

File: qb-core/client.functions.lua Function: QBCore.Functions.Notify

function QBCore.Functions.Notify(text, texttype, length, icon)
    if (GetResourceState("rat-notify") == "missing") then
        Citizen.Trace("^8ERROR ^7rat-notify is not present or started.")
        return
    end
    if (icon) then icon = (icon):gsub("fas", "fa-solid") end

    local t = "info"
    if (texttype) then t = texttype end

    -- Capitalize the first letter of `texttype`
    local title = t:gsub("^%l", string.upper)

    exports["rat-notify"]:Add({
        title = title,
        text = text,
        style = t,
        duration = length or 5000
    })
end

Ox (FiveM / RedM)

File: ox_lib/source/interface/notify.lua Function: lib.notify

function lib.notify(data)
    local position = data.position or settings.notification_position

    if ( GetResourceState('rat-notity') == "missing" ) then
        Citizen.Trace("^8ERROR ^7rat-notify is not present or started.")
        return
    end

    exports["rat-notify"]:Add({
        id = data.id,
        title = data.title,
        text = data.description,
        duration = data.duration,
        style = data.type,
        icon = data.icon,
        pos = position
    })
end

Last updated