Skip to content

fighter

The fighter object is the first argument of every combat callback. Its methods read the fight, change health, move and play moves, and spawn projectiles and actors. Call them with a colon, such as fighter:snapshot(). The object fighter.opponent has a few of the same methods for the other side.

Read the current state of the fight: both fighters’ health, position and animation, plus the fight clock.

Signature: fighter:snapshot()

Returns: A snapshot table, or nil if the fighter cannot be observed.

When: Any combat callback

on_damage_resolving = function(self, fighter, event)
local combat = fighter:snapshot()
if not combat or combat.self.max_health <= 0 then return end
if combat.self.health / combat.self.max_health < 0.25 then
fighter:scale_incoming_damage(0.5)
end
end

The result is a copy; call again after a change. fighter.health is captured when the callback starts and can be stale, so use this for fresh numbers.

Top-level fields:

  • self: the fighter receiving this callback, even when it is the enemy.
  • opponent: its current target (a main fighter or an actor), or nil.
  • frame, seconds: active-fight frames (60 per second) shared by both sides. They skip round transitions and stopped frames, so they are not the round timer; store frame in on_round_begin to time within a round.
  • round_active: whether the round is running.
  • back_wall_distance: how far, in arena units, self stands from the wall behind it (the wall it faces away from). Near 0 means it is pinned against that wall.
  • phase: the fight’s phase, from 1. It stays 1 unless the fight’s round controller changes it with fighter:set_phase.
  • difficulty: { level, ratio } or nil. level is 0 very easy to 4 very hard and is fixed per opponent.

Each fighter entry has health, max_health, health_bars, near_misses and position = { x, y, z }. A normal fighter’s full health is 1; a raid boss’s max_health equals its health_bars (for example 20). Divide by max_health for a fraction, and guard against zero.

An actor’s entry also has an actor table (id, definition, owner, team); see actor snapshots.

animation is nil when nothing readable is playing. Otherwise it has name, type ("none", "move" or "attack"), facing (1 or -1 along model X), frame and intervals, an array of active { name, type } windows. To detect an attack window, look for type == "attack" in combat.opponent.animation.intervals; it does not guarantee a hit.

Near misses. near_misses counts the attacks that came within 50 units of the fighter (edge to edge) and ended without touching it, this fight. Each attack counts once, however long it lasts, and a blocked hit is not a miss. Dodging through an invulnerable move counts too. Compare it with the count you saw last to react to a dodge:

on_tick = function(self, fighter)
local view = fighter:snapshot()
if view and view.self.near_misses > self.state.seen then
self.state.seen = view.self.near_misses
-- the fighter just dodged an attack
end
end

Add to the other fighter’s magic charge.

Signature: fighter.opponent:add_magic_charge(amount)

Parameters

Parameter Type Required
amount number Required

Returns: nil.

When: Check fighter.opponent exists

if fighter.opponent then
fighter.opponent:add_magic_charge(0.1)
end

fighter.opponent has no shield methods and cannot change a hit in progress.

Heal or hurt the other fighter. It works like fighter:change_health.

Signature: fighter.opponent:change_health(amount)

Parameters

Parameter Type Required
amount number Required

Returns: nil.

When: Check fighter.opponent exists

if fighter.opponent then
fighter.opponent:change_health(-0.05)
end

Push the other fighter by a set distance, like fighter:move_by.

Signature: fighter.opponent:move_by(x, y, z?)

Parameters

Parameter Type Required
x number Required
y number Required
z number? Required

Returns: true, nil when queued, or false, reason when refused.

When: Same as fighter:move_by; check fighter.opponent exists

if fighter.opponent then
local accepted, reason = fighter.opponent:move_by(-60, 0, 0)
if not accepted then sf2.log.warn(reason) end
end

The rules of fighter:move_by apply, and the opponent’s queue is shared with other behaviors. Moving both fighters takes two separate calls that are not all-or-nothing. It does not work on actors.

Ask whether the opposing main fighter’s collision shape touches a rectangle.

Signature: fighter.opponent:overlaps_rect(rectangle)

Parameters

Parameter Type Required
rectangle ArenaRect Required

Fields of ArenaRect

Field Type Required Meaning
x number Required Left edge in arena units, -10000 to 10000.
y number Required Y position in arena units, -10000 to 10000. Positive is down.
width number Required Width in arena units, above 0 up to 4000.
height number Required Height in arena units, above 0 up to 4000.

Returns: boolean, nil, or nil, error when unavailable.

When: Offline combat callbacks; check fighter.opponent exists

if fighter.opponent then
local inside, failure = fighter.opponent:overlaps_rect {
x = -160, y = -420, width = 320, height = 440,
}
if inside == nil then sf2.log.warn(failure) end
end

Make the other fighter play one of your registered moves, like fighter:play_move.

Signature: fighter.opponent:play_move(move)

Parameters

Parameter Type Required
move MoveHandle Required

Returns: The same receipt as fighter:play_move.

When: Same as fighter:play_move; check fighter.opponent exists

if fighter.opponent then
local request = fighter.opponent:play_move(reaction)
if request.status == "failed" then sf2.log.warn(request.error) end
end

Everything in fighter:play_move applies, including skipping normal move selection. The opponent’s one-request slot is shared with its own behaviors. It does not work on actors.

Take control of the fight camera.

Signature: fighter:acquire_camera(settings?)

Parameters

Parameter Type Required
settings CameraSettings Optional

Fields of CameraSettings

Field Type Required Meaning
center_x number Optional Camera centre X in arena units, -10000 to 10000. Default follows the duel.
offset_y number Optional Vertical pan, -1000 to 1000; positive raises the view. Default 0.
zoom number Optional Zoom scale, 0.25 to 4. Default is the normal zoom.

Returns: A camera handle, or nil, error if the round is inactive, someone else holds the camera, or this script already has a handle.

When: Active combat callbacks; not fight/round begin or end

local camera
on_tick = function(_, fighter)
if not camera or not sf2.world.is_camera_active(camera) then
local view = fighter:snapshot()
if not view then return end
local failure
camera, failure = fighter:acquire_camera {
center_x = view.self.position.x, offset_y = -40, zoom = 1.3,
}
if failure then sf2.log.warn(failure) end
end
end

You can keep the handle after the callback returns. Another owner is never displaced, so acquiring can fail while a cutscene or other script has the camera.

Read a log of what happened to this mod’s actors, such as spawned, died or expired.

Signature: fighter:actor_events()

Returns: An array of { sequence, actor_id, kind, frame }, or nil, error. Only the latest 64 events are kept.

When: Any combat callback

for _, event in ipairs(fighter:actor_events() or {}) do
if event.sequence > last_sequence then
sf2.log.info(event.kind .. ": " .. event.actor_id)
last_sequence = event.sequence
end
end

