Skip to main content

BenzyNotifications — Exports

Every export other resources can call, each with a ready-to-paste example. A toast is purely visual: BenzyNotifications renders it on the client and never touches your game logic, so these are safe to call from anywhere.


Notification kinds​

The kind sets the toast's accent color (the left bar + the icon chip) and its icon. These are the built-in styles and their defaults:

KindDefault colorIconUse it for
successGreen #2ecc71✓Something worked — paid, saved, crafted, stored.
errorRed #e74c3c✕Something failed or is blocked — can't afford it, not allowed.
infoBlue #3498dbiNeutral information. The fallback for any unknown kind.
warningAmber #f39c12!A heads-up — low fuel, almost out of time.
requestGold #f1c40f?An incoming ask — a money request, a trade, an invite.
  • 'warn' maps to 'warning'; 'ok' and 'succeeded' map to 'success'.
  • Anything unrecognized falls back to info (blue) rather than erroring.
  • Every color + icon is set in Config.Kinds — change one, or add a whole new kind (e.g. police = { color = '#5b8def', icon = '★' }), and any caller that passes that kind gets your style.

Input forms​

kind, title, message, and duration can be passed two ways, whichever suits your script (plus a bare-message shortcut — exports.BenzyNotifications:Notify('You were paid $50') shows an info toast with just that text):

Positional — kind, then title, message, duration:

exports.BenzyNotifications:Notify('success', 'Bank', 'Payment received', 5000)

An options table — field names from the common notify APIs are all accepted, so a script written against another system often works unchanged:

MeaningAccepted keys
kindtype, kind, status
titletitle, header, caption
messagemessage, description, text, body, detail
duration (ms)duration, length, time, timeout
exports.BenzyNotifications:Notify({ type = 'success', title = 'Bank', description = 'Payment received', duration = 5000 })

duration is always optional — omit it to use Config.Duration. title is optional too (pass '' or leave it out for a message-only toast).


Client exports​

Call these from a client script to show a toast on that player's screen.

Notify(kind, title, message, duration) — show a toast (positional or options table, as above).

exports.BenzyNotifications:Notify('info', 'Door', 'Hold E to enter the building.')

ShowNotification(...) — an alias of Notify, for scripts that expect that name.

exports.BenzyNotifications:ShowNotification('error', 'Locked', 'You need a key.')

Per-kind shorthands — Success, Error, Info, Warning, Request. Each takes (title, message, duration) (or an options table) and forces its kind, so you never pass one:

exports.BenzyNotifications:Success('Garage', 'Your car has been stored.')
exports.BenzyNotifications:Error('Garage', 'That parking spot is taken.')
exports.BenzyNotifications:Warning('Fuel', 'Your tank is running low.', 8000)
exports.BenzyNotifications:Info('Door', 'Press E to open the door.')
exports.BenzyNotifications:Request('Trade', 'Alex wants to trade with you.')

Clear() — slide out every toast currently on screen (e.g. on death or logout).

exports.BenzyNotifications:Clear()

Easy to adopt. Notify(kind, title, message, duration) is the common notify signature, and the options-table form plus the per-kind shorthands cover the rest — so most resources can switch to it with a one-line change.


Server exports​

Call these from a server script to push a toast to a player (or everyone). The client renders it.

Notify(source, kind, title, message, duration) — push a toast to one player by server id (positional or, after source, an options table).

RegisterNetEvent('myjob:paid', function()
exports.BenzyNotifications:Notify(source, 'success', 'Paycheck', 'The city paid you $1,500.')
end)

ShowNotification(source, ...) — an alias of the server Notify.

NotifyAll(kind, title, message, duration) / Broadcast(...) — push a toast to every connected player.

exports.BenzyNotifications:NotifyAll('info', 'Server', 'A restart is scheduled in 5 minutes.', 10000)

Per-kind shorthands — Success, Error, Info, Warning, Request, each (source, title, message, duration):

exports.BenzyNotifications:Success(source, 'Paycheck', 'The city paid you $1,500.')
exports.BenzyNotifications:Error(source, 'Fine', 'You could not afford the fine.')

Per-kind broadcasts — SuccessAll, ErrorAll, InfoAll, WarningAll, RequestAll, each (title, message, duration) to everyone:

exports.BenzyNotifications:WarningAll('Weather', 'A storm is rolling in.')

Clear(source) / ClearAll() — dismiss a player's toasts (or everyone's).

exports.BenzyNotifications:Clear(source)

source first on the server. The single-target server exports take the player's server id as their first argument; the *All variants need no target. Notify returns true for a valid server id (and false otherwise).


Worked example: a job payout​

A server resource that pays a player and shows them a toast, with a fallback for when BenzyNotifications isn't running.

local function notify(src, kind, title, body, duration)
if GetResourceState('BenzyNotifications') == 'started' then
exports.BenzyNotifications:Notify(src, kind, title, body, duration)
else
TriggerClientEvent('chat:addMessage', src, { args = { title, body } })
end
end

RegisterNetEvent('mining:sellOre', function()
local src = source
local paid = giveOrePayout(src) -- your own logic
notify(src, 'success', 'Ore sold', ('You earned $%d.'):format(paid))
end)

See INTEGRATIONS.md for routing another resource's notifications through it, and EVENTS.md for the event-based alternatives to these exports.