Guide

How to use More Menus from your own scripts: opening menus, moving over from ESX and the typical patterns.

This guide walks through the typical uses of More Menus from a client script. Every export and every data field is listed on the API page. A complete working example of every export is backend/client/testcode.lua, which you can open with /testmenu while dev_mode is on.

Opening a default menu

Call exports.more_menus:Open with the type default, a namespace (usually your resource name), a name for the menu, a data table and the callbacks submit, cancel, change and close. Put title, subtitle and elements into data and give every element a label and a value of your own, so you can recognize it in submit, where data.current is the chosen element. Nothing closes automatically: call menu.close() in your cancel callback, otherwise Backspace does nothing.

Moving a script over from ESX

Replace ESX.UI.Menu. with exports.more_menus: in your script. Open, Close, CloseAll, GetOpened and GetOpenedMenus keep their arguments (type, namespace, name, data, submit, cancel, change, close), the returned menu has the same methods and the callbacks receive the same data. IsOpen and SetDialogError are new. More Menus does not register itself in ESX.UI.Menu, so esx_menu_default, esx_menu_dialog and esx_menu_list can keep running next to it. Differences to check: HTML tags in labels are removed, a menu you received must be changed through its methods followed by refresh(), and a text dialog also treats text that reads as a number as a number. Test every menu once after the change.

Submenus

Give a row the type submenu and open the next default menu, with another name, in the submit callback. The menus stack next to each other: the newest one receives the keys, Backspace runs its cancel callback, and once you close it the menu below is active again. The align field of the first menu decides where the whole stack sits.

Sliders, ranges, checkboxes and toggles

A slider takes options (value is the position, starting at 0) or min and max. A range takes min, max, step and unit. Checkbox and toggle hold true or false. When the player moves one of them, or flips a checkbox or toggle with Enter, only the change callback runs, with the new value in data.current. Enter on any other row, a slider and a range included, runs submit. When the player confirms, read the values of all rows from data.elements, where every element carries its current value.

Showing the player's money

Put cash, bank or black into the info list of a default menu to show the current money of the player in the bar above the rows. The bar updates when the money changes. For your own values add a table with label, value, icon, tone, money and wide.

Asking for text or a number

Open the type dialog with a title, a placeholder and, for numbers, inputType number with min and max. In submit, data.value holds the checked value: a number rounded to a whole number, or the text. Close the dialog in submit and in cancel. To reject text while the player types, set an error line from the change callback with exports.more_menus:SetDialogError and clear it with nil. Remember that 0 and negative numbers are refused unless min allows them.

Showing a table

Open the type list with head (the column headers), rows and, if you want, summary. Each row is a table with cols (one text per column) and data (anything you want back). Write a button into a cell as {{Label|value}}; clicking it calls submit with the row data and that value. From 9 rows on a search bar appears by itself. Close the list in the cancel callback.

Updating an open menu

Change the menu you received with setTitle, setElement, setElements, update or removeElement and call refresh() so the change appears. You can also call Open again with the same type, namespace and name: it replaces the open menu without running its close callback and keeps the selected row, unless an element has selected set to true.

Reading and closing menus

GetOpened and IsOpen return the open menu or nil, GetOpenedMenus lists all of them. Close closes one menu and CloseAll every menu: the close callbacks run, or the cancel callbacks when you pass true. Menus also close, with their close callbacks, when the player dies, and the menus of a resource that stops are removed without callbacks.

Keys and mouse

Default menus are controlled with the arrow keys (a held key repeats), Enter to choose and Backspace to go back. Left Alt turns on mouse mode, where rows can be clicked and sliders dragged; Alt or a right click leaves it. Dialogs and lists use the keyboard and the mouse of the page. Players can rebind every key in the FiveM key settings under Menu: up and the following names.

Checking values on the server

Callbacks run on the player's own client. If a menu choice pays money, gives an item or changes data, send only the choice to your server and check everything again there. Never trust the price, amount or row that comes from a menu.

Texts and language

The texts of More Menus itself (buttons, placeholders, error lines, key names) are in backend/locale/en.lua and de.lua, and MS.Locale in cl_config.lua picks the language. Titles, labels and error lines of your own menus come from your script, so translate them there.

Last updated