Menu
The Menu system provides hierarchical navigation menus with support for dynamic content, search functionality, and customizable layouts. Perfect for creating complex user interfaces with multiple levels of navigation.

registerMenu
Register a menu definition that can be displayed later with customizable structure and behavior.
Parameters:
menuId(string): Unique menu identifier for registration and displaymenuData(table): Menu configuration objecttitle(string, optional): Menu title displayed in header (default: empty string)subtitle(string, optional): Menu subtitle displayed below title (default: empty string)type(string, optional): Menu layout type - 'list', 'grid', 'compact' (default: 'list')position(string, optional): Menu position on screen (default: from config)showSearch(boolean, optional): Enable search functionality (default: false)showHeader(boolean, optional): Show menu header with title/subtitle (default: true)showClose(boolean, optional): Show close button in header (default: true)maxHeight(number, optional): Maximum menu height in pixels (default: 600)width(number, optional): Menu width in pixels (default: from config)items(table, optional): Array of menu items (default: empty array)searchPlaceholder(string, optional): Search input placeholder textenableKeyboard(boolean, optional): Enable keyboard navigation (default: true)closeOnSelect(boolean, optional): Close menu when item selected (default: true)
Returns: boolean - Success status
Example:
showMenu
Display a registered menu with optional display options and context data.
Parameters:
playerId(number, server-side only): Player server ID to show menu tomenuId(string): Menu ID to display (must be registered first)options(table, optional): Additional display optionsposition(string, optional): Override default menu positioncontextData(table, optional): Dynamic data to pass to menu itemsselectedIndex(number, optional): Initially selected item indexsearchTerm(string, optional): Pre-populate search fieldisSubMenu(boolean, optional): Internal flag for submenu navigation
Returns: boolean - Success status
Example:
hideMenu
Hide the currently active menu with optional animation and cleanup.
Parameters:
playerId(number, server-side only): Player server ID to hide menu for
Returns: boolean - Success status
Example:
navigateToSubmenu
Navigate to a registered submenu while maintaining navigation history.
Parameters:
playerId(number, server-side only): Player server IDsubmenuId(string): Submenu ID to navigate to (must be registered)
Returns: boolean - Success status
Example:
updateMenuItems
Update menu items dynamically for an active or registered menu.
Parameters:
playerId(number, server-side only): Player server IDmenuId(string): Menu ID to update items foritems(table): New items array to replace existing items
Returns: boolean - Success status
Example:
getActiveMenu
Get information about the currently active menu.
Returns: table|nil - Active menu data or nil if no menu is active
id(string): Menu identifiertitle(string): Menu titletype(string): Menu typeposition(string): Menu positionitemCount(number): Number of itemsselectedIndex(number): Currently selected item indexsearchTerm(string): Current search term
Example:
isMenuActive
Check if a specific menu is currently active.
Parameters:
menuId(string, optional): Menu ID to check (if nil, checks if any menu is active)
Returns: boolean - True if specified menu (or any menu) is active
Example:
Menu Item Structure
Menu items support various properties for different functionality and appearance:
Menu Types
List Menu
Standard vertical list layout with icons and descriptions.
Grid Menu
Grid layout for visual items like vehicles, weapons, or categories.
Compact Menu
Minimal layout for simple option lists.
Server-Side Usage
Server-side menu functions allow you to manage menus for specific players:
Configuration
Complete menu configuration options in config.lua:
Advanced Examples
Dynamic Player List Menu
Multi-Level Admin Menu
Inventory Menu with Categories
Context-Aware Vehicle Menu
Search-Enabled Command Menu
Events
The Menu system triggers comprehensive events for handling user interactions:
b2lib:menu-item-selected
Triggered when user selects a menu item.
b2lib:menu-closed
Triggered when a menu is closed.
b2lib:menu-search
Triggered when user searches in a menu.
b2lib:submenu-navigated
Triggered when navigating to a submenu.
Best Practices
Use Descriptive Menu IDs: Choose clear, unique identifiers that describe the menu's purpose
Implement Search for Large Lists: Enable search functionality for menus with more than 10 items
Provide Clear Item Descriptions: Include helpful descriptions for complex or ambiguous menu items
Use Appropriate Icons: Select relevant Lucide icons that enhance visual understanding
Group Related Items: Use separators and headers to organize menu items logically
Handle Menu Events: Always implement event handlers for menu interactions
Update Dynamic Content: Refresh menu items when underlying data changes
Consider Performance: Avoid creating menus with hundreds of items; use pagination instead
Test Keyboard Navigation: Ensure all menu functions work with keyboard-only input
Provide Context Data: Pass relevant context information to menu items for dynamic behavior
Troubleshooting
Menu Not Displaying
Problem: Menu doesn't appear when calling showMenu()
Solutions:
Menu Items Not Updating
Problem: updateMenuItems() doesn't refresh the display
Solutions:
Submenu Navigation Issues
Problem: Submenu navigation not working properly
Solutions:
Search Functionality Not Working
Problem: Menu search doesn't filter items correctly
Solutions:
Performance Issues with Large Menus
Problem: Menu becomes slow with many items
Solutions:
Menu Positioning Issues
Problem: Menu appears in wrong position or off-screen
Solutions:
Last updated