147 online 3 members  + Join RP Base  +
FreeScript

tLib

by tommy141x  ·  version 2026.11.06  ·  updated 3 days ago

No reviews yet

Downloads
0
Reviews
0
Size
2.6 MB
Code check
Checked
Licence
MIT
Released
Nov 2026

A shared utility library for Helix & FiveM resources

tLib
tLib
A shared utility library for FiveM resources: one NUI menu, dialog and toast system with
themes, 40 Lua import modules (access, permission, config, KVP, settings, platform and the
rest), and TypeScript/NUI utilities for resource frontends.

FiveM is the only supported runtime. Everything goes through an internal Platform adapter.

SystemsMenu System
One NUI menu, shared by every resource on the server. tLib owns the screen, the
keyboard and the permission check; a consumer declares pages and handles rows.

The API is declarative and split across the two sides. Pages register on the server,
which answers every open with that player's own ACE-filtered tree, so there is no path to a
row the player is not entitled to. The client registers behaviour: handlers, presenters
that fill rows in as they are shown, and hooks for entering or leaving a page.

Menu IDs are namespaced: every page a resource registers must be owner:name. Every
export below takes an optional trailing declaredOwner, used only where the platform
cannot identify the caller; pass it as its own argument, never as the result of a call
in the last argument slot (f(json.decode(x)) expands to two values and the second
lands in declaredOwner).

Start here: Developing modular menu resources covers a complete standalone consumer, registration/restart lifecycle, stable host slots, ownership and placement. tlib.lifecycle (shared import) and tlib.menuhost (server import) both expose API version = 1; they run in the caller's VM and contain no consumer-specific policy.

Server — declaring the tree
  • DefineMenuNamespace(spec) — Required first. { ace, catalog?, order?, capabilities?, theme? }. ace gates the whole namespace.
  • RegisterMenuDomains(domains) — Rate/cooldown domains actions may be assigned to.
  • RegisterMenu(menu, definition) — One page plus its authority: definition is { ace, actions = { [itemId] = { ace, run?, clientAction?, cooldown?, fixedValue?, domain? } }, theme?, rootVisible? }. rootVisible = false omits the automatic shared-root link without changing direct access or permissions.
  • UnregisterMenu(menuId)
  • RegisterMenuAuthority(spec) / UnregisterMenuAuthority() — Answer for rows this resource does not own.
  • OnMenuSnapshot(hook) — Adjust a player's tree as it is built for them.
  • RefreshMenus() — Re-push every open menu.

Server — changing what is already registered
  • PatchMenuItem(menuId, itemId, changes) / PatchMenuAction(itemId, changes) — The second finds the page itself.
  • SetMenuLinks(menuId, links) — Replace dynamic submenu rows on a page you own; links is an array of ordinary kind = 'submenu' rows, or {} to remove them. Base rows/actions are unchanged. Targets remain permission-filtered and disappear when unavailable. A catalogued page with links travels as a full descriptor (100 rows total, the existing descriptor schema limit); removing all links restores compact delivery.
  • SetMenuItemVisible(itemId, visible)
  • SetPlayerMenuOptions(source, itemId, options) — One player's own choices for a selector.
  • SetMenuNamespaceTheme(theme) / SetMenuTheme(menuId, theme) — nil clears.

A menu theme — { accent = '#rrggbb', banner = { dictionary, texture } | { url }, theme = '', skin = 'default' | 'vmenu' }. Every field is optional; at least one must be set. The same shape is accepted at all three layers, resolved most-specific-first and flattened field by field: the page's own theme, then the theme of the resource that created it, then the interface default. A resource that sets only an accent therefore keeps the interface's banner.

skin selects the presentation rather than a colour, so it is a closed set rather than a free string:

Skin

default, The shared look. The same controls, checkboxes, sliders and face as tLib's dialogs and toasts.
vmenu, The legacy vMenu-styled presentation, kept switchable for a test or a side-by-side comparison.

theme names a theme registered with AddTheme, which is where full CSS-variable control lives. To make a menu, its toasts and its dialogs match, register one theme id setting the nui-* variables (see the Theme System section) and pass that id as the menu's theme, as ShowDialog's theme option, and as ShowToast's theme argument.

Client — behaviour
  • RegisterMenuActions(handlers) — { [name] = function(value, context) end }, registered as one table: all of it installs or none of it does.
  • RegisterMenuCatalogProvider(provider) — Build this resource's catalog once, off a function that may yield.
  • RegisterMenuHooks(spec) — { snapshot, enter, leave, page, selection, close }. enter may refuse a navigation.
  • RegisterMenuPresenter(spec) / UnregisterMenuPresenter() — Fill rows in as a page is presented.
  • RegisterMenuStrings(dictionaries) — Translations for this resource's rows.
  • ConfigureMenuInterface(spec) — The root page. One screen, so the last caller wins.
  • SetMenuEffect(name, enabled, definition) — A handler that keeps running after the row was activated, re-checked against the player's grants while it does.
  • PublishMenuItem(name, changes), SetMenuItemState(name, value), GetMenuItemState(name), ExecuteMenuAction(name, value, context)
  • OnMenuActionsCleanup(fn) / OnMenuActionsPersist(fn)

Client — the screen (unscoped: it belongs to the player, not to a resource)
  • OpenMenu(menuId?) — Re-checks the page against a fresh permission-filtered snapshot.
  • CloseMenu() — The same teardown the close key runs. Does not toggle: closing a menu that is not open answers false, 'Menu is not open', so a caller that meant to close one is never the reason a fresh one appeared. Needed before OpenMenu, which refuses while a menu is already up.
  • IsMenuVisible(), GetMenuStackIds(), NavigateMenu(menuId), InvalidateMenuContext()
  • `SetMe

…