Menu
vorp menu is a library that allows you to create menus in game with a rdr2 style.
GetMenuData
on top of your client scripts add this to get the menu data setters and getters
The menu data
local Menu = exports.vorp_menu:GetMenuData()
CloseAll
Menu Elements
Menu elements are the elements that will be displayed in the menu
The value of the tab element
The label of the tab element
The description of the tab element
The type of the tab element
The minimum value of the tab element can also be floats
The maximum value of the tab element can also be floats
The hop value of the tab element
local MenuElements = {
{
label = "name",
value = 0,
desc = "description",
type = "slider",
min = 0,
max = 10,
hop = 1
}
}
The value of the tab element
The label of the tab element
The description of the tab element
The height of the tab element
Any value ,string,number,table,array,etc.
table within a table
local MenuElements = {
{
label = "name",
value = "value",
desc = "description",
itemHeight = "4vh",
any = any,
table = {
string = "string",
number = 111,
table = table,
}
}
}
The title of the menu
The subtext of the menu
The align of the menu , top-right , top-center , top-left
The elements for the menu
The last menu function name
The height of the all menu elements
local MenuInfo = {
title = "menu title",
subtext = "menu sub text",
align = "top-right",
elements = MenuElements,
lastmenu = "function", -- if you wish to go back to the previous menu , or remove (optional)
itemHeight = "4vh", -- set all elements to this height if they are not definded in the element (optional)
}
Functions
update elements ,add ,remove ,get elements runtime
this function will add a new element to the current menu elements by order
The label of the element
The value of the element
The description of the element
menu.addNewElement({
label = "label",
value = "open",
desc = "description"
})
refresh menu to show new element
menu.refresh()
this function will add a new element to the current menu elements by order
The label of the element
The value of the element
The description of the element
menu.addNewElement({
label = "label",
value = "open",
desc = "description"
})
refresh menu to show new element
menu.refresh()
find an element by value or index
local element = menu.getElementByValue(value)
local element = menu.getElementByIndex(index)
this function will update a specific element variable
The index of the menu element to update
The variable of the menu element to update , label,value,desc, any
The new value of the menu element to update
menu.setElement(index, variable, newValue)
refresh menu to show changes
menu.refresh()
this function will remove a specific element by value or index
The value of the element to remove
stop looking at the first element found can be used when you loop through several elements and remove all indexes
menu.removeElementByIndex(index,loop)
menu.removeElementByValue(value,loop)
refresh menu to show changes
menu.refresh()
this function will close the current menu
menu.close()
this function will set the title of the current menu
The title of the menu
menu.setTitle("title")
refresh menu to show changes
menu.refresh()
Menu Example
function OpenMenu()
Menu.CloseAll()
MenuElements = {
{
label = "name",
value = "value",
desc = "description"
}
{
label = "name",
value = 0,
desc = "description",
type = "slider",
min = 0,
max = 10,
hop = 1
}
{
label = "name",
value = "value",
desc = "description",
itemHeight = "4vh"
}
{
label = "name",
value = "value",
desc = "description",
any = any --(optional)
table = { --(optional)
string = "string",
number = 111,
table = table,
}
}
}
Menu.Open("default",GetCurrentResourceName(),"OpenMenu", -- unique namespace will allow the menu to open where you left off
{
title = "menu title",
subtext = "menu sub text",
align = "align", -- top-right , top-center , top-left
elements = MenuElements, -- elements needed
lastmenu = "function name", -- if you wish to go back to the previous menu , or remove (optional)
itemHeight = "4vh", -- set all elements to this height if they are not definded in the element (optional)
},
function(data, menu)
-- to go back to lastmenu if any
if (data.current == "backup") then --(optional)
return _G[data.trigger](any,any) -- or the function of the last menu
end
-- get any of the params you definded in the elements
if data.current.value == "value" then
return
end
if data.current.info == "param" then
return menu.close()
end
end,function(data,menu)
-- if theres no previous menu close menu on backspace press
menu.close()
end)
end