Context-Menu

Before diving into the functions, it's important to understand the two distinct ways you can display data using ak47_lib:

  1. Context Menus (RegisterContext & ShowContext): Best for static lists of actions where the user clicks an option to trigger an event, server event, or function. Usually mouse-driven.

  2. Interactive Menus (RegisterMenu & ShowMenu): Best for complex interactions like checkboxes, side-scrolling lists, and real-time navigation feedback. Completely keyboard-driven (Arrow Keys, Enter, Backspace).


🛠️ Core Functions

RegisterContext

Registers a mouse-driven context menu. This data is cached and can be called anytime using ShowContext.

Syntax:

Example:

RegisterMenu

Registers a keyboard-driven interactive menu. Features a master callback that triggers when the user presses Enter on an item.

Syntax:

Example:

Display & Hide Functions

Function

Description

Example Usage

ShowContext

Opens a registered context menu. You can specify if it should be keyboard only.

exports.ak47_lib:ShowContext('player_actions', false)

ShowMenu

Opens a registered menu in strict keyboard-only mode.

exports.ak47_lib:ShowMenu('settings_menu')

HideContext

Closes the active context menu.

exports.ak47_lib:HideContext(true)

HideMenu

Closes the active interactive menu.

exports.ak47_lib:HideMenu(true)

GetOpenMenu

Returns the string id of the currently open menu, or nil.

local current = exports.ak47_lib:GetOpenMenu()

SetMenuOptions

Dynamically updates the options of a registered menu without needing to re-register it.

Syntax:


⚙️ Configuration Properties

These properties are used at the root level of RegisterContext or RegisterMenu.

Property

Type

Description

id

string

Required. A unique identifier for the menu.

title

string

The display title at the top of the menu.

position

string

'top-left', 'top-right', 'bottom-left', or 'bottom-right'.

canClose

boolean

If true, the user can press ESC/Backspace to close.

disableInput

boolean

If true, disables all player controls while the menu is open.

options

table

Required. An array of option objects (see below).

onClose

function

Triggers when the menu is closed (receives the key pressed).

onSelected

function

(RegisterMenu only) Triggers when an item is hovered.

onSideScroll

function

(RegisterMenu only) Triggers when a side-scrolling list changes.

onCheck

function

(RegisterMenu only) Triggers when a checkbox is toggled.

Option Configuration (Items inside options)

Property

Type

Description

title / label

string

Required. The main text of the button. (title is preferred for Context, label for Menu).

description

string

Secondary text displayed as a tooltip or subtext.

icon

string

FontAwesome icon name (e.g., 'car', 'shield') or an image URL/Path.

iconColor

string

Hex or RGB color for the icon (e.g., '#ff5555').

iconAnimation

string

FontAwesome animation class (e.g., 'spin', 'beat').

disabled

boolean

Grays out the button and prevents interaction.

readOnly

boolean

Prevents hovering/clicking, but doesn't look completely disabled.

progress

number

0-100. Displays a progress bar inside the button.

colorScheme

string

Color used for the progress bar.

args

table

Custom data passed to events/callbacks when this item is interacted with.

close

boolean

Set to false to keep the menu open after clicking. Defaults to true.

Advanced Option Properties (Context Menus)

  • event (string): Triggers a client event when clicked. Passes args.

  • serverEvent (string): Triggers a server event when clicked. Passes args.

  • onSelect (function): Anonymous function executed when clicked. Passes args.

  • menu (string): The id of another menu to open when clicked (Submenu).

Advanced Option Properties (Interactive Menus)

  • checked (boolean): Turns the option into a Checkbox.

  • values (table): Array of strings or {label, description} objects. Turns the option into a Side-Scroller (Left/Right arrows).

  • defaultIndex (number): The starting index (1-based) for a values list.

Metadata Panel (Player/Vehicle Stats)

You can attach a beautiful side-panel to any option by adding image and metadata.


📝 Complete Usage Example

Here is a comprehensive example demonstrating submenus, side-scrolling, checkboxes, and metadata all working together seamlessly:

Last updated