API
Every client export of More Menus, the menu object, the callbacks and the data each menu type takes.
More Menus has no server side and no events. Everything is a client export: call exports.more_menus:Open(...) from a client script. The only command is /testmenu, which exists while dev_mode is on.
A menu is identified by three values: its type (default, dialog or list), a namespace (normally the name of your resource) and a name. Opening a menu with the same three values replaces the open one. Several default menus can be open at once and stack as submenus; dialogs and lists show the newest one of their type.
Exports
All exports run on the client and are shaped like ESX.UI.Menu, so an ESX script moves over by replacing ESX.UI.Menu. with exports.more_menus:. When a resource stops, its menus are removed without running their callbacks.
Open(type, namespace, name, data, submit, cancel, change, close)Menu or nilrequiredOpens a menu and returns it. type is default, dialog or list; namespace and name are strings; data is a table (see the data sections below). submit, cancel, change and close are optional callbacks. Opening a menu with the same type, namespace and name replaces the open one. Returns nil and prints an error to the console when an argument is wrong.
Close(type, namespace, name, cancel)nothingrequiredCloses one menu. Without cancel its close callback runs; with cancel set to true its cancel callback runs instead.
CloseAll(cancel)nothingdefault cancel: falseCloses every open menu in the same way, with the close callbacks or, with cancel set to true, the cancel callbacks.
GetOpened(type, namespace, name)Menu or nildefault —Returns the open menu with that type, namespace and name, or nil.
IsOpen(type, namespace, name)Menu or nildefault —Same result as GetOpened. Compare it against nil: it returns the menu, not true.
GetOpenedMenus()list of menusdefault —Every open menu, in the order they were opened.
SetDialogError(namespace, name, text)nothingdefault text: nilShows an error line under the field of the open dialog with that namespace and name. nil or an empty text clears it. The dialog cannot be confirmed while an error line is shown.
The menu object
Open returns the menu, and every callback receives it as its last argument. It is a copy (FiveM copies export values), so change a menu through its methods and never by writing to its data field. The setters change the menu and refresh() shows the change. The menu has the fields type, namespace, name, resourceName (the resource that opened it) and data (your table).
close()nothingdefault —Closes this menu: it leaves the screen and its close callback runs. The cancel callback does not run.
refresh()nothingdefault —Sends the menu to the screen again so that changes made with the other methods become visible.
update(query, newData)nothingdefault —Default menus only. Every element that has all the fields of query receives the fields of newData. Call refresh() afterwards.
setElement(i, key, value)nothingdefault —Default menus only. Sets one field of the element at position i (the first element is 1), for example its label. Call refresh() afterwards.
setElements(elements)nothingdefault —Default menus only. Replaces all elements with a new list of tables. Call refresh() afterwards.
setTitle(title)nothingdefault —Sets the title in the menu data. Call refresh() afterwards.
removeElement(query)nothingdefault —Default menus only. Removes every element that has at least one field equal to a field of query (update needs all fields to match, removeElement only one). Call refresh() afterwards.
Callbacks
submit, cancel, change and close are optional functions you pass to Open. submit(data, menu) runs when the player confirms: Enter or a click on a row, the Confirm button of a dialog, or a button inside a list cell. cancel(data, menu) runs when the player goes back: Backspace in a default menu, the Cancel button of a dialog, or the close button of a list. Neither closes the menu by itself, so close it from the callback with menu.close() or Close. change(data, menu) runs whenever the selection or a value moves in a default menu, and on every keystroke in a dialog. close() receives no arguments and runs when the menu is closed with close() or with Close and CloseAll without cancel.
What the callbacks receive
Default menu: change and submit receive a table with _namespace, _name, current (the selected element with its current value) and elements (all elements). cancel receives only _namespace and _name. Dialog: every callback receives the data table you passed, with _namespace and _name added; data.value holds the typed text, and in submit the checked value (see the dialog section). List: submit receives _namespace, _name, data (the data of the clicked row, with currentRow added when it is a table) and value (the value of the clicked button; a value that is a plain number arrives as a number); cancel receives _namespace and _name.
Default menu data
These fields go into the data table of Open with the type default.
titlestringdefault MenuTitle of the menu. HTML tags are removed from every text. When it is missing, the menu_title text is used.
subtitlestringdefault —Line under the title.
iconstringdefault —Icon name from the icon set of the menu. An unknown name falls back to the standard icon.
alignstringdefault top-leftScreen position: top-left, top, top-right, left, center, right, bottom-left, bottom or bottom-right. With stacked submenus the first menu decides.
infolistdefault —The info bar above the rows (see Info bar).
elementslist of tablesdefault —The rows (see Elements). Without elements the menu_empty text is shown.
Elements
Every element is a table. The fields below are drawn by the menu. Any other field you add, such as value, name or kind, stays on the element and comes back in the callbacks, so you can use it to recognize the row.
labelstringdefault —Text of the row. HTML tags are removed.
typestringdefault defaultdefault or none: a button. slider: a value that steps by 1, either through options or between min and max. range: a bar that moves in steps of step. checkbox and toggle: true or false. submenu: a row drawn as a submenu entry; it only looks like one, you open the next menu yourself in the submit callback.
valuenumber or booleandefault —Current value: a number for slider and range, true or false for checkbox and toggle. A value of the wrong type is ignored. In callbacks it holds the value the player set.
optionslist of stringsdefault —Slider only. The labels to choose from; value is the position in the list and starts at 0.
minnumberdefault 0Slider without options and range: lowest value.
maxnumberdefault range 100Slider without options and range: highest value. A slider without options and without max has no upper limit. With options the last option is the limit.
stepnumberdefault 1Range only. Size of one step when the player presses left or right.
unitstringdefault —Range only. Text after the value, for example %.
iconstringdefault —Icon name shown in the row.
rightLabelstringdefault —Text on the right side of the row.
selectedbooleandefault —true selects the row when the menu opens. When several rows are marked the last one counts. The selected row is remembered while the menu is open.
Info bar
The info list shows chips above the rows. An entry is one of the shorthands cash, bank or black, which show the money of the player and update when it changes (black is the black money reported by more_lib), or a table with the fields below.
labelstringdefault —Text of the chip.
valuestring or numberdefault —Value shown.
iconstringdefault —Icon name.
tonestringdefault redColour: red, crimson, orange, coral, yellow, green, teal, blue, violet or pink. Any other value uses the standard colour.
moneybooleandefault falseShows value in the money format of the money text (default: dollar sign and the amount).
widebooleandefault falseThe chip uses its own full-width row.
Dialog data
A dialog is a small window with one input field and the buttons Confirm and Cancel. Only the newest dialog is shown. On Confirm the typed text is checked first. A text that reads as a number is handed to your callback as a number rounded to a whole number (2.5 becomes 3), whatever the inputType. A number below min (below 1 when min is not set) or above max is refused: the dialog stays open, and in a number dialog the player sees the error line. Because of this, a text dialog refuses input such as 0 or -5 as well; this is how the ESX dialog behaves. Text that is not a number is passed on as typed.
titlestringdefault InputTitle of the dialog.
subtitlestringdefault —Line under the title.
iconstringdefault —Icon name.
placeholderstringdefault Type hereText shown in the empty field. A number dialog shows 0 by default.
valuestring or numberdefault —Text the field starts with.
inputTypestringdefault texttext or number. A number dialog shows an error line while the input is not a number or is out of range.
minnumberdefault 1Number dialogs: lowest accepted number.
maxnumberdefault —Number dialogs: highest accepted number.
minErrorstringdefault —Own error line for a number below min. Replaces the dialog_min text.
maxErrorstringdefault —Own error line for a number above max. Replaces the dialog_max text.
maxLengthnumberdefault —Most characters the field accepts.
errorstringdefault —Error line under the field. It is usually set with the SetDialogError export; Confirm is blocked while it is shown.
List data
A list is a table with a title, a header row, rows, an optional search bar and an optional summary. Only the newest list is shown. The header of the list counts the rows shown.
titlestringdefault ListTitle of the list. The first word is highlighted.
subtitlestringdefault —Line under the title.
iconstringdefault —Icon name.
headlistdefault —The column headers. Each is a string or a table with label, align (left, center or right), type (text or amount) and width (a number, the relative width of the column).
rowslist of tablesdefault —Every row is a table with cols (the texts of the cells, in the order of the columns) and data (anything you want back when the row is used).
searchbooleandefault automatictrue shows the search bar, false hides it. Without a value it appears from 9 rows on.
summarylistdefault —Entries under the table. Each is a table with label, value, icon and money (true formats the value as money).
A cell can contain buttons written as {{Label|value}}. The button shows a small icon with the label as its tooltip, and a click submits the row with that value: the value pay shows a card icon, every other value an arrow. A cell can hold several buttons and normal text next to them. Cell contents are converted to plain text and HTML tags are removed. Strip the characters {{ and }} from any text a player wrote before you put it into a cell, otherwise that player can plant a button that submits the row with a value they chose (the ESX list menu behaves the same).
Security
Every callback runs on the player's own client, as with the ESX menus, so values that come from a menu can be changed by a cheater. A script that pays money, gives items or changes a row from menu values must check them again on its own server.
Test menu
With dev_mode on, the command /testmenu opens a menu that shows every element type, the three alignments through a slider, the menu methods, a text dialog, a number dialog, a list and the exports GetOpened, GetOpenedMenus, IsOpen and CloseAll. Each callback prints its data to the F8 console. backend/client/testcode.lua stays editable and is a worked example of every export.
Last updated