Skip to content

sf2.battles

Battles are the story fights of your mod: a group of fights with their opponents, rules, rewards and map presentation. Register a battle while your mod loads. Patch existing battles, or set a handler that prepares a fight just before it starts. Get sf2 with local sf2 = require("sf2").

Create a map entry together with its fights, opponents, rules and rewards.

Signature: sf2.battles.register { id, page, x?, y?, type?, title?, alias?, description?, icon?, icon_atlas?, icons?, eclipse_toggle_name?, location?, reward_image?, music?, preview?, show_resistance?, power_mode?, fights }

Parameters

Parameter Type Required
definition BattleDefinition Required

Fields of BattleDefinition

Field Type Required Meaning
id string Required —
page string|PageHandle Required The map page the battle sits on.
type "story"|"dummy"|"tutorial"|"challenge"|"bosses"|"tournament"|"survival"|"friendly"|"auto"|"ai"|"hidden"|"fake"|"pvp"|"final"|"final_titan"|"raid" Optional Default “story”.
x integer Optional Default 0.
y integer Optional Default 0.
title LocalizationHandle|string Optional —
alias LocalizationHandle|string Optional Map entry name; defaults to title.
description LocalizationHandle|string Optional —
icon string Optional —
icon_atlas string Optional —
eclipse_toggle_name string Optional —
location string Optional —
reward_image string Optional —
music AudioHandle|string Optional Audio handle for music the mod ships, or a built-in track name.
preview SpriteHandle|string Optional Sprite handle for mod-supplied art, or a built-in preview name.
show_resistance boolean Optional Show the immunity slider in the map panel for the resistance its fights test or raise (Resistance_2 when none).
power_mode "normal"|"power" Optional Underworld pages only: show in normal or power mode. Omit for always.
icons BattleIcons Optional Mod-supplied map-button sprites.
fights BattleFight[] Required 1 to 100 fights, played in order.

Returns: A battle handle; battle.fights[1] etc. are the fight handles in order.

When: Entrypoint, after the page it sits on.

local battle = sf2.battles.register {
id = "training_battle", page = page, title = sf2.text.get("battle.title"),
preview = sf2.assets.sprite("sprites/training_preview"),
fights = { {
opponents = { { fighter = "core:warrior-templates/default", level = 1 } },
rounds = 1,
rewards = { [1] = { gems = 5 } },
} },
}
local first_fight = battle.fights[1]

See Story battles for fights, opponents and rewards, and Battle rules for rules. Registering does not show the entry in an existing story save: reveal it with a story handler or sf2.map.reveal.

Fight IDs are <battle id>_<name>, where name defaults to the fight’s position. Saved progress uses these IDs, so once players have your mod, keep the ids, names and order of existing fights unchanged.

player gives the fight a temporary player character; it does not touch the saved profile. Give it an explicit level and a compatible rig and move set (Characters). Use fighter:change_form for a change during the fight.

An opponent is a fighter table plus its own fields, and can inherit from one with fighter.

opponents = { {
fighter = "core:warrior-templates/default",
level = 1,
tactic = "Standard",
avatar = sf2.assets.sprite("sprites/partner"),
} }
  • avatar: a sprite handle is checked at load; a plain string such as "character_savage" names core art and is not checked.
  • health_bars is a raid shield measured in normal health bars; visible_health_bars is how many stacked bars the HUD draws. See Underworld and modes.
  • health_marks = { 12, 22 } draws thin dividers on this fighter’s health bar at those health values, counted in health bars from empty (the units of health in fighter:snapshot). Use it to show where a boss’s phases split. 1 to 16 values, each above 0. On a stacked bar a mark shows while the bar that holds it is the one drawn; a mark exactly on the edge between two bars, or beyond the whole pool, is not drawn. A normal fighter’s bar is 1 health bar, so its marks are between 0 and 1. Opponents and player only; sf2.fighters.register does not take it.
  • Invented attribute names create no new mechanics, and duplicate loadout items or perks are rejected.

