Menu Item Type
MenuItem
A MenuItem represents an entry in the right-click context menu.
Methods
index
menu_item:index() -> number
Returns the index of this menu item in the menu.
Returns:
number: The menu index
Example:
local menu_items = menu:get_all()
for _, item in ipairs(menu_items) do
logger:info("Index " .. item:index() .. ": " .. item:action() .. " -> " .. item:target())
end
action
menu_item:action() -> string
Returns the action text (e.g., "Attack", "Talk-to", "Take").
Returns:
string: The action text
Example:
local menu_items = menu:get_all()
for _, item in ipairs(menu_items) do
if item:action() == "Attack" then
logger:info("Found attack option for: " .. item:target())
end
end
target
menu_item:target() -> string
Returns the target text (e.g., "Guard", "Banker", "Coins").
Returns:
string: The target text
Example:
local menu_items = menu:get_all()
for _, item in ipairs(menu_items) do
if item:target():find("Banker") then
logger:info("Banker menu option: " .. item:action())
end
end
Common Patterns
Finding Specific Menu Options
local function find_menu_option(action_text, target_text)
local menu_items = menu:get_all()
for _, item in ipairs(menu_items) do
local action_match = action_text == nil or item:action():find(action_text)
local target_match = target_text == nil or item:target():find(target_text)
if action_match and target_match then
return item
end
end
return nil
end
-- Find "Attack" option for "Guard"
local attack_option = find_menu_option("Attack", "Guard")
if attack_option then
logger:info("Found at index: " .. attack_option:index())
end
Listing All Menu Options
local function print_menu_options()
local menu_items = menu:get_all()
logger:info("===== Menu Options =====")
for _, item in ipairs(menu_items) do
logger:info(item:index() .. ". " .. item:action() .. " -> " .. item:target())
end
logger:info("========================")
end
print_menu_options()
Checking for Specific Actions
local function has_menu_action(action_text)
local menu_items = menu:get_all()
for _, item in ipairs(menu_items) do
if item:action() == action_text then
return true
end
end
return false
end
if has_menu_action("Pick-lock") then
logger:info("Pick-lock option available")
end
Finding Actions by Target
local function get_actions_for_target(target_text)
local menu_items = menu:get_all()
local actions = {}
for _, item in ipairs(menu_items) do
if item:target():find(target_text) then
table.insert(actions, item:action())
end
end
return actions
end
local banker_actions = get_actions_for_target("Banker")
for _, action in ipairs(banker_actions) do
logger:info("Banker action: " .. action)
end
Menu Option Validation
local function validate_menu_option(action, target)
local menu_items = menu:get_all()
for _, item in ipairs(menu_items) do
if item:action() == action and item:target() == target then
logger:info("Valid menu option found at index " .. item:index())
return true
end
end
logger:warn("Menu option not found: " .. action .. " -> " .. target)
return false
end
validate_menu_option("Attack", "Guard")
Counting Menu Entries
local function count_menu_entries()
local menu_items = menu:get_all()
return #menu_items
end
local count = count_menu_entries()
logger:info("Menu has " .. count .. " entries")
Finding by Index Range
local function get_top_menu_options(count)
local menu_items = menu:get_all()
local top_options = {}
for i = 1, math.min(count, #menu_items) do
table.insert(top_options, menu_items[i])
end
return top_options
end
local top_3 = get_top_menu_options(3)
for _, item in ipairs(top_3) do
logger:info(item:action() .. " -> " .. item:target())
end
Filtering Menu Items
local function filter_menu_items(filter_fn)
local menu_items = menu:get_all()
local filtered = {}
for _, item in ipairs(menu_items) do
if filter_fn(item) then
table.insert(filtered, item)
end
end
return filtered
end
-- Get all "Take" actions
local take_actions = filter_menu_items(function(item)
return item:action() == "Take"
end)
logger:info("Found " .. #take_actions .. " Take actions")
Menu Context Analysis
local function analyze_menu_context()
local menu_items = menu:get_all()
local has_combat = false
local has_interact = false
local has_pickup = false
for _, item in ipairs(menu_items) do
local action = item:action()
if action == "Attack" then
has_combat = true
elseif action:find("Talk") or action:find("Trade") then
has_interact = true
elseif action == "Take" then
has_pickup = true
end
end
logger:info("Combat options: " .. tostring(has_combat))
logger:info("Interaction options: " .. tostring(has_interact))
logger:info("Pickup options: " .. tostring(has_pickup))
end
analyze_menu_context()
Finding Multiple Targets
local function find_all_targets()
local menu_items = menu:get_all()
local targets = {}
for _, item in ipairs(menu_items) do
local target = item:target()
if not targets[target] then
targets[target] = {}
end
table.insert(targets[target], item:action())
end
return targets
end
local targets = find_all_targets()
for target, actions in pairs(targets) do
logger:info(target .. ": " .. table.concat(actions, ", "))
end
Menu Item Filters
MenuItem objects are commonly used with filter tables when interacting with entities:
-- Using action filters
npc:interact({action = "Talk-to"})
npc:interact({action_equals = "Attack"})
npc:interact({action_contains = "Talk"})
-- Using target filters
game_object:interact({target = "Door"})
game_object:interact({target_equals = "Wooden door"})
game_object:interact({target_contains = "door"})
-- Combining filters
ground_item:interact({
action = "Take",
target = "Coins"
})
Filter Types
Action Filters
action- Flexible contains matching (most common)action_equals- Exact matchaction_contains- Contains match (same asaction)
Target Filters
target- Flexible contains matching (most common)target_equals- Exact matchtarget_contains- Contains match (same astarget)
Examples by Action Type
Combat Actions
-- Attack, Cast spell on, Use ranged on
local menu_items = menu:get_all()
for _, item in ipairs(menu_items) do
if item:action():find("Attack") or item:action():find("Cast") then
logger:info("Combat: " .. item:action() .. " -> " .. item:target())
end
end
Interaction Actions
-- Talk-to, Trade-with, Bank, etc.
local interactions = {"Talk-to", "Trade", "Bank", "Use"}
for _, item in ipairs(menu:get_all()) do
for _, interaction in ipairs(interactions) do
if item:action():find(interaction) then
logger:info("Interaction: " .. item:action() .. " -> " .. item:target())
end
end
end
Movement Actions
-- Walk here, Follow, Chase
local movement_actions = {"Walk", "Follow", "Chase"}
for _, item in ipairs(menu:get_all()) do
for _, movement in ipairs(movement_actions) do
if item:action():find(movement) then
logger:info("Movement: " .. item:action())
end
end
end
See Also
- NPC - NPC interaction with menu filters
- GameObject - Object interaction with menu filters
- GroundItem - Item interaction with menu filters
- Player - Player interaction with menu filters