Skip to main content

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

PropertyTypeDefault ValueDescription
hostilebooleantrueCurrent hostility state; toggled on herd action.
canherdfnfunction or nilnilOptional predicate function (self, leader) -> can_herd: boolean, reason: string?.
onherfnfunction or nilnilOptional callback function (self, leader) invoked after herding.
use_amountnumber1Number of uses to consume from finiteuses if present.

Main functions

SetCanHerdFn(fn)

  • Description: Assigns a custom predicate function used by CanHerd to 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 Herd action.
  • Parameters: fn (function or nil) - Signature: fn(self, leader).
  • Returns: Nothing.

SetUseAmount(use_amount)

  • Description: Sets the number of uses to consume from the finiteuses component on Herd.
  • Parameters: use_amount (number) - Number of uses to consume; defaults to 1 if not set or if nil.
  • Returns: Nothing.

CanHerd(leader)

  • Description: Checks whether the current entity can herd the given leader. Runs the optional canherdfn predicate first, if present.
  • Parameters: leader (Entity) - The entity whose followers would be controlled.
  • Returns: can_herd: boolean, reason?: stringtrue if allowed; optionally returns a reason string on failure.
  • Error states: Returns false, reason if canherdfn is set and returns false or a falsy value.

Herd(leader)

  • Description: Executes the herd action: toggles hostile state for all followers of the leader, consumes finite uses (if applicable), and runs the onherfn callback if set.
  • Parameters: leader (Entity) - The leader whose followers' hostility states are inverted.
  • Returns: Nothing.
  • Error states: If leader has no leader component or no followers, no followers are toggled, but the component still attempts to consume uses and call onherfn. No explicit error is thrown.

Events & listeners

  • Listens to: None.
  • Pushes: None.