Perk settings. A perks entry is a perk handle or ID, or a table { perk, aspect?, chance_factor?, chance?, frames?, parameters? }. These change only that opponent’s copy of a core perk. chance_factor is a multiplier, chance a 0-1 probability, frames simulation frames. They override the perk’s own values only where it reads them, and an explicit zero overrides. parameters sets other numeric values the perk reads (such as DamageFactor); a name it does not read has no effect.

perks = {
{ perk = sf2.perks.get("core:perks/PERK_ITEM_SPECIAL_TIME_BOMB_WEAPON"), aspect = 100000, chance_factor = 2.69 },
{ perk = sf2.perks.get("core:perks/PERK_HERMITSTORM"), frames = 300 },
}

A fight’s rewards maps a win count to a reward table. A win is one opponent beaten: [0] is a loss, [1] a win against the first opponent.

rewards = {
[0] = { experience = 1 },
[1] = { gems = 20, experience = 300,
currencies = { { currency = "ForgeMaterial1", expected = 50 } } },
}
  • One opponent, or several opponents over several rounds: keys [0] and [1]. Several opponents with one round each: [0] to [n], one per opponent beaten.
  • A missing key pays nothing, so most fights write only [1]. An empty {} or a key outside the range is an error. The map shows the last key’s reward as the prize.
  • experience is an absolute point count. prize_base is the base for performance coin bonuses, not a fixed award.
  • currencies rows are { currency, expected, show? }; expected is the average amount the drop is rolled from, and show = false hides it on the result screen.
  • A choice candidate is { item, upgrade = 0, weight = 1, configure? }; each group picks one by weight.
  • An items entry for a stackable consumable can add count (1 up to the item’s stack): { item = elixir, count = 2 } gives two pieces, never past the stack. Each piece shows on the result screen. A reward lists at most 100 pieces in all. A mod’s consumables are given again even when the player already holds some; other items are given only once.

Chest draws (lottery). A reward can hold a lottery: after a win the game draws one slot by weight and shows it on the lottery screen of Shadow Fight 2 1.9.38 (the Ascension chests) when the player is back on the map. The draw is saved, so closing the game before opening the chest does not lose it. Use it in a win slot ([1] and up).

local helm = sf2.items.get("core:items/helm/HELM_C2_Z2_MONK")
local ticket = sf2.items.get(sf2.mod.id .. ":items/consumable/ticket") -- a stackable consumable
rewards = { [1] = { lottery = {
type = "bronze",
image = sf2.assets.sprite("sprites/chest_bronze"),
slots = {
{ item = helm, weight = 2 },
{ currency = "ForgeMaterial3", scale = 0.27 },
{ coins_scale = 0.2, max_level = 37 },
{ coins_scale = 0.2, min_level = 38 },
{ item = ticket, count = 1, image = sf2.assets.sprite("core:UI/Atlases/MiscSprites.ticket") },
},
} } }
Slot field Default Meaning
weight 1 Relative chance, above 0 up to 1000000.
min_level, max_level None The player levels the slot can be drawn at (1 to 10000).
image The item’s art for core items Sprite handle or core image name shown when the slot is drawn.
item Prize: an item, with upgrade, configure and count as in items.
currency Prize: "ForgeMaterial1", "ForgeMaterial2" or "ForgeMaterial3", with expected (an amount) or scale (a multiple of the player level’s base value, up to 1000).
coins, coins_scale Prize: a fixed number of coins, or a multiple of the player level’s base value.
pity false true on an item slot makes it a pity slot (see the lottery’s pity).
Lottery field Default Meaning
slots Required 1 to 64 slots, as above.
type The gold scroll "bronze", "silver" or "gold": which chest scroll the lottery screen draws. A typed chest also has the Puppeteer remind the player, the first time they leave it, that extra spins can win more.
pity 0 Percentage points (0 to 100) added to the chance of the pity slots for every earlier draw of this lottery that missed all of them, spins for gems included; drawing one resets the count. With 2 of 14 slots as pity slots (about 14%) and pity = 3, the next draw after a miss is about 17%. Draws that cannot reach a pity slot (the player owns its item) do not count. The count is saved per pity item in the player’s profile, so give each lottery’s pity slots a different item. Default off: the odds stay the slots’ weights.
image None The chest’s picture. The map panel shows it as the fight’s prize, and the plain reward card (used only for draws saved before the lottery screen existed) shows it when the drawn slot has no picture.
  • Each slot holds exactly one prize.
  • An equipment slot drops out of the draw once the player owns that item, so a set piece is not drawn twice. Consumable slots always stay in.
  • “Base value” is the game’s coin or orb amount for the player’s level. scale = 0.27 pays 27% of it, so prizes grow with the player. Coin prizes follow the player’s coin type: after the Interlude’s platinum and Act 7’s credits they are divided like every other coin reward, so a level-52 player in Act 7 gets 250,000 credits from coins_scale = 0.8.

