activatable
Overview
The activatable component manages the "activatable" state of an entity, determining when and how a player can interact with it through an activation action (e.g., clicking on it). It controls various activation modifiers such as forced right-click, quick actions, and standing actions by adding or removing specific tags on the entity. It provides hooks for custom activation logic and triggers an event upon successful activation.
Dependencies & Tags
Dependencies: None identified. This component primarily interacts with the entity's tag system.
Tags Added/Removed by this Component:
inactive: Added whenself.inactiveistrue, removed whenfalse. Typically prevents general interaction.standingactivation: Added whenself.standingactionistrue, removed whenfalse. Suggests the entity requires the player to be standing to activate.quickactivation: Added whenself.quickactionistrue, removed whenfalse. Implies a quicker or more immediate activation context.activatable_forceright: Added whenself.forcerightclickactionistrue, removed whenfalse. Forces activation via right-click interaction.activatable_forcenopickup: Added whenself.forcenopickupactionistrue, removed whenfalse. Prevents pickup when the entity is activatable.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil | A reference to the entity this component is attached to. |
OnActivate | function | nil | A callback function (inst, doer) that is executed when DoActivate is called. It should return success, msg. |
inactive | boolean | true | When true, the entity is considered inactive and cannot be activated. This property automatically adds/removes the inactive tag. |
standingaction | boolean | false | When true, this component adds the standingactivation tag to the entity. |
quickaction | boolean | false | When true, this component adds the quickactivation tag to the entity. |
forcerightclickaction | boolean | false | When true, this component adds the activatable_forceright tag to the entity, suggesting it should be activated via right-click. |
forcenopickupaction | boolean | false | When true, this component adds the activatable_forcenopickup tag to the entity, indicating it cannot be picked up while activatable. |
CanActivateFn | function | nil | An optional callback function (inst, doer) that can be set externally. If present, its return value (success, msg) will override or extend the default CanActivate logic. |
Main Functions
Activatable:OnRemoveFromEntity()
- Description: This function is automatically called when the component is removed from its parent entity. It ensures that all tags added by this component (e.g.,
inactive,quickactivation) are properly cleaned up and removed from the entity to prevent lingering side effects. - Parameters: None.
Activatable:CanActivate(doer)
- Description: Determines if the entity can currently be activated by a specific
doer. By default, it returnstrueifself.inactiveisfalse. If a customself.CanActivateFnhas been set, that function's return value will be used instead, allowing for complex activation conditions. - Parameters:
doer: TheEntityattempting to activate this component.
- Returns:
success (boolean), msg (string, optional):success:trueif the entity can be activated,falseotherwise.msg: An optional string message providing a reason if activation is not possible.
Activatable:DoActivate(doer)
- Description: Initiates the activation process. It first checks if
self.OnActivateis defined. If so, it setsself.inactivetofalse(making the entity non-inactive), calls theself.OnActivatecallback with the entity and the doer, and then pushes an"onactivated"event if the callback returnstruefor success. - Parameters:
doer: TheEntityperforming the activation.
- Returns:
success (boolean, optional), msg (string, optional):- The return values from the
self.OnActivatecallback. Ifself.OnActivateisnil, it returnsnil.
- The return values from the
Activatable:GetDebugString()
- Description: Returns a string representation of the component's current
inactivestate, primarily for debugging purposes. - Parameters: None.
- Returns:
string: The string representation ofself.inactive(e.g.,"true"or"false").
Events & Listeners
- Pushes:
"onactivated": Triggered byActivatable:DoActivate(doer)if theself.OnActivatecallback returnstruefor success.- Payload:
{doer = doer_entity}
- Payload: