Notify (ed_notify)

A simple & elegant notification system.

Installation

Download the Script

Download the script using keymaster.

Add it to your resources

Open the downloaded zip, copy ed_notify & put it inside your resources.

Start the Script

Terminal
refresh
start ed_notify

Finally, if everything is right, you can put it inside your server.cfg as follows:

server.cfg
ensure ed_notify

ESX Integration

If you want to change the default notification system to ed_notify, you'll need to replace ESX.ShowNotification function as follows:

es_extended/client/functions.lua
-- ...
function ESX.ShowNotification(message, notifyType, length)
    if GetResourceState("ed_notify") ~= "missing" then
        exports.ed_notify:push({
          title = message,
          type = notifyType,
          duration = length
        })
        return
    end

    print("[^1ERROR^7] ^5ed_notify^7 is Missing!")
end
-- ...

QBCore Integration

If you want to change the default notification system to ed_notify, you'll need to replace QBCore.Functions.Notify function as follows:

qb-core/client/functions.lua
-- ...
function QBCore.Functions.Notify(text, texttype, length)
    if GetResourceState("ed_notify") ~= "missing" then
        exports.ed_notify:push({
          title = text.text or text,
          type = texttype,
          description = text.caption,
          duration = length
        })
        return
    end

    print("[^1ERROR^7] ^5ed_notify^7 is Missing!")
end
-- ...

Configuration

config.lua
translations.lua
-- https://edeverce.com/scripts/notify

Config = {
   ---@type "default"|"blue"|"green"|"red"|"rose"|"orange"|"violet"|"yellow"
   -- UI theme. See https://edeverce.com/guides/theming for more advanced configuration.
   theme = "default",

   ---@type string
   -- Command to open notify settings.
   settingsCommand = "notifysettings",

   ---@type number
   -- Default notification duration. Can be overwritten by setting duration when pushing a notification.
   defaultDuration = 5000,

   ---@type "top-left"|"top-center"|"top-right"|"bottom-left"|"bottom-center"|"bottom-right"
   -- Default position. Can be overwritten by user's preferences.
   defaultPosition = "top-right",

   ---@type number
   -- Default offset (px). Can be overwritten by user's preferences.
   defaultOffset = 25,

   -- See https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/keyboard/ for keys.

   ---@type string?
   -- Default focus key. Can be set to nil if you don't want to use this feature. Key can be changed by players via key bindings.
   defaultFocusKey = "K",

   ---@type string?
   -- Default expand key. Can be set to nil if you don't want to use this feature. Key can be changed by players via key bindings.
   defaultExpandKey = "J",

   ---@type table<string, { icon?: string, color?: string }>
   -- Icon is optional, must be a font awesome icon name. Color is optional, must be a HEX value.
   -- See https://fontawesome.com/icons for icon names.
   customTypes = {
      example = {
         icon = "fa fa-message",
         color = "#6644ff",
      },
   },
}

API

Push

Pushing a notification:

Client
Server
-- Using exports:
exports.ed_notify:push(options)

-- Using event:
TriggerEvent("ed_notify:push", options)
title required string
Title of the notification.
id?string
Unique id for notification to update later on.
type?'info' | 'success' | 'error' | 'warning' | 'loading' | customType
Type of the notification.
description?string
Description of the notification.
duration?number
Duration of the notification. If not passed, Config.defaultDuration will be used.

Update

Updating a notification:

Client
Server
-- Using exports:
exports.ed_notify:update(options)

-- Using event:
TriggerEvent("ed_notify:update", options)
title required string
Title of the notification.
id required string
ID of the notification to update.
type?'info' | 'success' | 'error' | 'warning' | 'loading' | customType
Type of the notification.
description?string
Description of the notification.
duration?number
Duration of the notification.

Dismiss

Dismissing a notification:

Client
Server
-- Using exports:
exports.ed_notify:dismiss(id)

-- Using event:
TriggerEvent("ed_notify:dismiss", id)
id?string
ID of the notification to dismiss. If not passed, all notifications will be dismissed.

Usage

Push

exports.ed_notify:push({
  title = "Notification Title",
  id = "unique-id",
  type = "success",
  description = "Notification Description",
  duration = 5000
})

Update

exports.ed_notify:update({
  title = "Updated Notification Title",
  id = "unique-id",
  type = "error",
  description = "Updated Notification Description",
  duration = 2500
})

Dismiss

exports.ed_notify:dismiss("unique-id")