The lottery screen. The scroll shows every prize the player can still draw. START spins for free and stops on the drawn slot; the prize grows, then fades into the player’s inventory. Then CONTINUE leaves, and MORE spins again for gems (5 for the first extra spin, then 10, 15 … up to 55, from LotteryRerollPrices in internalSettings.xml). Each extra spin draws and pays another prize from the same slots. Without enough gems the game’s “not enough gems” dialog opens instead.

Resistances. resistances = { { name = "Resistance_2", value = 45 } } raises a resistance the game keeps in the player’s save. Resistance_2 is the only one the game defines (Ascension’s immunity, at most 1000). Pair it with the resistance rule, which sets a fight’s threshold. Up to 8 entries, each value 1 to 100000.

A battle with show_resistance = true shows the player’s value on the map panel as the immunity slider of 1.9.38’s Ascension, taking turns with the difficulty bar. It shows the resistance the battle’s fights test (a resistance rule) or raise (a reward), Resistance_2 when they name none. A fight that raises a resistance also shows the big immunity slider on its result screen, filling from the old value to the new one.

Configuring equipment when granted. Equipment grants (direct items and choice candidates, not consumables, free items or seals) can set the item’s level and enchantments in a configure callback.

local precision = sf2.perks.get("core:perks/PERK_ITEM_SPECIAL_PRECISION_WEAPON")
rewards = { [1] = { items = { {
item = desolator,
configure = function(context)
return {
level = context.player_level,
enchantments = { { perk = precision, aspect = 1940.5, chance = 0.2 } },
}
end,
} } } }

context has player_level and item_id. Return level (defaults to player_level; it must exist in the item’s progression or the grant is skipped) and/or enchantments, which take the same settings as opponent perks. An enchantment’s aspect may also be "level": its power is the forge’s aspect scale value for the player’s level at the moment of the grant (the power a shop item of that level has). It is saved as that number and does not change as the player levels up. The callback must be a pure calculation that gives the same result for the same context, because it can run more than once (for previews). Capture perk handles outside it. If it errors, only that item is skipped.

preview is the battle panel image and icons replaces the round map button (base required; supply active too or the selected state has no art, and pressed for the art shown while the button is held, or it only darkens). A sprite handle is checked at load; a plain string is not, so a typo shows an empty panel. Leave icon_atlas empty when you set icons.

type is a map category, not a game mode: "dummy", "tutorial", "challenge", "bosses", "tournament", "story", "survival", "friendly", "auto", "ai", "hidden", "fake", "pvp", "final", "final_titan" or "raid".

On an Underworld page, power_mode = "normal" shows the entry only while Power Mode is off and "power" only while it is on; pair a normal boss with a harder one at the same spot to swap them. It is rejected on story pages. The Underworld map shows its Power Mode switch only while some entry uses power_mode = "power"; leave the field out everywhere and there is no switch, and every entry always shows.

Eclipse pairs. Register the normal and Eclipse battles on the same page, each with its own fights, and set only the normal entry’s eclipse_toggle_name to the variant’s full name (for example sf2.mod.id .. ":battles/training_eclipse", not a localization key). The swap is done by sf2.game.refresh_eclipse_battles and the game’s own updates, once the normal entry’s last fight has been won. For scheduled or replayable content, see Underworld and modes.