kind is spawned, removed, expired, died, owner_changed, round_ended or spawn_failed. Reading does not remove events, so track the last sequence you handled; read too rarely and old events are lost. This is a log, not a notification: use the actor callbacks to react as it happens.

Get this mod’s living actors that this main fighter spawned.

Signature: fighter:actors()

Returns: An ordered array of actor references, or nil, error.

When: Active combat callbacks

for _, actor in ipairs(fighter:actors() or {}) do
local view = actor:snapshot()
if view then sf2.log.info(view.id .. " health=" .. view.health) end
end

References stop working when the callback returns even though the actor lives on, so call again next time. Actors still appearing or leaving, and other mods’ actors, are left out. There is no fighter.opponent:actors; an opponent’s behavior calls its own fighter:actors().

Give a fighter temporary damage reduction against upcoming hits.

Signature: fighter:add_damage_shield(key, fraction, frames)

Parameters

Parameter Type Required
key string Required
fraction number Required
frames integer Required

Returns: nil.

When: Combat callbacks

fighter:add_damage_shield("opening_ward", 0.25, 180) -- 25% less damage for 3 seconds

fraction is the share of damage removed. Reusing a key refreshes that behavior’s shield; different keys stack. The timer pauses with combat and shields clear when the round or fight ends. Remove one early with remove_damage_shield. Shields show no icon; add one with show_status_icon.

Add to a fighter’s magic charge, within the game’s normal limits.

Signature: fighter:add_magic_charge(amount)

Parameters

Parameter Type Required
amount number Required

Returns: nil.

When: Combat callbacks

fighter:add_magic_charge(0.35)

The player needs a usable magic item to see the effect.

Add a fixed amount of damage to the hit this fighter is about to land.

Signature: fighter:add_outgoing_damage(amount)

Parameters

Parameter Type Required
amount number Required

Returns: nil. Raises a Lua error when there is no hit to change.

When: on_damage_dealing, or on_post_hit where event.target == "opponent"

fighter:add_outgoing_damage(0.04)

amount is in health units (1 is a normal fighter’s full health). The defender’s rules and the normal health update still run afterwards. To multiply instead, use scale_outgoing_damage.

Check whether a fighter is currently playing a named move or move template.

Signature: fighter:animation_is(name, who?)

Parameters

Parameter Type Required
name string Required
who "self"|"opponent" Optional

Returns: true or false.

When: Any combat callback

on_tick = function(self, fighter, event)
if fighter:animation_is("Stun", "opponent") then
self.state.chain = self.state.chain + 1
end
end

who is "self" (the default) or "opponent". name matches the move’s own name or any of the template names it belongs to, the same names move conditions use. The check is always false when there is no opponent or nothing is playing.

Turn the fighter into a different character mid-fight, keeping health percentage, position and combat state.

Signature: local request = fighter:change_form(character)

Parameters

Parameter Type Required
character WarriorHandle Required

Returns: A result whose status starts as "queued" and becomes "applied" or "failed" (with an error) at the end of the step.

When: Active combat callbacks

local pending
local behavior = {
on_round_begin = function() pending = nil end,
on_tick = function(_, fighter)
if not pending then
pending = fighter:change_form(second_form) -- a registered fighter
elseif pending.status == "failed" then
sf2.log.warn(pending.error) -- do not retry every frame
end
end,
}

The change happens after the current step. The new character supplies body, equipment and tactic; health percentage, round wins, position, cooldowns, magic charge and ongoing effects carry over. The fight does not restart and an attack in progress does not continue. Living companions stay attached.

queued is not success, so check status. Active stolen magic can make the request fail. For actors see actor:change_form.

Heal or hurt a fighter by a set amount, the way the game changes health normally.

Signature: fighter:change_health(amount)

Parameters

Parameter Type Required
amount number Required

Returns: nil.

When: Any callback

fighter:change_health(0.05)

Positive heals, negative damages. The unit is health, where 1 is a normal fighter’s full health, not a percentage. A fighter already at zero cannot be revived, and healing after on_damage_received does not reverse a lethal hit. A health_bars = 20 raid shield holds 20 units, so -1 removes only one of them.

End the cloak this behavior instance started with set_cloak before its frames run out.

Signature: fighter:clear_cloak()

Returns: nil.

When: Combat callbacks

fighter:clear_cloak()

Switch off a flag this behavior set, the same way a timed flag ends.

Signature: fighter:clear_flag(key)

Parameters

Parameter Type Required
key string Required

Returns: nil. Clearing a flag that is not set does nothing.

When: Active round

fighter:clear_flag("pending")

Clearing a set flag removes it from mod_exists checks and sends the ModExpires event for its full name, which a move can listen for with events = { { type = "mod_expires", name = "example.spell:behaviors/cast:pending" } }. The move’s conditions still decide whether it runs. If no move needs to react, use declared behavior state instead of a flag.

Remove a charge meter shown with set_meter.

Signature: fighter:clear_meter(key)

Parameters

Parameter Type Required
key string Required

Returns: nil.

When: Combat callbacks, on the player or the opponent

fighter:clear_meter("focus")

The meter fades out over a quarter of a second. Calling fighter:set_meter with the same key while it fades brings it back. Clearing a key that is not showing does nothing.

Remove the tint this behavior instance set with set_model_color before its frames run out.

Signature: fighter:clear_model_color()

Returns: nil.

When: Combat callbacks

fighter:clear_model_color()

Remove a status icon this behavior showed earlier.

Signature: fighter:clear_status_icon(key)

Parameters

Parameter Type Required
key string Required

Returns: nil.

When: Combat callbacks

fighter:clear_status_icon("relentless")

Cannot remove icons other code added.

Count the debuffs currently showing on a fighter.

Signature: fighter:debuff_count(who?)

Parameters

Parameter Type Required
who "self"|"opponent" Optional

Returns: A whole number, 0 when there are none.

When: Any combat callback

on_damage_dealing = function(parameters, fighter, event)
fighter:scale_outgoing_damage(1 + 0.1 * fighter:debuff_count())
end

who is "opponent" (the default) or "self". A debuff is a status icon sitting on that fighter whose image name ends in _Red: the red icons the game shows for effects such as bleeding and stun, and any icon you show with fighter:show_status_icon using a sprite named that way.

Ask the game to end the current round as a player win or loss.

Signature: fighter:end_round(outcome) -> boolean, string?

Parameters

Parameter Type Required
outcome "win"|"loss" Required

Returns: true, nil when queued, or false, reason when refused.

When: The controller’s own rule, normally on_tick

if self.state.score >= 10 then
local accepted, reason = fighter:end_round("win")
if not accepted then sf2.log.warn(reason) end
end

outcome is "win" or "loss" and always describes the player, even when called from an opponent’s callback.

The request settles at the end of the step: a knockout, timeout or other built-in end condition wins over it, and a player surrender discards it. Otherwise the round ends with the usual score, results and rewards; nobody is killed or healed. Repeating the same result does nothing; asking for the opposite returns false.

Make the hit in progress shock the fighter it lands on, even through anti-shock perks.

Signature: fighter:force_hit_shock { disarm?, weapon_returns_after? }

Parameters

Parameter Type Required
options ForceHitShockOptions Optional

Fields of ForceHitShockOptions

Field Type Required Meaning
disarm boolean Optional Also knock the weapon away. Default true.
weapon_returns_after integer Optional Frames, 1 to 3600, after the weapon comes off until it returns. Default: it stays off. Needs disarm.

Returns: nil.

When: Only inside on_post_hit, when this fighter is the attacker

on_post_hit = function(parameters, fighter, event)
if event.target == "opponent" and event.weapon and not event.blocked then
fighter:force_hit_shock { weapon_returns_after = 300 }
end
end
Option Required Default Meaning
disarm No true Whether the shock also knocks the weapon away.
weapon_returns_after No Stays off Frames (1 to 3600) after the weapon comes off until it returns. Sixty frames is one second. Needs disarm.

The call overrides perks that block shock, since those have already run by this point. A fighter whose hit is armored by fighter:set_hit_armored is still not shocked. A fighter already in shock is not shocked again, and a fighter that has already lost its weapon does not lose it a second time.

When weapon_returns_after runs out, the weapon fades out where it lies and fades back in in the fighter’s hand. If the fighter is in a knockdown at that moment, the weapon waits, faded out, until the fighter has recovered. The perks on the weapon can fire again from then on. Effects the weapon’s perks had already applied, which ended when it was knocked away, do not come back until the next round.

Also receive the hits landed by the actors this behavior owns.

Signature: fighter:forward_actor_hits(enabled)

Parameters

Parameter Type Required
enabled boolean Required

Returns: nil.

When: Combat callbacks, on the player or the opponent

on_fight_begin = function(parameters, fighter, event)
fighter:forward_actor_hits(true)
end,
on_post_hit = function(parameters, fighter, event)
if event.attack and event.attack.actor_id then
fighter:scale_outgoing_damage(1.5)
end
end

Hits landed by an actor normally reach only the actor’s own behavior. After this call, this behavior’s on_post_hit and on_damage_dealing also run for hits made by actors its mod owns, with event.target set to "opponent" and event.attack.actor_id naming the actor. Inside those calls fighter:scale_outgoing_damage and fighter:add_outgoing_damage change that hit.

It is off until you ask for it and stays on until the end of the fight. The other callbacks still fire only for the actor.

Check whether this behavior has a flag switched on, without changing it.

Signature: fighter:has_flag(key)

Parameters

Parameter Type Required
key string Required

Returns: true if this behavior has the flag, else false.

When: Combat callbacks

if fighter:has_flag("pending") then
sf2.log.info("This cast still owns its pending flag")
end

Only sees this behavior’s own flags; see set_flag.

Check whether a fighter has a perk active right now.

Signature: fighter:has_perk(perk, who?)

Parameters

Parameter Type Required
perk string|PerkHandle Required
who "self"|"opponent" Optional

Returns: true or false.

When: Any combat callback

on_hit_pre_crit = function(parameters, fighter, event)
if fighter:has_perk("PERK_ANTI_SHOCK", "opponent") then
fighter:set_hit_blocked(false)
end
end

perk is a core perk name such as "PERK_ANTI_SHOCK", a qualified ID such as "core:perks/PERK_ANTI_SHOCK" or "example.mod:perks/guard", or a perk handle. who is "self" (the default) or "opponent".

A perk is active when the fighter has it in the current round and nothing has switched it off: a weapon perk lost to a disarm does not count, and neither does one silenced with fighter:set_perk_disabled.

Draw a filled rectangle in the arena that stays put as fighters move, or one that rides on a fighter’s body.

Signature: fighter:mark_rect(rectangle, color?)

Parameters

Parameter Type Required
rectangle ArenaMarkerRect Required
color string? Required

Fields of ArenaMarkerRect

Field Type Required Meaning
x number Required Left edge in arena units, -10000 to 10000.
y number Required Y position in arena units, -10000 to 10000. Positive is down.
width number Required Width in arena units, above 0 up to 4000.
height number Required Height in arena units, above 0 up to 4000.
node string Optional A body point such as “chest”, or an exact rig node name, for the marker to follow. x and y are then measured from it.
of "self"|"enemy" Optional Whose node: this fighter or the other main fighter. Default “self”. Needs node.

Returns: A marker handle, or nil, error when the round is unavailable or you are out of markers.

When: Active simulation callbacks such as on_tick

if not marker then
marker = assert(fighter:mark_rect {
x = -160, y = -420, width = 320, height = 440,
})
end

The default color is translucent yellow. The marker lasts through the current round; keep the handle in a Lua variable (not saved state) to move, recolor or remove it.

A rectangle with a node (and optionally of = "enemy") follows that part of a fighter’s body instead, with x and y measured from the node, as for fighter:mark_sprite.

Draw a sprite in the arena, or on a fighter’s body. Sprite and rectangle markers share the same limits.

Signature: fighter:mark_sprite(sprite, rectangle, color?)

Parameters

Parameter Type Required
sprite SpriteHandle Required
rectangle ArenaMarkerRect Required
color string? Required

Fields of ArenaMarkerRect

Field Type Required Meaning
x number Required Left edge in arena units, -10000 to 10000.
y number Required Y position in arena units, -10000 to 10000. Positive is down.
width number Required Width in arena units, above 0 up to 4000.
height number Required Height in arena units, above 0 up to 4000.
node string Optional A body point such as “chest”, or an exact rig node name, for the marker to follow. x and y are then measured from it.
of "self"|"enemy" Optional Whose node: this fighter or the other main fighter. Default “self”. Needs node.

Returns: A marker handle, or nil, error when the sprite or round is unavailable or you are out of markers.

When: Active simulation callbacks such as on_tick

local warning = sf2.assets.sprite("sprites/warning") -- at load time
-- inside on_tick:
marker = assert(fighter:mark_sprite(warning, {
x = -160, y = -420, width = 320, height = 440,
}, "#ffcc3399"))

Use a descriptor from sf2.assets.sprite; a PNG texture ID is not a sprite ID. The default tint is opaque white and multiplies the sprite’s pixels. The marker is art only, with no collider or damage. It lasts until removed or the round ends; keep the handle in a Lua variable, not saved state.

To stick the sprite to a fighter’s body, add node to the rectangle: a body point (see Body points in the move reference) such as "chest", or an exact rig node name. x and y are then measured from that node, and the marker moves with it every drawn frame, smoothly, through jumps and knockdowns. of picks whose node: "self" (the default) or "enemy", the other main fighter.

local spark = sf2.assets.sprite("sprites/spark") -- at load time
-- inside on_tick: a 24-unit spark centred on the enemy's chest
local mark = fighter:mark_sprite(spark, {
node = "chest", of = "enemy", x = -12, y = -12, width = 24, height = 24,
})

A marker keeps the node it was made with. sf2.world.try_set_marker can still change its rectangle, measured from the same node; to follow another node, remove the marker and make a new one. The marker is hidden while the node is missing.

Push the fighter sideways, up or down by a set distance, for example for a dash or knock-up.

Signature: fighter:move_by(x, y, z?)

Parameters

Parameter Type Required
x number Required
y number Required
z number? Required

Returns: true, nil when queued, or false, reason when refused.

When: Simulation callbacks in offline fights; not fight/round begin or end

local accepted, reason = fighter:move_by(80, 0)
if not accepted then sf2.log.warn(reason) end

The values are offsets from the current position, not destinations or speeds. Positive X does not depend on facing (multiply by facing for a forward dash) and positive Y is down, so negative Y moves up. The move is queued, so a snapshot in the same callback does not show it yet.

Requests for a fighter add together and apply once per step. The whole rig moves, walls and floors can still correct the position, and nothing is hit along the way. The shift keeps the fighter’s own motion, so a small push every step (a wind) does not stop a fighter who is flying or falling: they still land. Queued motion is dropped if the round ends or the fighter dies. See Moves.

Ask whether this fighter’s collision shape touches a rectangle.

Signature: fighter:overlaps_rect(rectangle)

Parameters

Parameter Type Required
rectangle ArenaRect Required

Fields of ArenaRect

Field Type Required Meaning
x number Required Left edge in arena units, -10000 to 10000.
y number Required Y position in arena units, -10000 to 10000. Positive is down.
width number Required Width in arena units, above 0 up to 4000.
height number Required Height in arena units, above 0 up to 4000.

Returns: boolean, nil, or nil, error when geometry is unavailable. false means no overlap; nil means the query failed.

When: Offline combat callbacks

local region = { x = -160, y = -420, width = 320, height = 440 }
local inside, failure = fighter:overlaps_rect(region)
if inside == nil then sf2.log.warn(failure)
elseif inside then sf2.log.info("Inside the column") end

The rectangle uses the same coordinates as fighter:mark_rect.

Make the fighter play one of your registered moves right now, for example when an ability activates.

Signature: fighter:play_move(move)

Parameters

Parameter Type Required
move MoveHandle Required

Returns: A receipt with status ("queued", "applied" or "failed") and an optional error. applied means the move started, not that it hit.

When: Simulation callbacks in offline rounds; not fight/round begin or end

-- strike is a move handle registered while loading.
local request = fighter:play_move(strike)
if request.status == "failed" then sf2.log.warn(request.error) end

This plays the named move directly. It skips normal move selection, so conditions, key bindings, priorities and control restrictions are ignored, and it can interrupt the current animation. Handle cost and cooldown in Lua, and put attack windows and damage in the move definition. See Moves.

Only one request per fighter can wait per step, across all mods; later ones get a failed receipt. The move starts later in the same step, so a snapshot taken right after still shows the old animation. A death or round end turns a pending request into failed.

Hold the fight while a seal picture cracks and shatters in the middle of the screen, then let the fight go on by itself.

Signature: fighter:play_seal_break(sprite, seconds?) -> boolean, string?

Parameters

Parameter Type Required
sprite SpriteHandle Required
seconds number Optional

Returns: true, nil when the effect started, or false, reason when refused.

When: The controller’s own rule while a round is being fought, normally on_tick; not in on_fight_begin, on_round_begin, on_round_end or on_fight_end

local seal = sf2.assets.sprite("ui/seal_arkhos")
local seals = {
on_tick = function(self, fighter, tick)
local combat = fighter:snapshot()
if not combat then return end
if combat.phase == 1 and combat.opponent.health <= 22 then
fighter:set_phase(2)
fighter:play_seal_break(seal) -- the fight waits about 2.4 seconds
end
end,
}

The fight holds still exactly as under the pause menu while the effect plays: fighters, the round timer, the AI and every fight callback stop. The fight darkens for a beat, then the sprite slams into the middle of the screen and lands with a ring of dust. Three blows shake it, throw sparks and small chips from the point struck and spread cracks across it. Light leaks through the cracks while it trembles, then it bursts: the pieces fly apart, hang tumbling for a moment and fall away, behind a shockwave, rays of light and a spray of sparks, with the game’s hit sounds, a shattering of glass and a gong. Then the dimming lifts and the fight resumes by itself; your controller simply carries on at its next on_tick.

sprite is a sprite handle or ID, such as a seal’s artwork. seconds is how long the whole effect lasts, from 0.6 to 4; it defaults to 2.4. Everything in it keeps its proportions, so a shorter break is simply quicker. The pieces are cut from the sprite itself, so any picture works and no extra art is needed.

Only the fight’s round controller (a behavior rule with controls_outcome = true) can play it; any other rule gets false, reason. It is also refused when another seal break is still playing, between rounds, once the fight is over, or when the sprite cannot be loaded. Versus fights have no round controller.

Shaking follows the player’s hit-shake accessibility setting. The effect draws only while it plays; nothing stays on screen during normal fighting. See Battle rules for a boss whose seals break one after another.

Get this mod’s live projectiles for the callback’s fighter.

Signature: fighter:projectiles()

Returns: An array of projectile references in spawn order (empty when none), or nil, error.

When: Active simulation callbacks

for _, projectile in ipairs(fighter:projectiles() or {}) do
local view = projectile:snapshot()
if view then sf2.log.info(view.name .. " at " .. view.position.x) end
end

References stop working when the callback returns, so query again each time. Projectiles still being created or removed are left out. From an actor’s behavior this returns only that actor’s own projectiles. Spawn them with fighter:spawn_projectile.

Remove a shield this behavior added earlier with add_damage_shield.

Signature: fighter:remove_damage_shield(key)

Parameters

Parameter Type Required
key string Required

Returns: nil.

When: Combat callbacks

fighter:remove_damage_shield("opening_ward")

Only removes shields this behavior added.

Reduce the damage of the hit this fighter is about to take, before it is applied.

Signature: fighter:scale_incoming_damage(multiplier)

Parameters

Parameter Type Required
multiplier number Required

Returns: nil.

When: Only inside on_damage_resolving

fighter:scale_incoming_damage(0.5)

0 prevents this hit’s damage and 0.5 halves it; values above 1 are rejected. Several behaviors multiply in callback order. Damage is final after resolving.

Make the hit this fighter is about to land stronger or weaker by multiplying its damage.

