Skip to content

sf2.perks

Perks are the special abilities that items and enchantments give a fighter. Register your own, look up existing ones, or patch them. Get sf2 with local sf2 = require("sf2").

Register a new perk, or a forgeable enchantment, backed by your own Lua behavior.

Signature: sf2.perks.register { id, display_name, description, icon?, behavior?, template?, kind?, parameters?, upgrades?, initial_upgrade?, enchantment? }

Parameters

Parameter Type Required
definition PerkDefinition|EnchantmentDefinition Required

Fields every kind shares (PerkDefinition, EnchantmentDefinition)

Field Type Required Meaning
id string Required —
icon string|SpriteHandle Optional —
parameters table<string,any> Optional —

More fields of PerkDefinition

Field Type Required Meaning
display_name string|LocalizationHandle Optional Required unless template provides it.
description string|LocalizationHandle Optional Required unless template provides it.
behavior BehaviorDefinition|StatefulBehavior Optional Behavior table. Required unless template provides one.
template string|PerkHandle Optional A perk of this mod to copy from; fields you set override it.
kind "single"|"combo" Optional Default “single”.
upgrades PerkUpgrade[] Optional —
initial_upgrade integer Optional —

More fields of EnchantmentDefinition

Field Type Required Meaning
display_name string|LocalizationHandle Optional Required unless enchantment.perk provides it.
description string|LocalizationHandle Optional Required unless enchantment.perk provides it.
behavior BehaviorDefinition|StatefulBehavior Optional A behavior table, registered automatically. Needed unless enchantment.perk is set.
enchantment PerkEnchantment Required —

Returns: A perk handle, or an enchantment handle when enchantment is given.

When: Entrypoint.

local focus = sf2.perks.register {
id = "opening_focus",
display_name = sf2.text.get("perk.opening_charge"),
description = sf2.text.get("perk.opening_charge.description"),
behavior = opening_charge,
parameters = { amount = 0.35 },
}

Registering does not give the perk to anyone. Add it to an opponent’s perks, a fight rule, a perk-tree choice or an item (an item-only perk can be written inline as perk = { behavior = ... }). Player callbacks run only for learned, active perks. See the perks guide.

behavior is a table of callbacks and defaults. Passing the same table to several perks reuses it, and each perk’s parameters override the behavior’s defaults.

local opening_charge = {
parameters = { amount = 0.25 },
on_fight_begin = function(parameters, fighter, event)
fighter:add_magic_charge(parameters.amount)
end,
}

template = <perk> copies name, description, icon, kind, behavior and parameters from a scripted perk of your mod unless you set them; your parameters are merged over the template’s. Upgrades are not copied.

Give enchantment to register a perk players get from a forge recipe. With behavior it is a new enchantment; with enchantment.perk it wraps an existing scripted perk of your mod (leave out behavior). kind, upgrades, initial_upgrade and template do not apply. The player must still forge it, so make it obtainable with sf2.forge.register.

local enchantment = sf2.perks.register {
id = "charged_weapon",
display_name = sf2.text.get("perk.opening_charge"),
description = sf2.text.get("perk.opening_charge.description"),
behavior = opening_charge,
enchantment = { recipe = "simple", item_types = { "weapon" } },
}

upgrades is a list of levels numbered 1, 2, 3… with no gaps; level 0 is the base perk. Each level’s parameters override the base perk’s, not the previous level’s. initial_upgrade makes a newly registered learned perk start at that rank; saved ranks are unchanged. Offer the steps with sf2.perks.patch and a branch. Only learned perks use the upgrade level; equipment and warrior callbacks always use base parameters.

upgrades = {
{ level = 1, parameters = { Drain = 0.02 } },
{ level = 2, parameters = { Drain = 0.04 } },
}

Change how a perk shows on the HUD, forbid moves while one of its flags lasts, or replace the choices at one perk-tree level.

Signature: sf2.perks.patch { perk, recharge_indicator? = { flags, ready, cooldown }, opponent_icons?, meter? = { segments?, phases }, forbid_moves? = { flag, moves } } or sf2.perks.patch { branch = { level, entries } }

