Followerherder
Based on game build 714014 | Last updated: 2026-03-03
Overview
Followerherder is a component that allows an entity to control the hostility state of followers associated with a given leader. When activated (typically via an action), it inverts the current hostile state for all followers and optionally consumes uses from a finiteuses component. It supports custom validation (CanHerd) and side-effect (Herd) callbacks via function hooks.
Usage example
local inst = CreateEntity()
inst:AddComponent("followerherder")
inst.components.followerherder:SetUseAmount(1)
inst.components.followerherder:SetCanHerdFn(function(self_inst, leader)
return leader:HasTag("herdable_leader"), "Leader is not herdable"
end)
inst.components.followerherder:SetOnHerdFn(function(self_inst, leader)
print("Follower herd triggered for leader:", leader:GetDebugName())
end)
Dependencies & tags
Components used: finiteuses, leader
Tags: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
hostile | boolean | true | Current hostility state; toggled on herd action. |
canherdfn | function or nil | nil | Optional predicate function (self, leader) -> can_herd: boolean, reason: string?. |
onherfn | function or nil | nil | Optional callback function (self, leader) invoked after herding. |
use_amount | number | 1 | Number of uses to consume from finiteuses if present. |
Main functions
SetCanHerdFn(fn)
- Description: Assigns a custom predicate function used by
CanHerdto determine if herding is allowed. - Parameters:
fn(function or nil) - Signature:fn(self, leader) -> can_herd: boolean, reason?: string. - Returns: Nothing.
SetOnHerdFn(fn)
- Description: Assigns a callback function executed after a successful
Herdaction. - Parameters:
fn(function or nil) - Signature:fn(self, leader). - Returns: Nothing.
SetUseAmount(use_amount)
- Description: Sets the number of uses to consume from the
finiteusescomponent onHerd. - Parameters:
use_amount(number) - Number of uses to consume; defaults to1if not set or ifnil. - Returns: Nothing.
CanHerd(leader)
- Description: Checks whether the current entity can herd the given
leader. Runs the optionalcanherdfnpredicate first, if present. - Parameters:
leader(Entity) - The entity whose followers would be controlled. - Returns:
can_herd: boolean, reason?: string—trueif allowed; optionally returns a reason string on failure. - Error states: Returns
false, reasonifcanherdfnis set and returnsfalseor a falsy value.
Herd(leader)
- Description: Executes the herd action: toggles
hostilestate for all followers of theleader, consumes finite uses (if applicable), and runs theonherfncallback if set. - Parameters:
leader(Entity) - The leader whose followers' hostility states are inverted. - Returns: Nothing.
- Error states: If
leaderhas noleadercomponent or no followers, no followers are toggled, but the component still attempts to consume uses and callonherfn. No explicit error is thrown.
Events & listeners
- Listens to: None.
- Pushes: None.