Signature: fighter:scale_outgoing_damage(multiplier)

Parameters

Parameter Type Required
multiplier number Required

Returns: nil. Raises a Lua error when there is no hit to change.

When: on_damage_dealing, or on_post_hit where event.target == "opponent"

on_damage_dealing = function(parameters, fighter, event)
fighter:scale_outgoing_damage(1.25)
end

Each call multiplies the current value, and zero stays zero. Invulnerability, shields and the defender’s modifiers apply afterwards, so this does not bypass defense.

Make a computer-controlled fighter stand and wait: it starts no new move until released.

Signature: fighter:set_ai_held(held)

Parameters

Parameter Type Required
held boolean Required

Returns: nil.

When: Combat callbacks while a round is running

-- On the boss: a three-second breather each time a quarter of his health is gone.
local last_quarter, rest_until = nil, nil
local breather = {
on_tick = function(parameters, fighter, event)
local combat = fighter:snapshot()
if not combat or combat.self.max_health <= 0 then return end
local quarter = math.floor(combat.self.health / combat.self.max_health * 4)
if last_quarter and quarter < last_quarter then
rest_until = event.frame + 180
fighter:set_ai_held(true)
elseif rest_until and event.frame >= rest_until then
rest_until = nil
fighter:set_ai_held(false)
end
last_quarter = quarter
end,
}

While held, the fighter’s AI picks nothing: no attack, block, step or ability, whether its tactic is one of the game’s or has its own on_decide. A move already playing finishes, then the fighter stands. Hits still land on it and it still reacts to them; pair the hold with fighter:scale_incoming_damage or fighter:set_hit_armored if it should not be hurt or knocked about.

The hold applies to this fighter only, so the behavior must run on the computer-controlled side (an opponent’s behavior rule, target = "opponent"). On the player it does nothing, since the player has no AI to hold.

Each behavior holds its own claim: the fighter acts again once every behavior that held it has passed false. All holds end when the round resets, and a hold stays with the fighter when it changes form.

Add to one of this fighter’s attributes until the round resets.

Signature: fighter:set_attribute_bonus(attribute, amount)

Parameters

Parameter Type Required
attribute string Required
amount integer Required

Returns: nil.

When: Combat callbacks while a round is running

on_combo_changed = function(parameters, fighter, event)
fighter:set_attribute_bonus("WeaponDamage", event.combo * 5)
end

attribute is an attribute name such as "WeaponDamage", the same names attributes rules use. amount is a whole number from -1000000 to 1000000.

Each call replaces this behavior’s previous bonus for that attribute rather than adding to it, so call it as often as you like; pass 0 to remove the bonus. Bonuses from other behaviors stack alongside. They last until the round resets, so set them again in on_round_begin to keep them, and they follow the fighter through a form change.

Show a recharge animation on a combat button so the player sees an ability cooling down.

Signature: fighter:set_button_cooldown(control, frames)

Parameters

Parameter Type Required
control "punch"|"kick"|"ranged"|"raid_charge" Required
frames integer Required

Returns: nil.

When: Combat callbacks during an active round

on_animation_start = function(self, fighter, event)
if event.target == "self" and event.animation_name == "SummonAssistant" then
fighter:set_button_cooldown("raid_charge", 600)
end
end,

control cannot be "magic", whose ring follows the charge. frames is 1 to 3600 (60 frames are a second), or 0 to empty the ring and keep it empty until the next call, for an ability that waits on something else, such as a summoned helper leaving:

fighter:set_button_cooldown("raid_charge", 0) -- empty while the helper fights
-- later, when it leaves:
fighter:set_button_cooldown("raid_charge", 600) -- the real recharge starts

A cooldown only changes what the button shows and does not stop the move being used; to prevent that, set a timed flag and put a not_mod condition on the move. Only the player’s buttons are drawn.

Turn this fighter into refracting glass for a number of frames, for invisibility and stealth abilities.

Signature: fighter:set_cloak(frames)

Parameters

Parameter Type Required
frames integer Required

Returns: nil.

When: Combat callbacks during an active round

fighter:set_cloak(650) -- glass for about 11 seconds

The stage shows through the body, blurred and bent, with a bright rim; the whole body is drawn as one shape. A fully transparent set_model_color hides the fighter outright instead. The cloak flashes when it appears and when the fighter lands a hit.

Each behavior has one cloak, and calling again restarts its timer. It ends when the frames run out, on clear_cloak or when the round resets. It is visual only: pair it with set_hit_blocked if it should change gameplay.

Stop the player from using one action button, for example to disable magic during a fight.

Signature: fighter:set_control_blocked(control, blocked)

Parameters

Parameter Type Required
control "punch"|"kick"|"ranged"|"magic"|"raid_charge" Required
blocked boolean Required

Returns: nil.

When: Player behavior callbacks during an active round, including on_fight_begin and on_round_begin

local restriction = {
on_round_begin = function(parameters, fighter)
fighter:set_control_blocked("magic", true)
end,
}

true hides the button and blocks the action on touch, keyboard and gamepad; a held action is released. false removes only this behavior’s own restriction, not another behavior’s or the game’s. Restrictions clear when the next round is prepared, so set them again in on_round_begin. It does nothing for opponents.

Let the player pick a direction when using a combat button.

Signature: fighter:set_control_directions(control, directions)

Parameters

Parameter Type Required
control "raid_charge" Required
directions ("up"|"right"|"down"|"left")[]|nil Required

Returns: nil.

When: Combat callbacks; does nothing unless this fighter is the player

on_round_begin = function(parameters, fighter, event)
fighter:set_control_directions("raid_charge", { "up", "right", "down", "left" })
end

control is currently "raid_charge", the only button that can pick a direction. directions lists up to four of "up", "right", "down" and "left"; the player drags across the button to choose one, and a tap with no drag picks the first in the list. On a keyboard the player holds the raid charge key and presses a movement key, and on a controller holds the raid button and presses the d-pad; those keys do not move the fighter while the raid input is held. Letting go without pressing a direction picks the first in the list. Pass nil to remove the directions from the button.

The choice arrives in on_control_direction. Directions are removed when the fight ends. On any fighter except the player, this call has no effect.

Show the RaidCharge button in a fight that would normally hide it.

Signature: fighter:set_control_visible(control, visible)

Parameters

Parameter Type Required
control "raid_charge" Required
visible boolean Required

Returns: nil.

When: Combat callbacks during an active round; for the player also on_fight_begin and on_round_begin

on_round_begin = function(self, fighter, event)
fighter:set_control_visible("raid_charge", true)
end,

Only "raid_charge" is supported. The button shows no charge count, and a control restriction still hides it. It only affects the player’s button; called for an opponent it does nothing.