Move an existing battle on the map, or change an existing fight’s opponents, rules, music or item drops.

Signature: sf2.battles.patch { battle, x?, y?, edit_rules? } or sf2.battles.patch { fight, description?, rounds?, round_time?, location?, music?, opponents?, reward_drops?, rules?, append_rules?, edit_rules? }

Parameters

Parameter Type Required
definition BattlePatch|FightPatch Required

Fields of BattlePatch

Field Type Required Meaning
battle string|BattleHandle Required Battle handle, or qualified core or dependency battle ID, such as core:battles/zone_6/duel.
x integer Optional New map x, -10000..10000; omit to keep.
y integer Optional New map y, -10000..10000; omit to keep.
edit_rules NativeRuleEdit[] Optional Core battles only: edits the rules stored on the battle. Give x, y or edit_rules.

Fields of FightPatch

Field Type Required Meaning
fight string|FightHandle Required Fight handle, or qualified core or dependency fight ID.
description string Optional —
rounds integer Optional —
round_time integer Optional —
location string Optional —
music AudioHandle|string Optional Audio handle for mod-owned music, or a built-in track name.
opponents Opponent[] Optional Replaces the fight’s opponents.
reward_drops RewardDropPatch[] Optional —
rules (Rule_no_perks|Rule_require_item|Rule_equip_item|Rule_avatar|Rule_name|Rule_perk|Rule_behavior|Rule_recharge_magic_each_round|Rule_attributes|Rule_no_button|Rule_hot_ground|Rule_ring_out|Rule_regeneration|Rule_no_animation|Rule_no_health_bar|Rule_invert_joystick|Rule_random_area|Rule_light_in_the_darkness|Rule_group|Rule_random|Rule_remove_interval|Rule_resistance)[] Optional Replaces the fight’s rules. Cannot be combined with other patches to its rules.
append_rules (Rule_no_perks|Rule_require_item|Rule_equip_item|Rule_avatar|Rule_name|Rule_perk|Rule_behavior|Rule_recharge_magic_each_round|Rule_attributes|Rule_no_button|Rule_hot_ground|Rule_ring_out|Rule_regeneration|Rule_no_animation|Rule_no_health_bar|Rule_invert_joystick|Rule_random_area|Rule_light_in_the_darkness|Rule_group|Rule_random|Rule_remove_interval|Rule_resistance)[] Optional Rules added to the fight’s existing ones. Duplicates and overlapping outcome controllers conflict.
edit_rules NativeRuleEdit[] Optional Core fights only: edits the game’s own rules in place. Not combined with rules.

Returns: nil.

When: Entrypoint. The target’s owner must be a declared dependency.

-- Move Act 6's Duel and its intermission twin.
sf2.battles.patch { battle = "core:battles/zone_6/duel", x = -300, y = 100 }
sf2.battles.patch { battle = "core:battles/zone_6/duel_intermission", x = -300, y = 100 }
sf2.battles.patch {
fight = "core:fights/zone_1/boss_lynx/1",
opponents = { { fighter = "core:warrior-templates/default", level = 12 } },
append_rules = { { kind = "behavior", behavior = my_behavior } },
}

Pass exactly one of battle or fight (a fight handle or ID string). Saved progress, lock state and rewards are never affected, and disabling the mod and restarting restores the original.

Moving a battle. x and y use the same map-page space as sf2.battles.register. Core IDs look like core:battles/<zone>/<battle>. An Eclipse-mode or intermission twin is a separate battle; move it too if it shares the spot. Patching a battle your own mod registered is an error.

Changing a fight. Fields are plain replacements; omitted ones are kept. opponents replaces the whole list. rules replaces the whole rule list (including native rules; {} clears it), while append_rules adds to it; use one or the other. To change one detail of the game’s own rules instead, use edit_rules (below). See Battle rules.

Two mods patching the same field conflict and the second fails to load; different fields coexist, and append_rules from several mods combine in dependency order. If a call fails validation, none of its fields apply. See Combine mods.

