esx_menu_default
A list type menu used by es_extended
Only available on clientside
ESX.UI.Menu.Open
Open a menu that can be used with arrow keys
ESX.UI.Menu.Open(type, namespace, name, data, onSelect, cancel )Arguments
- type:
string- the menu to open
defaultin this case
- the menu to open
- namespace:
string- The namespace of the menu, usually
GetResourceName()is used
- The namespace of the menu, usually
- name:
string- The name of the menu
- data:
table- The table with the elements to show in the menu
- onSelect:
function- Function that gets ran when an element is selected.
- cancel:
function- Function that gets ran when the menu gets closed
Data table
- title:
titleof the menu - align:
position(top-left | top-right | bottom-left | bottom-right | center) - elements:
selectableelements table - locales?:
localestable
Elements
- label:
string- label name to show, supports HTML
- name:
string- name of the element
- value:
number|string- value of the element/slider
- type:
string- Type of the element
- min:
number- minimum slider value
- max:
number- Maximum slider value
Locales
- backspace:
string- Backspace button label for the menu
- select:
string- Select button label for the menu
onSelect
Function triggered when an element is selected, returns data and menu, data.current is used to get the current selected element
Example
function(data, menu)
--- for a simple element
if data.current.name == "element1" then
print("Element 1 Selected")
menu.close()
end
-- for slider elements
if data.current.name == "bread" then
print(data.current.value)
end
endcancel
This function is triggered when the menu gets closed, returns data and menu
Example
function(data, menu)
print("Closing Menu - " .. menu.title)
menu.close() -- close menu
endMenu Example
local Elements = {
{label = "I`m An Element", name = "element1"},
{label = "Bread - £200", name = "bread", value = 1, type = 'slider', min = 1,max = 100},
{label = '<span style="color:green;">HEY! IM GREEN!/span>', name = "geen_element"}
}
local Locales = {
backspace = "Back",
select = "Select"
}
ESX.UI.Menu.Open("default", GetCurrentResourceName(), "Example_Menu", {
title = "Example Menu", -- The Name of Menu to show to users,
align = 'top-left', -- top-left | top-right | bottom-left | bottom-right | center |
elements = Elements, -- define elements as the pre-created table
locales = Locales -- define optional button locales as the pre-created table
}, function(data,menu) -- OnSelect Function
--- for a simple element
if data.current.name == "element1" then
print("Element 1 Selected")
menu.close()
end
-- for slider elements
if data.current.name == "bread" then
print(data.current.value)
if data.current.value == 69 then
print("Nice!")
menu.close()
end
end
end, function(data, menu) -- Cancel Function
print("Closing Menu")
menu.close() -- close menu
end)Result
