GetMenuData
GetMenuData
GetMenuData
on top of your client scripts add this to get the menu data setters and getters
The menu data
Copy
local Menu = exports.vorp_menu:GetMenuData()
CloseAll
CloseAll
CloseAll
Close all menus
Copy
-- these params are optional
MenuData.CloseAll(showRadar, soundClose, fireEventClose)
Menu Elements
Menu elements are the elements that will be displayed in the menu- Elements
- Sliders
- Tick Box
- Desc Price
- Menu Params
Menu Elements
Menu Elements
for each element you can use the following params
The value of the tab element
The label of the tab element
The description of the tab element
The height of the tab element example
4vhThe position of the label
left or centerThe text of the footer
If true the element will not be selectable, meaning the red square will not be shown
If true the element will not be clickable and will be grayed out
The image name from vorp_inventory items folder, for grid menu only
If
true will not fire the open event by default it will fire the open eventCopy
local menuElements = {
{
label = "name",
value = "value",
desc = "description",
itemHeight = "4vh", -- optional
labelPos = "left", -- optional
footerText = "any text here", -- optional
isNotSelectable = true, -- optional
image = "image", -- optional
skipeOpenEvent = false, -- if true will not fire open event -- optional
}
}
Slider Number
Slider Number
allows to use a slider type of element to select a number , can be floats or integers this is defined by the hop value
The value of the tab element
The label of the tab element
The description of the tab element
The type of the tab element must be
sliderThe minimum value , if not defined will default to 0
The maximum value , if not defined will default to 100
The hop value , can hop by 1 2 etc, to use floats set the hop to 0.1 etc.
Copy
local menuElements = {
{
label = "name",
value = 0,
desc = "description",
type = "slider", -- required
min = 0,
max = 10,
hop = 1
}
}
Slider Text
Slider Text
allows to use a slider type of element to select a string , from a list of strings
The value of the tab element
The label of the tab element
The description of the tab element
The type of the tab element must be
text-sliderThe list of strings to select from
Copy
local menuElements = {
{
label = "name",
value = "value",
desc = "description",
type = "text-slider", -- required
textList = {
{
label = "skinny",
value = "anything you want",
},
{
label = "fatter",
value = "anything you want",
}
}
}
}
data.current.textIndex will return the index of the selected stringCopy
-- example
if data.current.value == "value" and data.current.textIndex then
local currentValue = data.current.textList[data.current.textIndex].value
end
Linear Label Slider
Linear Label Slider
allows to use a slider type in the label of the element to select a number , can be floats or integers this is defined by the hop value
works with press key or drag when
cursorEnabled is trueThe value
The label
The description
The type must be
label-sliderThe minimum value , if not defined will default to 0
The maximum value , if not defined will default to 100
The hop value , can hop by 1 2 etc, to use floats set the hop to 0.1 etc.
The attributes of the slider , can be used to style the slider
trackColor is the color of the track accepts names or hex codes rgba
fillColor is the color of the fill, only accepts linear-gradient you can choose one color or multiple colors and the direction
thumbColor is the color of the thumb accepts names or hex codes rgbaCopy
local menuElements = {
{
label = "name",
value = 0,
desc = "description",
type = "label-slider", -- required
min = 0,
max = 10,
hop = 1,
attributes = { -- optional
trackColor = "grey",
fillColor = "linear-gradient(90deg, #000, #fff)",
thumbColor = "white"
}
}
}
Linear Desc Slider
Linear Desc Slider
allows to create multiple sliders in the description of the element, can use integers or floats
The value of the tab element
The label of the tab element
The description of the tab element
The type of the tab element must be
desc-sliderThe minimum value , if not defined will default to 0
The maximum value , if not defined will default to 100
The hop value , can hop by 1 2 etc, to use floats set the hop to 0.1 etc.
The list of sliders
Copy
local menuElements = {
{
label = "name",
value = "any",
desc = "description",
type = "desc-slider", -- required
sliders = {
{
label = "Slider one",
value = 0,
min = 0,
max = 1,
hop = 1,
color = true, -- custom keys if needed
attributes = {
trackColor = "red", -- red or #ffff or a multicolor
fillColor = "linear-gradient(90deg, red, orange, yellow, green, blue, purple)", -- green or #ffff or a multicolor
thumbColor = "grey", -- yellow or #ffff or a multicolor
}
},
{
label = "Slider two",
value = 0.0,
min = -10.0,
max = 10.0,
hop = 0.1,
comp = true, -- custom keys if needed
},
}
}
}
data.current.sliderIndex will return the index of the selected sliderCopy
-- example
if data.current.value == "any" and data.current.sliders then
local currentValue = data.current.sliders[data.current.sliderIndex].value
end
Label Tick Box
Label Tick Box
allows to create a tick box in the element
only accept
unticked or tickedThe label of the tab element
The description of the tab element
to enable it set to true
Copy
local menuElements = {
{
label = "name",
value = "unticked", -- start unticked or ticked
desc = "description",
tickBox = true
}
}
data.current.value will return the value of the tick boxCopy
-- example
if data.current.tickBox then
print(data.current.value)
end
Desc Tick Box
Desc Tick Box
allows to create multiple tick boxes in the description of the element
The value of the tab element
The label of the tab element
The description of the tab element
The type of the element must be
tick-boxThe list of tick boxes
Copy
local menuElements = {
{
label = "label",
desc = "description",
value = "value",
type = "tick-box", -- required
tickBoxes = {
{
label = "box one",
value = "ticked", -- value will change to ticket or unticked
},
{
label = "box two",
value = "unticked", -- value will change to ticket or unticked
},
}
}
}
data.current.tickBoxIndex will return the index of the tick box we ticked or untickedCopy
-- example
if data.current.value == "value" and data.current.tickBoxes then
local currentValue = data.current.tickBoxes[data.current.tickBoxIndex].value
end
Desc Price
Desc Price
allows to create a price in the description of the element like RDO
The value of the tab element
The label of the tab element
The description of the tab element
The price of the tab element
amountis the amount of the priceiconisgoldormoneyonlytextthe label
Copy
local menuElements = {
{
label = "label",
desc = "description",
value = "value",
descPrice = {
amount = 100.00,
icon = "money",
text = "Price",
}
}
}
Copy
-- example
if data.current.value == "value" and data.current.descPrice then
local currentValue = data.current.descPrice.amount
end
Menu Params
Menu Params
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 if you wish to go back to the previous menu this will enable the following code and call a global function
Copy
if (data.current == "backup") then
return _G[data.trigger](parameters,parameters)
end
sets to all elements to this height
4vh etcsets the position of the label to all elements
leftcenter
adds a divider to the footer of the menu to all elements
sets the fixed height of the menu, so it doesnt resize depending on elements and description
enables the cursor for the menu, key inputs will still work, including for sliders and tick boxes
- hover over the element and left click to select element then again left click to act as ENTER, or simply press ENTER
- right click to close the menu, or simply press Backspace
- scroll wheel to scroll up and down the menu
sets the max visible items in the menu
hides the radar when the menu opens. to display it again simple pass these params again in these functions
Copy
function(data, menu)
-- to hide the radar and to play the final sound of the menu closing
menu.close(hideRadar, soundClose)
-- also available here
Menu.CloseAll(hideRadar, soundClose)
end
plays the first opening sound of the menu
creates a button in the description , useful when you dont have to create a new element for a button
creates a button in the description , useful when you dont have to create a new element for a button
sets the menu to a grid layout, instead of a list layoutuse in the menuelements the value
image to display item imagesuseful for creating shopsif
true will skip the open event by default it will fire the open eventCopy
local MenuInfo = {
title = "menu title",
subtext = "menu sub text",
align = "top-right",
elements = menuElements,
lastmenu = "functionName",
itemHeight = "4vh",
labelPos = "left",
divider = true,
fixedHeight = true,
enableCursor = true,
maxVisibleItems = 6,
hideRadar = true,
soundOpen = true,
confirmButton = { label = "Confirm", value = "confirm" },
cancelButton = { label = "Cancel", value = "cancel" },
isGrid = false,
skipOpenEvent = false,
}
Functions
update elements ,add ,remove ,get elements runtime- Set
- Get
- Update
- Remove
- Close
- setTitle
- setSubtext
- Display Input
addNewElement
addNewElement
this function will add a new element to the current menu elements by orderrefresh menu to show new element
The label of the element
The value of the element
The description of the element
Copy
menu.addNewElement({
label = "label",
value = "open",
desc = "description"
})
Copy
menu.refresh()
getElementBy[Value/Index]
getElementBy[Value/Index]
find an element by value or index
data.current.valueis available to use in the menu elementsdata.current.indexis available to use in the menu elements
Copy
local element = menu.getElementByValue(value)
local element = menu.getElementByIndex(index)
setElement
setElement
this function will update a specific refresh menu to show changes
element variableThe
index of the menu element to updatedata.current.index is available to use in the menu elementsThe variable of the menu element to update ,
label,value,desc, anyThe new value of the menu element to update
Copy
menu.setElement(index, variable, newValue)
Copy
menu.refresh()
removeElementBy[Value/Index]
removeElementBy[Value/Index]
this function will remove a specific element by value or indexrefresh menu to show changes
The value of the element to remove
data.current.value is available to use in the menu elementsThe index of the element to update
data.current.index is available to use in the menu elementsstop looking at the first element found can be used when you loop through several elements and remove all indexes
Copy
menu.removeElementByIndex(index,loop)
menu.removeElementByValue(value,loop)
Copy
menu.refresh()
CloseMenu
CloseMenu
this function will close the current menu
show the radar when the menu closes
plays the final sound when the menu closes
if
true will fire the close event, this is usefull when you want to final close a menu
by default the events are only fire when using the backspaceCopy
menu.close(showRadar, soundClose, fireEventClose)
setTitle
setTitle
this function will set the title of the current menurefresh menu to show changes
The title of the menu
Copy
menu.setTitle("title")
Copy
menu.refresh()
setSubtext
setSubtext
this function will set the subtext of the current menurefresh menu to show changes
The subtext of the menu
Copy
menu.setSubtext("subtext")
Copy
menu.refresh()
Inputs
Inputs
creates an input box to collect text or numbers etc.
The type of input,
text, number, password, dateyesno is a special type of input that will just create a yes or no button, no input neededThe header of the input
The placeholder of the input
The buttons of the input
The max length of the input
The pattern of the input
lettersall Unicode letters and spacesnumbersnumbers onlyalphanumericall Unicode letters and numbersno-symbolsletters, numbers, spaces (all languages)usernameusername with international lettersphonephone numbers with + for country codesemailemail with international lettersmoneymoney format (supports both . and , decimals)no-specialno special symbols but allow apostrophes and hyphens
Copy
-- async function
menu.displayInput({
inputType = 'text',
header = 'Enter your name',
placeholder = 'Type here...', -- not for input type yesno
description = 'Are you sure you want to archive this bill?', -- for input type yesno only
buttons = { confirm = "Confirm", cancel = "Cancel" },
maxLength = 50,
pattern = 'letters',
patternMessage = "only letters alowed"
},
function(inputValue)
-- On submit
print("User entered: " .. inputValue)
end,
function()
-- On cancel
print("User cancelled pressed ESC")
end)
Events
- close menu event
Copy
AddEventHandler("vorp:menu:closemenu", function(data)
end)
- open menu event
Copy
AddEventHandler("vorp:menu:openmenu", function(data)
end)
Menu Example
Menu Example
Menu Example
Copy
function OpenMenu()
-- close any menu before opening
Menu.CloseAll()
local 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"
}
}
Menu.Open("default", GetCurrentResourceName() , "OpenMenu", -- unique namespace will allow the menu to open where you left off
{
title = "title",
subtext = "subtext",
align = "top-left", -- top-right , top-center , top-left
elements = menuElements, -- elements needed
lastmenu = "functionName", -- if you wish to go back to the previous menu , or remove (optional)
maxVisibleItems = 6, -- max visible items in the menu
hideRadar = true, -- hides the radar
soundOpen = true, -- plays the open sound of the menu
skipOpenEvent = false,
},
function(data, menu) -- submit callback
-- triggers when pressing/clicking enter
print("current key of MenuElements is " .. data.current.index)
print("current value of MenuElements is " .. data.current.value)
-- to go back to lastmenu if any
if (data.current == "backup") then --(optional) if lastmenu is defined
return _G[data.trigger](any,any) -- or the function of the last menu
end
end,
function(data,menu) -- cancel callback THIS IS OPTIONAL
-- when menu closes if lastmenu isn't defined
Menu.Close(true, true)
end,
-- do not use the below unless you really need, it causes the menu to spike when you press up and down because the submit callback is doing the same thing.
function(data, menu) -- change callback THIS IS OPTIONAL
-- if theres no previous menu close menu on backspace press
-- is called when scrolling through the elements, also when the type = "slider" is changed i dont know why.
end,
function(data,menu) -- close callback THIS IS OPTIONAL
-- when menu closes if lastmenu isnt defined
-- Menu.Close(showRadar, soundClose)
end)
end