Item drops. reward_drops edits only the item grants and item-only choices of one reward slot; gems, experience and currencies stay. wins picks the slot, and reward.gems must be zero. Without min_level/max_level the edit changes the direct drops; with them, it edits the level row with exactly those bounds, creating it if needed.

sf2.battles.patch {
fight = "core:fights/zone_1/boss_lynx_eclipsemode/1",
reward_drops = { {
wins = 1, mode = "eclipse",
reward = { items = { { item = sf2.items.get("core:items/weapon/WEAPON_C2_Z2_MONK_KATAR") } } },
} },
}
  • Modes are additive: "all" edits the shared reward, while "eclipse" or "normal" edit only that mode’s extra reward.
  • A mode does not select a different battle. BOSS_LYNX and BOSS_LYNX_ECLIPSEMODE are separate fights; patch the one you mean.
  • The game skips equipment the player already owns, so test with an item you do not have.

Editing the game’s own rules. Many core fights carry rules the game wrote itself, sometimes deep inside a random choice of challenges. edit_rules changes the animation list of those rules without restating the rest. Each entry names a rule kind and gives the list in the guarded form { expected = ..., value = ... }:

sf2.battles.patch {
fight = "core:fights/zone_7/duel/1",
edit_rules = {
{ kind = "hot_ground", animations = {
expected = { "ThrowFall", "Jump", "PhysicalFall" },
value = { "ThrowFall", "LegFall", "Jump", "PhysicalFall" },
} },
{ kind = "lose_fall", animations = {
expected = { "Fall", "Physical", "ThrowThroughTheBackV", "ThrowForwardV" },
value = { "Fall", "Physical", "ThrowThroughTheBackV", "ThrowLegPushV" },
} },
},
}
-- Some battles hold rules shared by all their fights; edit those on the battle.
sf2.battles.patch {
battle = "core:battles/zone_2/challenge_eclipsemode",
edit_rules = { { kind = "hot_ground", animations = {
expected = { "ThrowFall", "Jump", "PhysicalFall" },
value = { "ThrowFall", "LegFall", "Jump", "PhysicalFall" },
} } },
}
  • kind is "hot_ground" (the floor that burns a fighter who stays on it; the listed animations are the ones that count as off the ground) or "lose_fall" (the round is lost when a fighter falls out of bounds during one of the listed animations). lose_fall exists only in the game’s own fights; your own fights cannot add one.
  • expected must be the rule’s current list, names and order exactly. Every rule of that kind whose list matches is changed, wherever it sits in the fight’s rules. If none matches, for example in another game version, the whole patch fails to load instead of changing something else.
  • value replaces the list: 1 to 32 animation template names. Names the game does not know are ignored by the rule.
  • Only core fights and battles can be edited this way; for your own battles, write the rule you want in sf2.battles.register. A battle’s edit_rules changes only the rules stored on the battle, not those inside its fights.
  • One mod owns a fight’s (or battle’s) edit_rules; put every edit for it in one call. It cannot be combined with rules, which replaces the list it edits.

Set this mod’s fight-prepare handler.

Signature: sf2.battles.on_prepare(function(fight) ... end)

Parameters

Parameter Type Required
handler fun(fight:FightPrepareFight):FightPreparePlan|nil Required

Fields of FightPrepareFight

Field Type Required Meaning
id string Required Fight ID.
mode "story"|"survival"|"tournament"|"challenge"|"boss"|"final"|"ascension"|"replayable"|"periodic"|"raid"|"tutorial"|"other"|"dojo" Required The fight kind; “dojo” is sparring in the dojo, where only arrow_color is used.
underworld boolean Required —
tutorial boolean Required —
preview boolean Required True when only the map difficulty bar is computed; only strength is used.
score_victory boolean Required True for a score victory: the round goes to whoever lands more hits.
round_time integer Required Seconds per round; 0 when untimed.
endless boolean Required —
ratio number Required Difficulty-bar rating ratio before any plan; 0 when unknown.
enemies FightPrepareEnemy[] Required —

Fields of FightPreparePlan