Parameters

Parameter Type Required
definition PerkPatch Required

Fields of PerkPatch

Field Type Required Meaning
perk string|PerkHandle Optional The core or registered perk to change; needed with recharge_indicator, opponent_icons, meter or forbid_moves.
recharge_indicator PerkRechargeIndicator Optional —
meter PerkMeter Optional A fight meter fed from the perk’s own flags and variables.
opponent_icons boolean Optional false hides the HUD icons of this perk (its own icons and its recharge indicator) on the opponent side; the player keeps them. Default true.
forbid_moves PerkMoveForbid Optional While the flag is on a fighter, it starts none of these kinds of move, player and computer alike. Once per perk in a mod.
branch PerkBranch Optional Replaces the entries of a perk-tree level; use instead of perk.

Returns: nil.

When: Entrypoint.

sf2.perks.patch {
perk = sf2.perks.get("core:perks/PERK_HERMITSTORM"),
recharge_indicator = {
flags = { "HermitStormRecharge" },
ready = sf2.assets.sprite("sprites/abilities/hermit_storm"),
cooldown = sf2.assets.sprite("sprites/abilities/hermit_storm_cooldown"),
},
}

Give perk with any of recharge_indicator, opponent_icons, meter and forbid_moves, or give branch on its own.

Shows on the fight HUD whether a perk’s ability is ready, for every fighter carrying the perk. Only one indicator per perk is allowed across enabled mods. The indicator replaces the perk’s own HUD icons: icons the base game draws for that perk (for example a boss ability’s ready and cooldown icons) stop showing while your mod is on.

A flag is a named modifier on a fighter, the same thing a move’s not_mod condition checks. The ability counts as recharging while any listed flag is active. Use a core perk’s own flag, or one your behavior sets with fighter:set_flag, written "<mod id>:behaviors/<behavior id>:<key>" (a perk’s behavior ID is the perk’s ID). A flag set without a duration shows no sweep, so give your own flags one.

-- In the perk's behavior:
fighter:set_flag("cooldown", 600)
-- Then:
sf2.perks.patch {
perk = storm,
recharge_indicator = {
flags = { sf2.mod.id .. ":behaviors/storm:cooldown" },
ready = sf2.assets.sprite("sprites/storm"),
cooldown = sf2.assets.sprite("sprites/storm_cooldown"),
},
}

The indicator is display only and never blocks a move: gate the move with a not_mod condition on the same flag. Icons draw at the sprite’s native size; set pixels_per_unit to size them.

opponent_icons (optional, default true) decides whether the perk’s icons appear on the opponent’s side of the fight HUD (the fighter on the right). Set it to false to hide them there: the icons the base game draws for the perk (for example the cloak icon while a fighter is invisible) and the perk’s recharge indicator, if it has one. The player’s side keeps showing them. It changes only what the HUD draws, never what the perk does. Only false changes anything; if any enabled mod sets it, the opponent’s icons for that perk stay hidden.

-- The player sees their own cloak's readiness; an invisible opponent gives nothing away.
sf2.perks.patch {
perk = sf2.perks.get("core:perks/PERK_INVISIBILITY"),
opponent_icons = false,
}

meter shows a perk’s charge in the fight meter that fighter:set_meter draws, for every main fighter carrying the perk, without a behavior. The meter reads the perk’s own state each frame, so it also works for game perks that keep a count in their XML.

-- Roaring Luminary: four unbroken strikes open the lava pool.
sf2.perks.patch {
perk = sf2.perks.get("core:perks/PERK_MAGMA_VOLCANO_SET"),
meter = {
segments = 4,
phases = {
{ flag = "MagmaActive", color = "#FF7A2E" }, -- the pool's time left
{ variable = "StrikeCount", max = 4, color = "#B4532A" }, -- strikes landed so far
},
},
}

phases is a list of 1 to 6 ways to fill the meter. Each frame, the first phase that applies is shown:

