Playeractionpicker
Based on game build 714014 | Last updated: 2026-03-03
Overview
PlayerActionPicker resolves contextual player actions (left-click, right-click, double-click, and hover states) into concrete executable actions. It sits at the intersection of input handling, inventory, world state, and gameplay systems, aggregating action proposals from attached prefabs, items, and components (SCENE, USEITEM, EQUIPPED, POINT, INVENTORY), then filters and sorts them by priority and validity. It integrates with PlayerController, AOETargeting, and container systems to ensure correct action behavior under modifiers like FORCE_STACK, FORCE_INSPECT, and boat steering.
Usage example
local inst = ThePlayer
inst:AddComponent("playeractionpicker")
-- Register a container to enable its actions
inst.components.playeractionpicker:RegisterContainer(mycontainer)
-- Get left-click actions at a world position
local actions = inst.components.playeractionpicker:GetLeftClickActions(Vector3(x, y, z), target_entity)
-- Push/pop an action filter to temporarily override action availability
local function myFilter(inst, action) return action.action ~= ACTIONS.DROP end
inst.components.playeractionpicker:PushActionFilter(myFilter, 10)
inst.components.playeractionpicker:PopActionFilter(myFilter)
Dependencies & tags
Components used: playercontroller, boatcannonuser, container, inventory, rider, combat, aoetargeting, aoecharging
Tags: Checks hostile, inspectable, walkableplatform, walkableperipheral, ignoremouseover, repairer, deployable, allow_action_on_impassable; adds none.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | EntityScript | — | Owner entity (typically player). |
map | WorldMap | TheWorld.Map | Map geometry/accessibility reference. |
containers | table | {} | Mapping of container → unregister callback. |
leftclickoverride | function or nil | nil | Custom override for left-click action resolution. |
rightclickoverride | function or nil | nil | Custom override for right-click action resolution. |
pointspecialactionsfn | function or nil | nil | Function returning special point-based actions (e.g., double-tap or touch gestures). |
actionfilterstack | table | {} | Stack of action filter entries: {fn = function, priority = number}. |
actionfilter | function or nil | nil | Currently active filter function; nil means no filtering. |
Main functions
RegisterContainer(container)
- Description: Registers a container entity to participate in action resolution. A callback is attached to the container’s
"onremove"event to auto-unregister on destruction. - Parameters:
container(EntityScriptornil) — entity to register. - Returns: Nothing.
UnregisterContainer(container)
- Description: Removes a previously registered container and cleans up event callbacks.
- Parameters:
container(EntityScriptornil) — entity to unregister. - Returns: Nothing.
HasContainerWidgetAction()
- Description: Returns
trueif any containers are currently registered and contributing actions. - Parameters: None.
- Returns:
boolean.
PushActionFilter(filterfn, priority)
- Description: Adds an action filter function to the top of the priority stack; the highest-priority active filter is used during action sorting.
- Parameters:
filterfn(function):(inst, action) -> boolean— returnstrueif action is allowed.priority(number, optional): priority level; defaults to0.
- Returns: Nothing.
PopActionFilter(filterfn)
- Description: Removes a filter from the stack. If
filterfnisnil, removes the highest-priority filter unconditionally. - Parameters:
filterfn(functionornil) — filter to remove. - Returns: Nothing.
SortActionList(actions, target, useitem)
- Description: Sorts action proposals by priority (via
OrderByPriority) and applies the activeactionfilter. ForCASTAOEactions, it attaches the effective AOE range (useitem.components.aoetargeting:GetRange()). ConstructsBufferedActionobjects for valid actions. - Parameters:
actions(table): List ofACTIONSor action tables.target(EntityScript,Vector3, ornil): Action target.useitem(EntityScriptornil): Item being used (to determine AOE range).
- Returns:
tableofBufferedActioninstances.
GetSceneActions(useitem, right)
- Description: Collects scene-level actions for an item or the player. If no actions exist and inspection is valid, adds
WALKTOas fallback (unless AOE targeting is active on right-click). - Parameters:
useitem(EntityScript): Item or player performing actions.right(boolean):truefor right-click context (alt actions),falsefor left-click.
- Returns:
tableofBufferedActioninstances.
GetUseItemActions(target, useitem, right)
- Description: Collects actions for
useitemapplied totarget. - Parameters:
target(EntityScript): Target entity.useitem(EntityScript): Item performing the action.right(boolean): Context flag.
- Returns:
tableofBufferedActioninstances.
GetSteeringActions(inst, pos, right)
- Description: Returns steering-related actions if the player is steering a boat. Returns
STOP_STEERING_BOAT(right) orSET_HEADING(left, non-controller). - Parameters:
inst(EntityScript): Player entity.pos(Vector3): Click position.right(boolean): Context flag.
- Returns:
tableofBufferedActionornil.
GetCannonAimActions(inst, pos, right)
- Description: Returns boat cannon aiming/shooting actions if a cannon is active.
- Parameters:
inst(EntityScript): Player entity.pos(Vector3): Click position.right(boolean): Context flag.
- Returns:
tableofBufferedActionornil.
GetPointActions(pos, useitem, right, target)
- Description: Collects point-based actions (e.g., drop, throw, place). Enforces
wholestackoption unlessCONTROL_FORCE_STACKis held. - Parameters:
pos(Vector3): Click position.useitem(EntityScript): Item performing the action.right(booleanornil): Context flag.target(EntityScriptornil): Optional target (e.g., forDROPon a container).
- Returns:
tableofBufferedActioninstances.
GetPointSpecialActions(pos, useitem, right, usereticulepos)
- Description: Invokes
pointspecialactionsfnif defined (e.g., for touch/double-tap actions). Supports an optional second position return (pos2) for reticule-based targeting. - Parameters:
pos(Vector3): Initial click position.useitem(EntityScriptornil).right(booleanornil).usereticulepos(boolean): Indicates whether to use reticule position instead of rawpos.
- Returns:
tableofBufferedActioninstances.
GetDoubleClickActions(pos, dir, target)
- Description: Invokes
doubleclickactionsfnif defined (not shown in this file but expected). Supports an optional second position return. - Parameters:
pos(Vector3ornil): Double-click position (mouse).dir(Vector3ornil): Direction (WASD/analog).target(EntityScriptornil): Target under mouse.
- Returns:
tableofBufferedActioninstances.
GetEquippedItemActions(target, useitem, right)
- Description: Collects actions triggered by the equipped
useitemontarget. - Parameters:
target(EntityScript): Target entity.useitem(EntityScript): Equipped item.right(boolean): Context flag.
- Returns:
tableofBufferedActioninstances.
GetInventoryActions(useitem, right)
- Description: Collects inventory-related actions (
DROP,THROW,EAT, etc.). Overrides toACTIONS.DROPwhenCONTROL_FORCE_TRADEis held; enforceswholestackunlessCONTROL_FORCE_STACKis held. - Parameters:
useitem(EntityScript): Item in hand.right(boolean): Context flag.
- Returns:
tableofBufferedActioninstances.
GetLeftClickActions(position, target)
- Description: Resolves the full set of left-click actions. Checks overrides, steering, cannon aim, item use (on entities or point), scene inspection/attack/equipped-item actions, and point special actions.
- Parameters:
position(Vector3): World click position.target(EntityScriptornil): Entity under mouse (ornilfor point).
- Returns:
tableofBufferedActioninstances.
GetRightClickActions(position, target, spellbook)
- Description: Resolves the full set of right-click actions. Handles containers, item use, equipped weapons (including stripping actions for
CASTAOE), scene inspection/attack/equipped-item actions, point special actions, and AOE passability logic. Respectsdisable_right_click(set by steering/cannon precedence). - Parameters:
position(Vector3): World click position.target(EntityScriptornil): Entity under mouse (ornilfor point).spellbook(EntityScriptornil): Optional spellbook (used for AOE targeting).
- Returns:
tableofBufferedActioninstances.
DoGetMouseActions(position, target, spellbook)
- Description: Main entry point for retrieving top-priority left- and right-click actions. Handles AOE targeting state, point visibility (darkness), and filters out redundant actions (e.g.,
CLOSESPELLBOOKon self). Returns the highest-priority action for each button, if any. - Parameters:
position(Vector3ornil): Mouse position in world.target(EntityScriptornil): Entity under mouse.spellbook(EntityScriptornil): Active spellbook for AOE targeting.
- Returns:
BufferedAction(LMB),BufferedAction(RMB ornil).
Events & listeners
- Listens to:
"onremove"on registered containers to triggerUnregisterContainer.