Each round starts with the game’s own visibility, so show the button again in every round. Calling it from on_round_begin shows it from the start of the round, through the round intro and the fighters’ opening stances. Called later (for example from on_tick), it appears only once the fight starts. The next fight also starts with the game’s own visibility.

Mirror the player’s movement controls for a while, like the inverted-joystick rule, then give them back.

Signature: fighter:set_controls_inverted(inverted)

Parameters

Parameter Type Required
inverted boolean Required

Returns: nil.

When: Player behavior callbacks while a round is running

-- On the player: controls flip for four seconds out of every ten.
local hex = {
on_tick = function(parameters, fighter, event)
local cycle = event.frame % 600
fighter:set_controls_inverted(cycle < 240)
end,
}

While inverted, every direction the player presses is mirrored, exactly as under the invert_joystick rule. Combat buttons are not affected. Unlike that rule, this can switch on and off at any moment of a round.

It works on the player only, so the behavior must run on the player’s side (target = "player"). Calling it for an opponent, or in Local Versus, is an error.

Each behavior holds its own claim: the controls stay mirrored until every behavior that inverted them has passed false, and an invert_joystick rule that is on keeps them mirrored either way. All claims end when the round resets. Release your claim yourself when your effect ends, for example when a fight phase changes, because a behavior gets no callback for that.

Switch on a named flag for this behavior that move conditions can test, optionally expiring after a set time.

Signature: fighter:set_flag(key, frames?)

Parameters

Parameter Type Required
key string Required
frames integer Optional

Returns: The full flag name as a string.

When: Combat callbacks during an active round

on_animation_start = function(parameters, fighter, event)
if event.target == "self"
and event.animation_name == sf2.mod.id .. ":moves/cast" then
fighter:set_flag("pending")
end
end,

The full name is <full behavior ID>:<key>, for example example.spell:behaviors/cast:pending; move conditions (mod_exists) match that full name.

Without frames the flag lasts until cleared or the round or fight ends. Setting a flag that is already active does nothing, even with a new duration, so clear it first to restart a timer:

fighter:clear_flag("cooldown")
fighter:set_flag("cooldown", 600) -- ten seconds

A flag belongs to one behavior instance; another instance cannot read or clear it, even with the same key. Built-in flags such as Stun cannot be set. Flags are not saved but survive a form change.

Let this fighter take the hit without flinching or being knocked back.

Signature: fighter:set_hit_armored(armored)

Parameters

Parameter Type Required
armored boolean Required

Returns: nil.

When: Only inside on_hit_pre_crit, when this fighter is the one being hit

on_hit_pre_crit = function(parameters, fighter, event)
if event.target == "self" and not event.blocked then
fighter:set_hit_armored(true)
end
end

The hit still deals its damage, but the fighter keeps playing its current move. There is no hit reaction and no knockback, and the hit cannot shock or disarm this fighter, even if the attacker tries to force it with fighter:force_hit_shock.

A hit that would knock the fighter out ignores armor, so the knockout still plays. Pass false to take back an earlier call from the same hit. Calling it when this fighter is the attacker raises an error, so check event.target first.

Decide whether the hit in progress counts as blocked, for unblockable attacks or guards that stop a hit.

Signature: fighter:set_hit_blocked(blocked)

Parameters

Parameter Type Required
blocked boolean Required

Returns: nil.

When: Only inside on_hit_pre_crit

if event.target == "opponent" and event.blocked then
fighter:set_hit_blocked(false)
end

The critical roll and damage are calculated after your decision, so an unblocked hit can crit and deals full damage. If several handlers call it the last one wins, and later handlers see the result in event.blocked.

Make the hit in progress critical, or stop it from being critical.

Signature: fighter:set_hit_critical(critical)

Parameters

Parameter Type Required
critical boolean Required

Returns: nil.

When: Only inside on_hit_post_crit, when this fighter is the attacker

on_hit_post_crit = function(parameters, fighter, event)
if event.target == "opponent" and event.ranged then
fighter:set_hit_critical(true)
end
end

Damage is worked out after this call, so a critical you switch on here deals critical damage. It runs after the critical roll, so it also overrides a roll that already came up critical when you pass false.

A blocked hit and an attack that can never be critical stay non-critical; passing true for those does nothing. If several handlers call this, the last one wins, and later handlers see the result in event.critical.

Choose which reaction this hit plays on the fighter it lands on.

Signature: fighter:set_hit_reaction(name)

Parameters

Parameter Type Required
name string|nil Required

Returns: nil.

When: Only inside on_hit_pre_crit, on either fighter

on_hit_pre_crit = function(parameters, fighter, event)
if event.target == "opponent" and event.unarmed then
fighter:set_hit_reaction("RootHit")
end
end

name is a reaction name from a move’s hit event, such as the one a moveset listens for. The fighter being hit then picks its reaction move as though the attack had named that reaction.

Pass nil to go back to the attack’s own reaction. If no move answers the name, the fighter falls back to a move with no name of its own. If several handlers call this, the last one wins. fighter:set_hit_armored cancels the reaction altogether.

Let strikes and throws pass through this fighter until released, as they do through a get-up’s invulnerable frames.

Signature: fighter:set_invulnerable(invulnerable)

Parameters

Parameter Type Required
invulnerable boolean Required

Returns: nil.

When: Combat callbacks while a round is running

-- On a boss: while he gathers himself between stages, nothing touches him.
local resting = false
local breather = {
on_tick = function(parameters, fighter, event)
local rest = parameters.rest_until and event.frame < parameters.rest_until
if rest ~= resting then
resting = rest
fighter:set_ai_held(rest)
fighter:set_invulnerable(rest)
end
end,
}

While it lasts, the fighter carries the same invulnerable window that a get-up or an evade has in its frames, whatever move it is playing. Attacks pass through it: there is no hit, no damage, no hit reaction and no spark, it cannot be grabbed by a throw, and a blade cannot clash with it. The attacker’s move simply plays on, as against empty air.

An attack made to ignore invulnerable windows (a move’s ignores_invulnerable) still lands. If the fighter must not be hurt at all, pair this with fighter:scale_incoming_damage and fighter:set_hit_armored in the same behavior.

It works on either main fighter. Each behavior holds its own claim: the fighter can be hit again once every behavior that made it invulnerable has passed false. It all ends when the round resets, and it stays with the fighter when it changes form.

Show a charge or stack meter for this fighter at the foot of the screen.

Signature: fighter:set_meter(key, { value, segments?, color?, label? })

Parameters

Parameter Type Required
key string Required
options FightMeterOptions Required

Fields of FightMeterOptions

Field Type Required Meaning
value number Required How full the meter is, 0 to 1.
segments integer Optional Splits the meter into this many separate cells, 1 to 8, filled one after another from the outer end. Default 1.
color string Optional Fill color as #RRGGBB or #RRGGBBAA. Default #FFFFFF.
label string Optional Short text over the bar, up to 12 characters, such as a stack count (“3/5”).

