sf2.actors
Actors are extra characters that appear in a fight beside the two main fighters, such as a summoned helper or a hazard. Register an actor definition while your mod loads, then spawn it from a combat callback with fighter:spawn_actor. Get sf2 with local sf2 = require("sf2").
sf2.actors.register
Section titled “sf2.actors.register”Describe a fighter that your mod can summon. A definition cannot be changed after registration.
Signature: sf2.actors.register(definition)
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
ActorDefinition |
Required |
Fields of ActorDefinition
| Field | Type | Required | Meaning |
|---|---|---|---|
id |
string |
Required | — |
character |
WarriorHandle |
Required | — |
team |
"owner"|"opponent" |
Optional | Relative to spawner; default owner. |
ai |
boolean |
Optional | Use the standard warrior tactic. Default true. |
lifetime_frames |
integer |
Optional | Frames the actor lasts, 1 to 36000. Default 1800. |
max_health |
number |
Optional | Health multiplier, 0.01 to 100. Default 1. |
behavior |
BehaviorDefinition|StatefulBehavior |
Optional | Behavior for this actor. Each actor keeps its own state. |
parameters |
table<string,any> |
Optional | Behavior parameters. Needs behavior. |
Returns: An actor definition handle to pass to fighter:spawn_actor.
When: Registration, before combat callbacks.
local sf2 = require("sf2")local companion = sf2.fighters.register { id = "companion", fighter = "core:warrior-templates/default", level = 1, tactic = "Standard", skeleton = "Skeleton", items = { sf2.items.get("core:items/weapon/WEAPON_KNIVES") },}local ally = sf2.actors.register { id = "ally", character = companion, team = "owner", ai = true, lifetime_frames = 900, max_health = 1,}team is relative to the fighter that spawns the actor. With ai = false the actor stays idle so your Lua can steer it. lifetime_frames counts after the entry animation finishes. max_health is the whole pool (1 is a normal fighter’s full health) and starts full. Actors are not saved, and are retired when the round is decided (actor_end_reason = "round_ended"). The camera keeps framing the main fighters; see combat scripting.
Behavior
Section titled “Behavior”Pass a behavior table to give each spawned actor its own state and callbacks: on_actor_spawn, on_actor_end, on_tick, hit, damage, block, critical and animation callbacks, but not the fight, round, combo or style callbacks. AI decisions stay in the fighter’s tactic. See the callback reference.
local ward = { state = { lifetime = "round", fields = { ready = { type = "boolean", default = true }, } }, on_damage_resolving = function(self, fighter) if self.state.ready then fighter:scale_incoming_damage(0.5) self.state.ready = false end end,}local guarded = sf2.actors.register { id = "guarded", character = companion, behavior = ward }Each actor has its own copy of the state, which disappears with it; saved lifetime is rejected. Inside an actor’s callback fighter.source is "actor", fighter.opponent is its current target (possibly another actor), and fighter.actor refers to the actor for that callback only. Actor callbacks cannot spawn more actors, block player controls, or decide the round outcome. When an actor dies or is dismissed, its projectiles are removed.