Integration
Exports, events, and integration guide for legacy-notify
Client Export: SendNotify#
Send a notification from any client-side script.
exports['legacy-notify']:SendNotify(data)
Parameters#
The data table accepts the following fields:
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Notification message text |
type | string | No | Notification type key (default: 'primary'). Must match a key in Config.Types |
title | string | No | Notification title text. If omitted, no title is displayed |
duration | number | No | Duration in milliseconds (default: Config.DefaultDuration / 5000) |
icon | string | No | FontAwesome 6 icon class override (e.g. 'fa-solid fa-bell'). Overrides the type's default icon |
position | string | No | Position override for this notification (default: Config.Position). See position options in Configuration |
Examples#
-- Simple notification
exports['legacy-notify']:SendNotify({
message = 'You picked up a lockpick',
})
-- Success notification with title
exports['legacy-notify']:SendNotify({
type = 'success',
title = 'Purchase Complete',
message = 'You bought a sandwich for $15',
duration = 4000,
})
-- Error notification with custom icon
exports['legacy-notify']:SendNotify({
type = 'error',
title = 'Access Denied',
message = 'You do not have the required key',
icon = 'fa-solid fa-lock',
})
-- Warning notification at a specific position
exports['legacy-notify']:SendNotify({
type = 'warning',
title = 'Low Fuel',
message = 'Your vehicle is running low on fuel',
position = 'bottom-center',
duration = 8000,
})
Server Export: SendNotify#
Send a notification to a specific player from any server-side script.
exports['legacy-notify']:SendNotify(source, data)
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
source | number | Yes | Player server ID to send the notification to |
data | table | Yes | Notification data table (same fields as the client export) |
Example#
-- Server-side: notify a player
exports['legacy-notify']:SendNotify(source, {
type = 'success',
title = 'Paycheck',
message = 'You received your weekly paycheck of $2,500',
duration = 6000,
})
-- Server-side: notify all players
for _, playerId in ipairs(GetPlayers()) do
exports['legacy-notify']:SendNotify(tonumber(playerId), {
type = 'info',
title = 'Server Announcement',
message = 'Server restart in 15 minutes',
})
end
Client Event: legacy-notify:send#
You can also trigger a notification via a client event:
-- From client-side
TriggerEvent('legacy-notify:send', {
type = 'info',
title = 'Notification',
message = 'Event-based notification',
})
Server Event: legacy-notify:sendFromServer#
Trigger a notification to the calling player from server-side via event:
-- From server-side (sends to the triggering player)
TriggerClientEvent('legacy-notify:send', source, {
type = 'success',
message = 'Action completed',
})
Replacing Existing Notification Systems#
To replace another notification system (e.g. ox_lib notifications) with legacy-notify, you can wrap the export:
-- Replace ox_lib notifications with legacy-notify
-- Add this to a client script that loads early
local typeMap = {
inform = 'info',
success = 'success',
error = 'error',
warning = 'warning',
}
local originalNotify = lib.notify
lib.notify = function(data)
exports['legacy-notify']:SendNotify({
type = typeMap[data.type] or 'primary',
title = data.title,
message = data.description,
duration = data.duration,
icon = data.icon,
position = data.position,
})
end