Returns: nil.

When: Combat callbacks, on the player or the opponent

on_tick = function(self, fighter, event)
fighter:set_meter("focus", { value = self.state.focus, segments = 4, color = "#35C0FF" })
end

key names the meter and is kept separate per behavior, so call this again with the same key to update it and use fighter:clear_meter to remove it. Meters are cleared when the round resets and when the fight ends, so set them again in each round. Actors cannot show meters.

Meters sit on the dark floor band at the foot of the screen, between the movement stick and the action buttons: the player’s left of the centre, filling toward it, and the opponent’s mirrored on the right. A fighter’s second meter stacks above its first. Each cell is drawn like the bars of the lacquer HUD (sf2.fx.ink_hud): a black plate in a gold frame with a glossy fill in color, whether or not a mod turns that HUD on.

A meter is part of the fight HUD. It is hidden with the rest of the HUD between rounds, fades with it whenever an effect such as the knockout close-up fades the HUD, and sits under the pause menu’s dimming and the round banners. It fades in when it first appears.

A label is written above the bar. A fighter’s second meter stacks where the first one’s label would sit, so give a label only to a fighter’s single meter.

Counting with cells. For stacks or charges, give one cell per stack: segments = 5 with value = stacks / 5 shows five cells, each one lit or empty, so the count reads at a glance without a label.

Movement. You can set the meter on every tick. The fill moves smoothly to each new value. A sudden drop leaves a pale trail that drains away after a moment. A cell flashes and grows briefly as it fills, and flashes and shrinks as it empties. The whole bar pulses once when it becomes full.

You do not need to clear a meter in on_round_end. If you leave it, it stays until the HUD hides for the next round, as the health bars do.

Tint this fighter’s whole model, weapons included, for a number of frames. A fully transparent colour (alpha 00) hides the fighter.

Signature: fighter:set_model_color(color, frames)

Parameters

Parameter Type Required
color string Required
frames integer Required

Returns: nil.

When: Combat callbacks during an active round

fighter:set_model_color("#FF5A3C", 10) -- a short red flash
-- or hide the fighter for about 2 seconds:
-- fighter:set_model_color("#FFFFFF00", 120)

color is #RRGGBB or #RRGGBBAA. It replaces the fighter’s own ink colour, weapons included, so #FFFFFF paints the fighter white.

The alpha (the last two digits) controls visibility. At 00 the tint hides the fighter and the weapons it holds, the way the game’s own invisibility does, until the tint ends. Between 01 and FE only the fighter’s limbs fade, while its clothing and other solid parts keep the colour at full strength; for an even see-through look use set_cloak.

Each behavior has one tint; calling again replaces it and restarts the timer. Setting the same transparent tint again every tick keeps the fighter hidden without it reappearing in between. A tint ends when the frames run out, on clear_model_color or when the round resets, and the most recent tint shows. It is visual only: the opponent’s AI still sees the fighter.

List short lines, each with an optional picture, under the rule text on the fight’s pause screen.

Signature: fighter:set_pause_notes(notes)

Parameters

Parameter Type Required
notes PauseNote[]|nil Required

Fields of PauseNote

Field Type Required Meaning
text string|LocalizationHandle Required The line: a text handle from sf2.text.get (shown in the player’s language) or a string shown as written, up to 200 characters.
icon string|SpriteHandle Optional A picture drawn at the left of the line. Default: none.

Returns: nil.

When: Combat callbacks while the fight is running; clearing works at any time

local sf2 = require("sf2")
-- While the mod loads: text and pictures cannot be fetched during a fight.
local cursed = sf2.text.get("my_mod:localization/curse_note") -- "Cursed: every hit you take burns."
local skull = sf2.assets.sprite("ui/skull")
local curse = {
on_fight_begin = function(parameters, fighter)
fighter:set_pause_notes({
{ text = "Curses on: +25% rewards" }, -- a plain string, shown as written
{ text = cursed, icon = skull }, -- a text handle, in the player's language
})
end,
on_fight_end = function(parameters, fighter)
fighter:set_pause_notes(nil)
end,
}

notes is a list of up to 6 tables. Each has:

  • text (required): a text handle from sf2.text.get or sf2.text.register, shown in the player’s language, or a string, shown exactly as written (up to 200 characters).
  • icon (optional): a sprite handle or sprite ID, drawn at the left of the line. Without one the line starts at the left edge of the list, which suits a heading.

Pass nil or an empty list to remove the behavior’s notes. Each call replaces everything this behavior listed before.

How they show:

  • The lines sit under the fight’s rule text (the description of its rules) in the same gold lettering at a smaller size, one row per note, and fade in with it. Without a rule text they sit straight under the buttons. Nothing is shown while no behavior has notes.
  • The list is built when the pause screen opens, so a change made while it is open shows the next time the game is paused.
  • If the lines would not fit on the screen, the rule text gives up its empty space and the gaps between the pause screen’s parts close up first; only then do the rows get shorter. A line too long for the screen wraps and its text shrinks to fit.

Notes are shared by the whole fight: any fighter’s behavior can set them, and the opponent’s notes show on the same pause screen. Each behavior keeps its own notes, listed in the order the behaviors first set them, up to 8 lines in total. They last through rounds and phases until the behavior clears them or the fight ends; set them again whenever what they describe changes, such as when a stage of a phased fight begins.

Stop one of a fighter’s perks from triggering for the rest of the round.

Signature: fighter:set_perk_disabled(perk, disabled)

Parameters

Parameter Type Required
perk string|PerkHandle Required
disabled boolean Required

Returns: nil.

When: Combat callbacks while a round is running

on_round_begin = function(parameters, fighter, event)
fighter:set_perk_disabled("PERK_ANTI_SHOCK", true)
end

perk takes the same names as fighter:has_perk. This applies to this fighter only, so to silence a perk on the other side the behavior must run on that fighter. While disabled, the perk’s triggers do not run; effects it already started keep going until they end.

Each behavior holds its own claim: the perk fires again once every behavior that disabled it has passed false, and all claims end when the round resets.

Pause every perk effect on this fighter: timers stop and nothing changes its health over time until released.

Signature: fighter:set_perk_effects_frozen(frozen)

Parameters

Parameter Type Required
frozen boolean Required

Returns: nil.

When: Combat callbacks while a round is running

-- On a boss: while he gathers himself between stages, a curse or bleed on him waits too.
local resting = false
local breather = {
on_tick = function(parameters, fighter, event)
local rest = parameters.rest_until and event.frame < parameters.rest_until
if rest ~= resting then
resting = rest
fighter:set_ai_held(rest)
fighter:set_perk_effects_frozen(rest)
end
end,
}

