Notifications
Toasts for short messages and text prompts for contextual hints such as [E] Search.
Toasts
lua
-- client
tm.notify({ type = 'success', message = tm.locale.t('garage.vehicleStored') })
-- a plain string is the message
tm.notify(tm.locale.t('garage.vehicleStored'))
-- server: first argument is the player
tm.notify(source, { type = 'error', message = tm.locale.t('garage.noSpace') })
tm.notify(-1, tm.locale.t('server.restartSoon')) -- everyone
tm.notify(0, 'Printed in the console instead') -- the console| Function | Notes |
|---|---|
tm.notify(data) (client) | Shows a toast and returns its id, or nil when there was nothing to show. data is a table or just the message string. |
tm.notify(source, data) (server) | source is a player id, -1 for everyone or 0 for the console, which logs the message instead. |
tm.dismissNotification(id) | Removes one toast by the id notify returned (or the id you passed). Client. |
tm.clearAllNotifications() | Removes every toast. Client. |
Options
| Field | Meaning |
|---|---|
message | Main text. title and description also work as the main text. At least one of the three is required. |
caption | Second, smaller line. description becomes the caption when message or title is also set. |
type | 'success', 'error', 'warning', 'inform', 'ongoing' (spinner), or any color name. |
duration | Milliseconds on screen, default 5000. 0 keeps it until dismissed. Alias timeout. |
position | One of the nine zones. Default bottom-center. |
icon, iconColor | See icons. When no icon is given the type picks one (check, cross, warning, info), and any other type gets a bell. |
avatar | Image URL shown in place of the icon. |
color | Accent color. |
progress | true shows a countdown bar. |
spinner | true shows a spinner. type = 'ongoing' does too. |
html | true renders the message as HTML. Only use it with text you control. |
multiLine | Keeps \n line breaks in the message. |
id | Same id again updates that toast in place instead of adding another. |
At most eight toasts are on screen. The oldest is removed when a ninth arrives.
A toast that tracks a task
A toast of type ongoing has no timeout until you dismiss it. Re-using its id updates it in place:
lua
local id = tm.notify({ id = 'impound', type = 'ongoing', message = tm.locale.t('garage.impounding') })
-- later
tm.notify({ id = id, type = 'success', message = tm.locale.t('garage.impounded') })
-- or just remove it
tm.dismissNotification(id)Text prompts
A small persistent hint, usually tied to a place or an object. Keys follow the [KEY] Action form, one control per line:
lua
tm.showTextUI(tm.locale.t('blackjack.controls'), { html = true }) -- '[E] Bet<br>[G] Leave' (en.json)
tm.hideTextUI()Never write "Press E to ...". Bracketed keys such as [E], [F5], [Ctrl+E] or [Esc/Backspace] are drawn as keycaps. Put each control on its own line: either <br> in the string with html = true, or a \n in the string with multiLine = true.
| Function | Notes |
|---|---|
tm.showTextUI(text, opts?) | Shows a prompt, or replaces the one with the same id. Calling it again with identical content does nothing, so it is cheap to call from a zone callback. |
tm.updateTextUI(text, opts?) | Changes the text and any options of a prompt that is already visible. Options you leave out keep their value. Does nothing when no prompt with that id is showing. |
tm.hideTextUI(id?) | Hides the prompt with that id, or the default prompt when no id is given. |
tm.isTextUIOpen(id?) | Returns open, current. Without an id it checks the default prompt first, then any other. |
Options
| Field | Meaning |
|---|---|
id | Which prompt this is. Default 'default'. Several ids can be on screen at once, each in its own slot. |
position | One of the nine zones. Default bottom-center. |
icon, iconColor, avatar | As for toasts. A prompt shows no icon unless you give one. |
color, type | Accent color or tone ('info', 'warning', 'negative' ...). |
html, multiLine | As for toasts. |
Showing a prompt from a zone
Do not poll. Show on enter and hide on leave:
lua
local zone = lib.zones.sphere({
coords = vec3(441.2, -981.9, 30.7), radius = 1.5,
onEnter = function() tm.showTextUI(tm.locale.t('mdt.open'), { id = 'mdt' }) end,
onExit = function() tm.hideTextUI('mdt') end,
})A prompt is removed automatically when the resource that showed it stops.