Field Type Required Meaning
round_time integer|"endless" Optional 1..86400 seconds, or “endless”. Untimed fights stay untimed.
strength number Optional 0.25..8 multiplier on the opponents’ rating.
minimum_ratio number Optional 0..100 lowest difficulty-bar value; strength rises to reach it (up to 64).
ai FightPrepareAi Optional —
ai_add FightPrepareAiAdd Optional Added after the ai multipliers, -1000..1000.
enemies table<integer,FightPrepareEnemyPlan> Optional —
arrow_color string Optional “#RRGGBB” or “#RRGGBBAA” tint of the player ground arrow; nil keeps the default colour.
armored_against string|PerkHandle[] Optional Up to 32 core perks of the player whose health drains and returned damage go through the opponents’ body armour, like a weapon hit.

Returns: nil.

When: Entrypoint; at most one handler per mod.

sf2.battles.on_prepare(function(fight)
if fight.underworld or fight.mode == "tutorial" then return nil end
if sf2.saves.get("difficulty") ~= "brutal" then return nil end
return { round_time = 60, strength = 2, ai_add = { dodge = 0.3 } }
end)

Return nil to leave the fight alone. An error is logged and only your plan is dropped. The plan fields are in Battle rules.

Show a different preview picture for battles on the map, optionally only while a setting is on.

Signature: sf2.battles.replace_preview { preview, replacement, setting?, choice? } or sf2.battles.replace_preview { battle, replacement, setting?, choice? }

Parameters

Parameter Type Required
definition PreviewReplacement Required

Fields of PreviewReplacement

Field Type Required Meaning
preview string Optional A battle preview name, such as “preview_main.cave”: every battle that shows it. Give this or battle.
battle string|BattleHandle Optional One battle: a handle, or a qualified core or dependency battle ID such as core:battles/zone_7/miniboss_ancient. Give this or preview.
replacement SpriteHandle|string Required Sprite handle for mod-supplied art, or a built-in preview name.
setting SettingHandle|SettingChoiceHandle Optional A switch that turns the replacement on or off, or a choice setting together with choice. Default: always on.
choice string Optional With a choice setting: the id of the choice the replacement applies to.

Returns: nil.

When: Entrypoint. Changing the setting takes effect the next time a battle’s panel opens on the map.

local se = sf2.settings.toggle { id = "se_previews", label = "Special Edition previews" }
-- Every battle that shows the Cave picture.
sf2.battles.replace_preview {
preview = "preview_main.cave",
replacement = sf2.assets.sprite("sprites/previews/cave_se"),
setting = se,
}
-- Just one battle, always.
sf2.battles.replace_preview {
battle = "core:battles/zone_7/miniboss_ancient",
replacement = sf2.assets.sprite("sprites/previews/ancient"),
}

The preview is the picture in a battle’s panel when you tap its button on the map. Pass exactly one target:

  • preview: a preview name, as battles name it (such as "preview_main.cave" or "preview_bosses.titan"). Every battle that shows that picture changes.
  • battle: one battle, as a handle or an ID such as "core:battles/zone_7/miniboss_ancient". It must come from the game or a mod you depend on. An Eclipse-mode or intermission twin is a separate battle, so replace it too if it should match.

replacement is a sprite handle for art your mod ships, or the name of another built-in preview. A 16:9 picture fits best; it is drawn in the same box as the original. Leave setting out to replace the picture whenever the mod is enabled. setting is a switch from sf2.settings.toggle, or a choice from sf2.settings.choice with choice, the id of the choice the picture shows for (see sf2.world.replace for an example).

To pick the picture from the player’s progress instead (for example, a different one for each fight of a battle), use sf2.battles.on_preview.

Only the picture changes. The battle’s stage, fights and rewards stay the same. To change the stage as well, use sf2.world.replace.

  • A replacement for one battle wins over a replacement for its preview name.
  • One mod may give the same target several replacements behind different settings or choices; the first one whose setting is on (or whose choice is picked) wins. Listing the same target and setting (and choice) twice is an error.
  • Two mods replacing the same target conflict, and the second fails to load. See Combine mods.
  • At most 256 replacements per mod.

