Playeractionpicker
Based on game build 722832 | Last updated: 2026-04-17
Overview
PlayerActionPicker is a core player component that determines which actions are available when the player interacts with the world via mouse clicks or keyboard input. It collects potential actions from equipped items, inventory, target entities, and the environment, then filters and sorts them by priority. This component works closely with playercontroller for input state and aoetargeting for area-of-effect ability targeting.
Usage example
local inst = CreateEntity()
inst:AddComponent("playeractionpicker")
-- Register a container for widget actions
local container = SpawnPrefab("chest")
inst.components.playeractionpicker:RegisterContainer(container)
-- Push a custom action filter
inst.components.playeractionpicker:PushActionFilter(function(inst, action)
return action.action ~= ACTIONS.ATTACK
end, 50)
-- Get available actions for a position
local actions = inst.components.playeractionpicker:GetLeftClickActions(position, target)
Dependencies & tags
External dependencies:
ACTIONS-- global action constants tableBufferedAction-- creates buffered action instancesTheWorld.Map-- world map reference for passability checksTheInput-- input handling for controller and mouse stateCONTROL_FORCE_STACK,CONTROL_FORCE_TRADE,CONTROL_FORCE_INSPECT,CONTROL_FORCE_ATTACK-- input control constantsEQUIPSLOTS-- equipment slot constants
Components used:
inventory-- retrieves equipped and active items via replicaplayercontroller-- checks control press state and AOETargeting statuscombat-- checks if target can be attackedcontainer-- checks if container is read-onlystackable-- checks if item is a stack for drop behaviorinventoryitem-- checks if item is locked in slotspellbook-- retrieves active spell book for AOETargetingboatcannonuser-- handles boat cannon aiming and shooting actionsaoetargeting-- checks range, allowwater, alwaysvalid properties
Tags:
inspectable-- checked for examine/look actionshostile-- checked for attack actionswalkableplatform-- excluded from certain interactionsignoremouseover-- excluded from mouse interactionswalkableperipheral-- allows point actions on peripheral entitiessteeringboat-- enables boat steering actionsrepairer-- affects right-click behavior on targetsdeployable-- affects right-click behavior on targetsallow_action_on_impassable-- allows actions on impassable terrain
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil | The owning player entity instance. |
map | Map | TheWorld.Map | Reference to the world map for passability checks. |
containers | table | {} | Table of registered container entities with cleanup callbacks. |
leftclickoverride | function | nil | Custom function to override left-click action selection. |
rightclickoverride | function | nil | Custom function to override right-click action selection. |
pointspecialactionsfn | function | nil | Custom function for special point-based actions. |
actionfilterstack | table | {} | Stack of action filter functions with priorities. |
actionfilter | function | nil | Currently active highest-priority action filter. |
Main functions
RegisterContainer(container)
- Description: Registers a container entity to listen for its removal and clean up automatically. Adds an event listener for
onremoveon the container. - Parameters:
container-- Entity instance to register as a container. - Returns: None.
- Error states: None.
UnregisterContainer(container)
- Description: Unregisters a previously registered container and removes the
onremoveevent listener. - Parameters:
container-- Entity instance to unregister. - Returns: None.
- Error states: None.
HasContainerWidgetAction()
- Description: Checks if any container widget actions are currently registered.
- Parameters: None.
- Returns:
trueif containers table is non-empty,falseotherwise. - Error states: None.
OnUpdateActionFilterStack()
- Description: Recalculates the active action filter by finding the highest priority filter in the stack.
- Parameters: None.
- Returns: None.
- Error states: None.
PushActionFilter(filterfn, priority)
- Description: Adds an action filter function to the stack with optional priority. Higher priority filters take precedence.
- Parameters:
filterfn-- Function that takes(inst, action)and returns boolean.priority-- Number priority value (default0).
- Returns: None.
- Error states: None.
PopActionFilter(filterfn)
- Description: Removes an action filter from the stack. If
filterfnis provided, removes that specific filter; otherwise removes the top filter. - Parameters:
filterfn-- Function to remove, ornilto pop top filter. - Returns: None.
- Error states: None.
SortActionList(actions, target, useitem)
- Description: Sorts actions by priority and applies the active action filter. Creates
BufferedActioninstances for valid actions. - Parameters:
actions-- Table of action definitions to sort.target-- Target entity orVector3position, ornil.useitem-- Item entity being used for the action.
- Returns: Sorted table of
BufferedActioninstances. - Error states: None
GetSceneActions(useitem, right)
- Description: Collects scene-based actions from the useitem. Falls back to
WALKTOaction if no actions found and entity is inspectable. - Parameters:
useitem-- Entity being used for the action.right-- Boolean indicating right-click context.
- Returns: Sorted table of
BufferedActioninstances. - Error states: None
GetUseItemActions(target, useitem, right)
- Description: Collects actions for using an item on a target entity.
- Parameters:
target-- Target entity for the action.useitem-- Item entity being used.right-- Boolean indicating right-click context.
- Returns: Sorted table of
BufferedActioninstances. - Error states: None.
GetSteeringActions(inst, pos, right)
- Description: Returns boat steering actions if the player has the
steeringboattag. - Parameters:
inst-- Player entity instance.pos-- Position vector for steering.right-- Boolean indicating right-click context.
- Returns: Sorted table of
BufferedActioninstances, ornilif not steering a boat. - Error states: None.
GetCannonAimActions(inst, pos, right)
- Description: Returns boat cannon aiming and shooting actions if the player has a
boatcannonusercomponent with an active cannon. - Parameters:
inst-- Player entity instance.pos-- Position vector for aiming.right-- Boolean indicating right-click context.
- Returns: Sorted table of
BufferedActioninstances, ornilif no cannon available. - Error states: None.
GetPointActions(pos, useitem, right, target)
- Description: Collects point-based actions at a world position. Modifies
DROPaction to drop whole stack unlessCONTROL_FORCE_STACKis pressed. - Parameters:
pos-- World position vector.useitem-- Item entity being used.right-- Boolean indicating right-click context.target-- Optional target entity.
- Returns: Sorted table of
BufferedActioninstances. - Error states: Errors if
self.inst.components.playercontrollerisnilwhen checkingIsControlPressed().
GetPointSpecialActions(pos, useitem, right, usereticulepos)
- Description: Calls the custom
pointspecialactionsfnif set to get special point-based actions. Supports legacy function signature withoutpos2return. - Parameters:
pos-- World position vector.useitem-- Item entity being used.right-- Boolean indicating right-click context.usereticulepos-- Boolean indicating if reticule position should be used.
- Returns: Sorted table of
BufferedActioninstances, or empty table if no custom function. - Error states: None.
GetDoubleClickActions(pos, dir, target)
- Description: Calls the custom
doubleclickactionsfnif set to handle double-click actions. Supports legacy function signature. - Parameters:
pos-- Double-click position vector.dir-- WASD/analog direction input.target-- Double-click mouseover target entity.
- Returns: Sorted table of
BufferedActioninstances, or empty table if no custom function. - Error states: None.
GetEquippedItemActions(target, useitem, right)
- Description: Collects actions for using an equipped item on a target entity.
- Parameters:
target-- Target entity for the action.useitem-- Equipped item entity.right-- Boolean indicating right-click context.
- Returns: Sorted table of
BufferedActioninstances. - Error states: None.
GetInventoryActions(useitem, right)
- Description: Collects inventory-based actions. Handles drop behavior based on
CONTROL_FORCE_TRADEandCONTROL_FORCE_STACKmodifiers. - Parameters:
useitem-- Inventory item entity.right-- Boolean indicating right-click context.
- Returns: Sorted table of
BufferedActioninstances. - Error states: Errors if
self.inst.components.playercontrollerisnilwhen checking control press states.
GetLeftClickActions(position, target)
- Description: Determines all available left-click actions based on position, target, equipped items, and player state. Handles steering, cannon aiming, item usage, and scene interactions.
- Parameters:
position-- World position vector for the click.target-- Target entity under cursor, ornil.
- Returns: Sorted table of
BufferedActioninstances, or empty table. - Error states: Errors if
self.inst.components.playercontrollerisnilwhen checking control states orself.inst.replica.inventoryisnil.
GetRightClickActions(position, target, spellbook)
- Description: Determines all available right-click actions. Handles AOETargeting items, container interactions, and spellbook targeting. Checks passability for point actions.
- Parameters:
position-- World position vector for the click.target-- Target entity under cursor, ornil.spellbook-- Optional spellbook entity for AOETargeting.
- Returns: Sorted table of
BufferedActioninstances, or empty table. - Error states: Errors if
self.inst.replica.inventoryisnilwhen getting active/equipped items, or ifself.inst.components.playercontrollerisnilwhen checkingIsAOETargeting().
DoGetMouseActions(position, target, spellbook)
- Description: Main entry point for mouse action selection. Handles AOETargeting state, visibility checks, and filters duplicate or UI-only actions. Returns left and right mouse button actions.
- Parameters:
position-- World position vector, ornilto get from input.target-- Target entity, ornilto get from input.spellbook-- Optional spellbook entity.
- Returns: Two values:
lmb(left mouse action) andrmb(right mouse action), bothBufferedActionornil. - Error states: Errors if
self.inst.components.playercontrollerisnilwhen checking AOETargeting state or getting targeting position.
Events & listeners
- Listens to:
onremove- listens on registered container entities to clean up when containers are removed.