Skip to content

sf2.fighters

Fighters are the characters, with their model, stats, equipment and behaviours, that you place in battles. Register new ones, look up an existing fighter to build on, or swap items in a core fighter’s equipment. Get sf2 with local sf2 = require("sf2").

Define your own fighter: shared settings that several opponents inherit.

Signature: sf2.fighters.register { id, fighter?, first_name?, last_name?, avatar?, voice?, level?, tactic?, attributes?, attribute_alignments?, items?, perks?, health_bars?, visible_health_bars?, skeleton? }

Parameters

Parameter Type Required
definition FighterDefinition Required

Fields of FighterDefinition

Field Type Required Meaning
id string Optional Generated as <battle>_<fight>_o<position> when omitted.
fighter string|FighterHandle Optional Fighter to inherit stats, items and perks from.
first_name LocalizationHandle|string Optional —
last_name LocalizationHandle|string Optional —
voice string Optional —
avatar SpriteHandle|string Optional Sprite handle for mod-supplied art, or a built-in portrait name.
level integer Optional —
tactic TacticHandle|string Optional —
items string|ItemHandle[] Optional —
perks (string|PerkHandle|WarriorPerk)[] Optional —
attributes table<string,number> Optional —
attribute_alignments AttributeAlignment[] Optional Rows append once to inherited template alignments. Omit to keep the parent rows.
health_bars integer Optional Raid shield: 0 inherits the template; 1-10000.
visible_health_bars integer Optional 0 inherits the template; 1-100 stacked HUD bars, each holding health_bars / visible_health_bars.
skeleton string Optional Recovered body item such as Skeleton or SkeletonHeavy, added to the loadout.
id string Required —

Returns: A fighter handle, accepted wherever sf2.fighters.get handles are.

When: Before the battles that use it.

local default = sf2.fighters.get("core:warrior-templates/default")
local boss = sf2.fighters.register {
id = "fire_boss", fighter = default,
first_name = "my.mod:localization/fire_boss.name", voice = "Male",
health_bars = 15, visible_health_bars = 15,
items = { sf2.items.get("core:items/weapon/WEAPON_KATANA") },
skeleton = "SkeletonHeavy",
}

Fields match the opponent fields in story battles, minus group, random, body_model and skin_models. fighter names a parent (core or registered earlier), so fighters can chain.

Fields inherit one by one, except items: a fighter’s list replaces its parent’s, so list everything it wears, including the body, and set skeleton too. Opponents that set their own items replace it the same way. attribute_alignments rows are additive.

Get an existing fighter blueprint to base a new fighter or opponent on.

Signature: sf2.fighters.get(id)

Parameters

Parameter Type Required
reference string Required

Returns: A fighter handle; a missing ID raises an error.

When: Entrypoint.

local default = sf2.fighters.get("core:warrior-templates/default")

Wherever a fighter is expected you may pass the ID string directly, so a lookup is optional.

Swap items in a core fighter’s own equipment, for every opponent that relies on it.

Signature: sf2.fighters.patch { fighter, items }

Parameters

Parameter Type Required
definition FighterPatch Required

Fields of FighterPatch

Field Type Required Meaning
fighter string|FighterHandle Required A core fighter.
items FighterItemSwap[] Required 1 to 16 swaps.

Returns: nil.

When: Entrypoint. The fighter’s owner (core) must be a declared dependency.

sf2.fighters.patch {
fighter = "core:warrior-templates/man_z7_master",
items = {
{ expected = "core:items/weapon/WEAPON_SUPER_COMPOSITE_SWORD",
value = "core:items/weapon/WEAPON_SWORD_SHADOW_LORD_25" },
},
}

A core fighter (the IDs sf2.fighters.get takes) is a blueprint: opponents name it and inherit its equipment. This call changes the blueprint, so every opponent that uses it without listing its own items wears the new item. Opponents that list their own items keep them, because their list replaces the blueprint’s.

  • fighter is a core fighter ID or handle. Fighters your mod registered are changed where you register them instead.
  • items holds 1 to 16 swaps written { expected = item, value = item }, as item IDs or handles. expected must be in the fighter’s own item list, and value must be the same kind of item (a weapon for a weapon, armor for armor). If expected is missing, for example in another game version, the whole patch fails to load.
  • A fighter that other core fighters are built on cannot be patched.
  • One mod owns a fighter’s items; put every swap for it in one call. Disabling the mod and restarting restores the original.