Choose a battle’s preview picture, the name at the top of its panel, and who accepts the challenge on a boss panel, each time its panel opens on the map.

Signature: sf2.battles.on_preview(handler)

Parameters

Parameter Type Required
handler fun(battle:PreviewBattle):SpriteHandle|string|PreviewResult|nil Required

Fields of PreviewBattle

Field Type Required Meaning
id string Required Battle ID, such as core:battles/zone_7/c3_boss_titan.
fight string Optional The fight the panel would start next, such as core:fights/zone_7/c3_boss_titan/6; nil when the battle has none.
index integer Required Position of that fight in the battle, from 1; 0 when there is none.
preview string Required The picture the panel would show: the battle picture after sf2.battles.replace_preview and earlier mods.

Fields of PreviewResult

Field Type Required Meaning
preview SpriteHandle|string Optional Sprite handle or built-in preview name; nil keeps the picture.
challenger string Optional Who accepts the challenge on a boss panel: replaces the battle’s name in “<name> accepted your challenge.” 1-64 characters.
title string Optional The battle name at the top of the panel instead of the battle title. 1-64 characters.

Returns: nil.

When: Entrypoint, once per mod. The handler runs each time a battle’s panel opens on the map.

local GUARDS = sf2.assets.sprite("sprites/previews/guards")
local BOSS_FIGHT = "core:fights/zone_7/c3_boss_titan/6"
sf2.battles.on_preview(function(battle)
if battle.id ~= "core:battles/zone_7/c3_boss_titan" then return nil end
-- The first five fights are the boss's guards.
if battle.index >= 1 and battle.index <= 5 then return GUARDS end
-- Until the boss is beaten once, keep the battle's own picture.
if sf2.profile.fight(BOSS_FIGHT).wins == 0 then return nil end
return "preview_bosses.titan"
end)

The preview is the picture in a battle’s panel when you tap its button on the map. Your handler gets a table describing the battle and returns the picture to show, or nil to keep the current one.

Field Meaning
id The battle’s ID, such as "core:battles/zone_7/c3_boss_titan".
fight The fight the panel would start next, such as "core:fights/zone_7/c3_boss_titan/6", or nil when the battle has none left.
index That fight’s position in the battle, counting from 1; 0 when there is none.
preview The picture the panel would show now: the battle’s own, after sf2.battles.replace_preview and any earlier mod’s handler.

Return a sprite handle for art your mod ships, or the name of a built-in preview (such as "preview_main.cave"). Read the player’s progress with sf2.profile.fight to change the picture as they move through a battle.

A battle’s panel is headed by the battle’s name, and a boss battle’s panel reads “Titan accepted your challenge.”, built from that name. When the fight the panel would start is against someone else, return a table instead of a picture:

local JUSTICE = sf2.text.read(sf2.text.register { id = "justice", language = "eng", value = "Justice" })
sf2.battles.on_preview(function(battle)
if battle.id ~= "core:battles/zone_7/c3_boss_titan" or battle.index ~= 6 then return nil end
return { preview = "preview_fights.may", title = JUSTICE, challenger = JUSTICE }
end)
Field Meaning
preview Optional. The picture, as above; leave it out to keep the current one.
title Optional. Text of 1 to 64 characters shown at the top of the panel instead of the battle’s name.
challenger Optional. Text of 1 to 64 characters that replaces the battle’s name in “name accepted your challenge.” It shows only on boss panels (the last fight of a boss battle).

Read both from your text with sf2.text.read so they can be translated. When several mods name a title or a challenger, the last one in load order wins.

  • Handlers run in load order, and each sees the picture the earlier ones chose, so a mod that depends on another has the last word.
  • Keep the handler quick: it runs while the map is on screen. An error in it is logged and the picture stays as it was.
  • Only the picture, the title and the challenger line change; the battle’s fights, stage and rewards stay the same. A boss panel with a challenger does not show the battle’s prize item, since that fight is against someone else.