Skip to content

Notifications ​

Toasts for short messages and text prompts for contextual hints such as [E] Search.

Toasts ​

Toasts (use the Toasts menu for more)Open full size
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
FunctionNotes
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 ​

FieldMeaning
messageMain text. title and description also work as the main text. At least one of the three is required.
captionSecond, smaller line. description becomes the caption when message or title is also set.
type'success', 'error', 'warning', 'inform', 'ongoing' (spinner), or any color name.
durationMilliseconds on screen, default 5000. 0 keeps it until dismissed. Alias timeout.
positionOne of the nine zones. Default bottom-center.
icon, iconColorSee icons. When no icon is given the type picks one (check, cross, warning, info), and any other type gets a bell.
avatarImage URL shown in place of the icon.
colorAccent color.
progresstrue shows a countdown bar.
spinnertrue shows a spinner. type = 'ongoing' does too.
htmltrue renders the message as HTML. Only use it with text you control.
multiLineKeeps \n line breaks in the message.
idSame 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 ​

Text prompts (use the TextUI menu for more)Open full size

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.

FunctionNotes
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 ​

FieldMeaning
idWhich prompt this is. Default 'default'. Several ids can be on screen at once, each in its own slot.
positionOne of the nine zones. Default bottom-center.
icon, iconColor, avatarAs for toasts. A prompt shows no icon unless you give one.
color, typeAccent color or tone ('info', 'warning', 'negative' ...).
html, multiLineAs 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.