While frozen, every perk effect on this fighter keeps its time left: flags, icons, attribute changes and other timed effects stop counting down, whoever’s perk put them there. Health changes from perks and from the regeneration attribute stop too, in both directions, so a damage-over-time curse or bleed deals nothing and a heal over time gives nothing. When the freeze ends, every effect carries on from where it stopped, so a curse keeps its level and the time it had left.

New effects can still be added while frozen; they wait too. An effect that a perk ends outright still ends. The freeze changes only this fighter: effects on its opponent keep running.

Each behavior holds its own claim: the effects run again once every behavior that froze them has passed false. All freezes end when the round resets, and a freeze stays with the fighter when it changes form.

Move the fight to another phase, so the battle rules limited to that phase switch on and the others switch off.

Signature: fighter:set_phase(phase) -> boolean, string?

Parameters

Parameter Type Required
phase integer Required

Returns: true, nil when accepted, or false, reason when refused.

When: The controller’s own rule, normally on_tick; not in on_round_end or on_fight_end

local seals = {
on_tick = function(self, fighter, tick)
local combat = fighter:snapshot()
if not combat then return end
local boss = combat.opponent
if combat.phase == 1 and boss.health <= 20 then
fighter:set_phase(2)
elseif combat.phase == 2 and boss.health <= 10 then
fighter:set_phase(3)
end
end,
}

Only the fight’s round controller (a behavior rule with controls_outcome = true) can change the phase; any other rule gets false, reason. phase is a whole number from 1 to 100, and every fight starts at 1.

Asked for in on_fight_begin or on_round_begin, the change is made at once and the round starts in the new phase, for example to resume a boss at a later stage. Asked for while the round is running, it takes effect at the end of the current step. Then:

  • battle rules with phases switch on or off to match, without restarting the round: hot ground, ring out, regeneration, attributes, remove interval, no health bar, invert joystick, random area, light in the darkness, no button, no animation, perk and no perks rules all follow;
  • behavior rules with phases start or stop receiving callbacks;
  • if the fight’s rule text changes during the round, the new text is shown as a banner (the one an Underworld fight shows when a round starts); the pause screen and the next round’s banner always show the current text.

The phase lasts for the rest of the fight, across rounds, until the controller changes it again. Asked for after the round has ended (from a callback that still runs then), it changes once the next round is being fought. Asking twice in one step keeps the last request. Read the current phase from fighter:snapshot as phase. Versus fights have no phases.

See Battle rules for a whole boss built on phases.

Raise the coins, gems, experience and forge materials the player earns if this fight is won, for example as a bonus for a clean run.

Signature: fighter:set_reward_bonus(fraction) -> boolean, string?

Parameters

Parameter Type Required
fraction number Required

Returns: true, nil when accepted, or false, reason when refused.

When: Any callback of the fight’s round controller, up to and including on_fight_end

local momentum = {
state = { lifetime = "fight", fields = { clean = 0 } },
on_tick = function(self, fighter, tick)
-- ... count self.state.clean as the player breaks seals without help ...
fighter:set_reward_bonus(0.1 * self.state.clean) -- +10% for each
end,
}

fraction is the extra share: 0.2 pays 20% more, 0 removes the bonus. It must be from 0 to 4. The last value set wins, and every fight starts with no bonus.

The bonus is applied when the fight’s rewards are worked out, to the coins, gems, experience and forge materials (the enchant orbs) of a win only; a loss, a timeout or a surrender pays the usual amounts. It multiplies the totals after the game’s own coin and gem modifiers, rounding to whole numbers. Item drops, other currencies and choices are not changed. The result screen’s lines show the amounts before the bonus; the player receives the raised amounts.

Only the fight’s round controller (a behavior rule with controls_outcome = true) can set it; any other rule gets false, reason.

Make a fighter tremble on screen for a number of frames.

Signature: fighter:shake(frames, who?, amplitude?)

Parameters

Parameter Type Required
frames integer Required
who "self"|"opponent" Optional
amplitude number Optional

Returns: nil.

When: Combat callbacks during an active round

on_tick = function(self, fighter, event)
if event.frame % 30 == 0 then
fighter:shake(30, "opponent", 3)
end
end

frames is 1 to 3600, and sixty frames is one second. who is "self" (the default) or "opponent". amplitude is how far the fighter moves, from 0 to 40 in fight units, and defaults to 4.

The shake only changes how the fighter is drawn: hitboxes and position stay where they are. It moves one fighter and leaves the screen and the other fighter still. Calling it during a shake extends the shake and keeps the larger amplitude until it ends.

Show a small status icon for a limited time, or refresh one already showing.

Signature: fighter:show_status_icon(key, sprite, frames, stacks?)

Parameters

Parameter Type Required
key string Required
sprite SpriteHandle Required
frames integer Required
stacks integer Optional

Returns: nil.

When: Combat callbacks

local icon = sf2.assets.sprite("core:ui/skills/IconCrackedApple_Blue")
fighter:show_status_icon("relentless", icon, 300, 5)

key lets you refresh or clear the icon later; keys are separate per behavior. sprite must come from sf2.assets.sprite at load time.

Summon an actor next to the fighter, owned by this mod and this fighter.

Signature: fighter:spawn_actor(definition, x, y, z?)

Parameters

Parameter Type Required
definition ActorDefinitionHandle Required
x number Required
y number Required
z number? Required

Returns: A receipt with status; once applied it has an actor_id, on failure an error.

When: Active combat callbacks

-- ally is a registered actor definition; call once from on_tick.
local receipt = fighter:spawn_actor(ally, 180, 0)

Offsets are from the spawning fighter’s center in arena units; positive X is right and positive Y is down. The actor appears on a later step, so check the receipt in a later callback. A rejected spawn never appears in fighter:actors, and pending spawns are cancelled if the round changes. See combat scripting.

Spawn a projectile from a definition registered by this mod, at an offset from the fighter.

Signature: fighter:spawn_projectile(definition, x, y, z?)

Parameters

Parameter Type Required
definition ProjectileDefinitionHandle Required
x number Required
y number Required
z number? Required

Returns: A receipt with status and, once applied, a string projectile_id; on failure an error.

When: Active simulation callbacks such as on_tick

local pending
on_tick = function(self, fighter)
if not pending then
pending = fighter:spawn_projectile(dart, 40, 0)
elseif pending.status == "failed" then
sf2.log.warn(pending.error)
end
end

Offsets are measured from the fighter’s center when the spawn is applied, along world axes: positive Y is down and X is not mirrored by facing. Multiply by facing yourself for a forward shot.

A loop of spawns can partly succeed because each request settles on its own. The receipt fails if the owner dies, changes form or is removed, or the round ends. Actions on the projectile’s first frame run before it is placed, so do position-sensitive effects on later frames. Get live references with fighter:projectiles. See Projectiles.