Client side
The menu is built into jrs_core (modules/menu). No extra resource is needed. Old scripts that call exports.jrs_menu:GetMenuData() keep working because jrs_core provides jrs_menu.
GetMenuData#
Open#
Open#
Opens a menu and returns the menu instance (see Instance functions). Opening a menu with the same type, namespace and name closes the old one first.
typestringrequiredAlways "default".
namespacestringrequiredYour resource name, GetCurrentResourceName().
namestringrequiredA unique name for this menu inside your resource.
datatablerequiredThe menu data: title, subtext, align, elements (see Menu data).
submitfunctionCalled with (data, menu) when the player presses Enter on an element. data.current is the selected element.
cancelfunctionCalled with (data, menu) when the player presses Backspace. Close the menu here with menu.close().
changefunctionCalled with (data, menu) when a slider value changes.
closefunctionCalled when the menu is closed.
returntable | nilThe menu instance, or nil and a reason (ui_busy:<owner>, unknown_menu_type) when it could not open.
local MenuData = exports.jrs_core:GetMenuData()
MenuData.CloseAll()
MenuData.Open('default', GetCurrentResourceName(), 'shop_menu', {
title = 'General Store',
subtext = 'Choose an option',
align = 'top-left',
elements = {
{ label = 'Buy bread', value = 'bread', desc = '$0.50' },
{ label = 'Amount', value = 1, type = 'slider', min = 1, max = 10, hop = 1 },
},
}, function(data, menu)
if data.current.value == 'bread' then
print('bought bread')
end
end, function(data, menu)
menu.close()
end)Menu data#
Instance functions#
The table returned by Open (and passed as the second argument of your callbacks).
close#
Closes this menu and calls your close callback.
menu.close()refresh#
Redraws the menu after you changed the data.
menu.setTitle('New title')
menu.refresh()setTitle#
titlestringrequiredThe new title.
menu.setTitle('New title')setElement#
Changes one field of one row, then call refresh.
indexnumberrequiredRow index, starting at 1.
keystringrequiredThe field name, for example label.
valueanyrequiredThe new value.
menu.setElement(1, 'label', 'Sold out')
menu.refresh()setElements#
Replaces all rows.
menu.setElements({ { label = 'Back', value = 'back' } })
menu.refresh()update#
Updates every row that matches the query.
querytablerequiredFields a row must have, for example { value = 'bread' }.
newDatatablerequiredFields to set on the matching rows.
menu.update({ value = 'bread' }, { label = 'Bread (sold out)' })
menu.refresh()removeElement#
Removes every row that matches the query.
menu.removeElement({ value = 'bread' })
menu.refresh()Menu API functions#
CloseAll#
Closes every open menu.
MenuData.CloseAll()Close#
typestringrequired"default".
namespacestringrequiredThe resource name.
namestringrequiredThe menu name.
MenuData.Close('default', GetCurrentResourceName(), 'shop_menu')IsOpen#
local open = MenuData.IsOpen('default', GetCurrentResourceName(), 'shop_menu')IsAnyOpen#
if MenuData.IsAnyOpen() then return endGetOpened#
Returns the instance of an open menu, or nil.
local menu = MenuData.GetOpened('default', GetCurrentResourceName(), 'shop_menu')ReOpen#
Opens an instance again with its old data and callbacks. The menu does this itself after the pause menu closes.
MenuData.ReOpen(menu)Controls#
The menu reads the keyboard itself: arrows move, Enter selects, Backspace goes back. The pause menu closes open menus and brings them back afterwards.
RegisterControls and UnregisterControls exist for compatibility with older scripts and do nothing.
Events#
Fired on the client when the first menu opens and when the last one closes. Useful for pausing your own prompts.
AddEventHandler('jrs_menu:openmenu', function() end)
AddEventHandler('jrs_menu:closemenu', function() end)