Skip to content

Battles and bosses

This tutorial starts with the smallest possible fight and grows it step by step into a boss battle. Each step is a complete script you can run. It assumes you have finished Your first mod and know what a manifest and entry script are. No art downloads are needed: every example reuses the game’s own fighter and arena.

Piece What it is
Page A map page: a background picture that holds battle buttons.
Battle The button the player taps on a page. It opens a panel with a title and description.
Fight One match inside a battle. A battle has one or more fights, played in order.
Opponent A character the player fights. A fight lists one or more.
Fighter A reusable character blueprint that opponents can inherit from.
Location The arena a fight takes place in.

Opponents, rules and rewards are plain tables written inline, right where they are used, so one sf2.battles.register call describes a whole battle. You only create separate objects for things other content refers to: pages, fighters, locations and battles.

Register calls return handles: values that stand for what you registered. Register something before you use its handle. Everywhere a handle is accepted you may also pass the ID string.

Add this to your entry script. It registers a one-round fight against a core fighter, in a small arena built from core art.

local sf2 = require("sf2")
local title = sf2.text.register { id = "battle.training", language = "eng", value = "Sparring Practice" }
local about = sf2.text.register { id = "battle.training.about", language = "eng", value = "Win one round against a training opponent." }
local partner = sf2.text.register { id = "opponent.partner", language = "eng", value = "Sparring Partner" }
local arena = sf2.world.register {
id = "training_arena", color = "#1b2230",
layers = {
{ images = { {
sprite = sf2.assets.sprite("core:textures/locations/battlefield/battlefield_bg1.back_1"),
width = 1936, height = 1024,
} } },
{ fighters = { player_x = 868, enemy_x = 1068 } },
},
}
local page = sf2.map.register { id = "training", art = "Map1.1" }
local battle = sf2.battles.register {
id = "training", page = page, x = 0, y = 0,
title = title, description = about, location = arena,
fights = { {
rounds = 1,
opponents = { {
fighter = "core:warrior-templates/default",
first_name = partner, level = 1, tactic = "Standard",
} },
} },
}
sf2.modes.register { id = "training", fights = battle.fights, repeatable = true }
sf2.story.on("session", function()
sf2.map.reveal { battle = battle }
end)

What each part does:

  • Text handles come from sf2.text.register. Any field that shows text accepts a handle (so the text follows the player’s language) or a plain string.
  • Layers in an arena are listed back to front. The layer with fighters is where the fighters stand; layers after it draw in front of them.
  • The page is a map page. "Map1.1" is the Act I background; the other story backgrounds are Map1.2, Map1.3, Map2.4, Map2.5, Map2.6 and Map3.7. Battle x and y are positions on the page, not picture pixels.
  • The core fighter gives the opponent its look and starting equipment. tactic picks its fighting style; the warriors catalog lists the built-in ones.
  • A mode wraps the fight so the player can replay it. battle.fights is the list of fight handles the battle call created, in order.
  • Registering a battle does not put it on a save that already exists. A session handler runs when a game session starts, and sf2.map.reveal creates the map entry. Repeating the reveal is harmless.

Restart Eclipse, enable the mod, enter Campaign and look for Sparring Practice on the map. If the entry is missing, open Details in the mod menu; see Troubleshooting.

A fight’s rewards table is keyed by wins: how many opponents the player beat. [0] is a loss and [1] is beating the first opponent.

fights = { {
rounds = 1,
opponents = { { fighter = "core:warrior-templates/default", level = 1 } },
rewards = {
[0] = { experience = 10 },
[1] = { gems = 10, experience = 300,
items = { { item = sf2.items.get("core:items/weapon/WEAPON_KATANA") } } },
},
} }

A reward can hold gems, experience (a point count, not a level), a list of guaranteed items, choices (weighted item picks), forge-material currencies, a lottery (a chest the player opens after a win, drawing one prize such as an item, orbs or coins) and resistances. The fight shows the reward of its highest key on the map. A missing key pays nothing, and an empty {} is an error, so leave the key out instead. With several opponents and one round each, keys run from [0] to [n]. Every field is listed in sf2.battles.register.

A lottery is pure chance by default. To make a rare prize come sooner the longer a player goes without it, mark its slots pity = true and give the lottery a pity in percentage points: every draw that misses those slots adds that much to their chance next time, and drawing one starts the count again.

lottery = { pity = 3, slots = {
{ item = monk_belt, pity = true },
{ coins_scale = 1 }, { coins_scale = 2 }, { currency = "ForgeMaterial1", scale = 1 },
} }

Players who already own an item are not given it twice by a reward. Your mod’s consumables are the exception: a fight can drop them every time, and a stackable consumable can drop several pieces at once with count, such as { item = elixir, count = 2 }. To grant an item some other way, see sf2.profile.give_item, and do not use both for the same prize.

A boss battle is several fights in a row. Give the boss a reusable fighter, then reuse it with different levels. Replace the battle from step 1 with this:

local boss = sf2.fighters.register {
id = "ember_master", fighter = "core:warrior-templates/default",
first_name = "Ember Master", voice = "Male", skeleton = "SkeletonHeavy",
items = { sf2.items.get("core:items/weapon/WEAPON_KATANA") },
tactic = "Aggressive",
}
local battle = sf2.battles.register {
id = "ember_boss", page = page, type = "bosses", x = 300, y = 150,
title = title, description = about, location = arena,
music = "fight1_samurai_spirit",
fights = {
{ name = "guards", rounds = 2, round_time = 60,
opponents = {
{ fighter = "core:warrior-templates/default", level = 10 },
{ fighter = "core:warrior-templates/default", level = 12 },
},
rewards = { [2] = { gems = 5, experience = 500 } } },
{ name = "master", rounds = 3, round_time = 99,
opponents = { { fighter = boss, level = 15 } },
rewards = { [1] = { gems = 20, experience = 1500 } } },
},
}

Things to know:

  • Items replace, they do not add. A fighter that sets items lists everything it wears, and an opponent that sets items replaces its fighter’s list. Set skeleton as well so the body is not lost.
  • Every other fighter field is inherited one by one. An opponent can override just level or perks and keep the rest.
  • type is the game’s battle category ("story" by default, "bosses", "survival", "final", and others). Pick the one whose look and behaviour you want.
  • rounds is how many rounds the fight lasts (default 3) and round_time is seconds per round (default 99).
  • music takes a native track name or an audio handle from sf2.assets.audio. location can be a core arena such as "core:locations/dojo"; the locations catalog lists them.
  • Name fights if you ever plan to add or reorder them. A fight’s ID is <mod id>:fights/<battle id>_<name>; unnamed fights are numbered 1, 2, and so on.

To give an opponent core perks with tuned settings, list them in perks: each entry is a perk handle, or { perk = ..., chance = 0.3, aspect = 100000 } to change how strongly it triggers for that opponent only.

perks = {
sf2.perks.get("core:perks/PERK_HERMITSTORM"),
{ perk = sf2.perks.get("core:perks/PERK_ITEM_SPECIAL_ENFEEBLE_RANGED"), chance = 0.26 },
}

To show the player a speech before the master fight, see Story events.

A rule changes how one fight plays: no perks, a hot floor, a regenerating boss, or your own Lua. Rules are tables in the fight’s rules list:

{ name = "master", rounds = 3,
opponents = { { fighter = boss, level = 15 } },
rules = {
{ kind = "no_perks", target = "player" },
{ kind = "regeneration", rate = 0.001, frames_after_hit = 180, target = "opponent" },
} }

Battle rules lists every kind and shows how to write your own.

Step 5: more than one page, and the campaign’s own map

Section titled “Step 5: more than one page, and the campaign’s own map”

A mod can add as many pages as it likes with sf2.map.register, each with its own art (a core name or your own sprite). The page marked start = true is where a new map begins.

Your pages come after the campaign’s unless you place them. To hide a secret battle to the left of Act 1, register its page with before = "core:zones/zone_1" and secret = true. A secret page has no dot on the strip under the map, and the map never opens on it, so players find it only by swiping past Act 1. A secret page may also hold no battle at all, which makes an empty stretch to cross first:

local gap = sf2.map.register { id = "gap", art = void_art, before = "core:zones/zone_1", secret = true }
local hideout = sf2.map.register { id = "hideout", art = hideout_art, before = gap, secret = true }
-- Put the battle on `hideout` and reveal it as usual.

To put a battle on one of the campaign’s pages instead, look the page up with sf2.map.get and add core as a dependency in your manifest:

local act1 = sf2.map.get("core:zones/zone_1")

(Check the page ID in the story map catalog.) You can also change the core game. sf2.battles.patch moves a core battle, swaps a fight’s opponents, music or arena, adds or replaces rules, and edits item drops:

sf2.battles.patch { battle = "core:battles/zone_6/duel", 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 = "no_perks", target = "opponent" } },
}

Prefer append_rules to rules: appended rules combine with other mods’ rules, while rules replaces the whole list and conflicts with anyone else touching it. See Sharing mods.

Map buttons, previews and Eclipse variants

Section titled “Map buttons, previews and Eclipse variants”
  • preview is the picture in the battle panel (484 by 274 pixels fills it). Pass a sprite handle for your own art.
  • icons = { base = ..., active = ..., pressed = ... } replaces the round map button with your sprites (300 by 300 pixels). Supply active, or the selected state has no art. pressed is optional: it shows while the button is held; without it the button darkens.
  • To pair a normal battle with an Eclipse variant on the same page, set the normal entry’s eclipse_toggle_name to the variant’s runtime name, sf2.mod.id .. ":battles/<variant id>". Give the variant its own fights. See sf2.game.refresh_eclipse_battles for when the swap happens.

The Underworld is the game’s second map, full of boss pages. Set underworld = true on a page and your bosses appear there, even with a Power Mode variant. That is the next guide: Underworld, modes and raids.

Saved progress finds your fights by page, battle and fight ID together. Once players have your mod, do not rename or reorder existing ids, battles or fights; add new ones instead. Sharing mods explains how to update safely.

  • A battle holds 1 to 100 fights, and a fight 1 to 64 opponents.
  • rewards keys must fit the fight: [0] and [1] for one opponent, up to [n] for n opponents with one round each.
  • Unknown fields are errors that name the position, such as sf2.battles.register fights[2].opponents[1], so a typo is easy to find.