Phase Applies Fills
flag While that flag is active on the fighter, or with on = "opponent" on its opponent. The flag’s time left. With show = "passed" it fills as the flag runs, which suits a cooldown. With show = "full" it stays full while the flag is up, which suits a flag the perk keeps re-arming in short bursts. An untimed flag shows full.
variable with max Always. With only_above_zero = true, only while the variable is above 0. The perk variable (the value XML reads as ?Variable[name]) divided by max. With count = "down" it fills as the variable falls toward 0.
neither Always. Full, for example a “ready” state after the other phases.

Every phase takes an optional color ("#RRGGBB" or "#RRGGBBAA", default white) and segments. A phase can also give label_variable, a perk variable whose value is written as a whole number above the bar while the phase is shown, such as a curse’s level over its time left:

-- Crimson Corruption: the curse's time left, with its level above the bar.
phases = { { flag = "BloodCurseStart", on = "opponent", label_variable = "EffectStep", color = "#C0182E" } }

segments (1 to 8, default 1, a smooth bar) splits the meter into cells; set it on the meter and override it per phase. When no phase applies, the meter is hidden.

Flags and variables use the perk’s exact names: a game perk’s <ModFlag Name> and <SetModVariable Name> in its XML (resolve _Name parameters to their values), or the flags your own behavior sets. Only one meter per perk is allowed across enabled mods. The meter is a display only, and on the opponent side it follows opponent_icons.

forbid_moves keeps a fighter from starting certain kinds of move while a flag is on it. Unlike the recharge indicator and the meter, this changes the fight: it holds for the player and for computer opponents, and the computer stops choosing those moves while the flag lasts.

-- Time Shift: while its slow lasts, the slowed fighter throws nothing, casts no magic and
-- uses no boss ability.
sf2.perks.patch {
perk = sf2.perks.get("core:perks/PERK_TIME_SHIFT_SET_TIME_SHIFTER"),
forbid_moves = { flag = "IsSlowedDown", moves = { "ranged", "magic", "ability" } },
}
Field Required Meaning
flag Yes The exact flag name (1 to 128 characters), as a move’s not_mod takes it. The moves are forbidden to whichever fighter the flag is on: a game perk often puts its flag on the opponent, as Time Shift puts IsSlowedDown on the fighter it slows.
moves Yes A list of 1 to 3 kinds, each once: "ranged" (ranged weapon throws), "magic" (magic casts, which also covers most boss abilities, since they are built as casts) and "ability" (boss abilities, such as the moves on the raid charge button).

Only the start of a move is stopped: a button press, or a computer opponent’s choice. A move already playing finishes, along with the parts of it that follow on by themselves, and a projectile already thrown keeps flying. A fighter whose magic meter is full keeps the charge for later. A kind is matched by the game template a move is built on (RangedPlayer, MagicPlayer or BossAbility), so moves you register with sf2.moves.register count when their inherit list names one. Abilities a behavior starts without a move, such as an actor it spawns when a button is pressed, are not stopped.

The flag is matched by name only, whichever perk set it. Use a game perk’s own flag (its <ModFlag Name> or <ModIcon Name> in the XML, with _Name parameters resolved), or the qualified name fighter:set_flag returns for a flag your behavior sets on its own fighter. Each mod gives forbid_moves once per perk; when several mods forbid moves under the same perk, every kind any of them lists is forbidden.

branch replaces the choices at one perk-tree level; it does not teach a perk or change XP or prices. Two mods replacing the same level conflict. Keep alternatives sensible for players already past that level.

sf2.perks.patch {
branch = { level = 2, entries = { { perk = opening_focus, action = "unlock" } } },
}

Look up an existing perk definition.

Signature: sf2.perks.get(reference)

Parameters

Parameter Type Required
reference string Required

Returns: A perk handle; a missing definition raises an error.

When: Entrypoint.

local lifesteal = sf2.perks.get("core:perks/PERK_ITEM_SPECIAL_LIFESTEAL_WEAPON")

Use the complete perk ID. The handle works in opponent loadouts, fight rules and forge candidates.