Skip to content

sf2.forge

The forge is where the player upgrades equipment with perks. Register price profiles and recipes, look up the ones that already exist, or patch them. Get sf2 with local sf2 = require("sf2").

Create a forge price profile, or a recipe that turns an item and a perk into an upgraded item.

Signature: sf2.forge.register { id, prices } for a price profile, or sf2.forge.register { id, alias?, profile, items, candidates } for a recipe

Parameters

Parameter Type Required
definition ForgePriceProfile|ForgeRecipe Required

Fields every kind shares (ForgePriceProfile, ForgeRecipe)

Field Type Required Meaning
id string Required —

More fields of ForgePriceProfile

Field Type Required Meaning
prices ForgePriceTable[] Required —

More fields of ForgeRecipe

Field Type Required Meaning
alias string Optional —
profile string|ForgeProfileHandle Required —
items ForgeItem[] Required —
candidates ForgeCandidate[] Required —

Returns: A price-profile handle or a recipe handle.

When: Loading; register a profile before recipes that use it.

local abilities_price = sf2.forge.register {
id = "abilities",
prices = {
{ equipment = "weapon", rows = {
{ max_level = 2, materials = { 38, 10, 5 } },
{ level = 3, materials = { 46, 13, 6 } },
{ min_level = 4, materials = { 56, 17, 8 } },
} },
},
}

Give prices for a profile, or profile, items and candidates for a recipe; both or neither is an error. See the forge guide.

A profile sets how many of each forge material one enchantment costs, by the player’s level (not the item’s). Only your mod’s recipes use it; core profiles keep their prices. The first row whose range contains the level wins. Cover every player level: if no row matches, the enchantment is free. Enchanting is instant.

profile is a handle from sf2.forge.get or one registered in this mod. A recipe can only use equipment categories its profile prices. Each candidates entry names a perk (from sf2.perks.register) and an equipment category.

local recipe = sf2.forge.register {
id = "training_recipe",
profile = sf2.forge.get("Simple"),
items = { { equipment = "weapon", enchantments = 1 } },
candidates = { { perk = training_perk, equipment = "weapon", min_level = 1, max_level = 52 } },
}

A new recipe does not change core pools or costs; use sf2.forge.patch for that.

Change an existing forge recipe, perk offer, or price profile without replacing it.

Signature: sf2.forge.patch { recipe, selection?, tiers? }, sf2.forge.patch { recipe, perk, equipment?, price?, unlock?, locked_text? }, sf2.forge.patch { profile, equipment, deviation = { minimum, maximum } }, sf2.forge.patch { profile, perk, equipment, exclude = true } or sf2.forge.patch { profile, perk, equipment, include = true | { min_level?, max_level?, min_deviation?, max_deviation?, before? } }

Parameters

Parameter Type Required
definition ForgeRecipeSelection|ForgeCandidateSettings|ForgeProfilePatch Required

Fields of ForgeRecipeSelection

Field Type Required Meaning
recipe string|ForgeProfileHandle|ForgeRecipeHandle Required Recipe name, qualified ID, or a recipe handle.
selection "random"|"choose" Optional Default “random” (the original roll); “random” changes nothing.
tiers ForgeChoiceTier[] Optional Required for “choose”: 1-5 tiers in display order.

Fields of ForgeCandidateSettings

Field Type Required Meaning
recipe string|ForgeProfileHandle|ForgeRecipeHandle Required Recipe name, qualified ID, or a recipe handle.
perk string|PerkHandle|EnchantmentHandle Required Perk or scripted enchantment handle, or a qualified perks/… or enchantments/… ID.
equipment "weapon"|"armor"|"helm"|"ranged"|"magic" Optional Omitted: every equipment category of the recipe.
price number Optional Price multiplier 0.01-100, default 1.
unlock ForgeCandidateUnlock Optional —
locked_text string|LocalizationHandle Optional Shown while the candidate is locked.

Fields of ForgeProfilePatch

Field Type Required Meaning
profile string|ForgeProfileHandle Required —
equipment "weapon"|"armor"|"helm"|"ranged"|"magic" Required —
perk string|PerkHandle Optional Needed with exclude or include.
deviation ForgeDeviationRange Optional Replaces the deviation range for the equipment kind.
exclude true Optional Removes the perk from the profile’s candidates.
include true|ForgeInclusion Optional Adds a perk the recipe does not offer; a table limits it.

Returns: nil.

When: Loading.

local sf2 = require("sf2")
sf2.forge.patch {
profile = sf2.forge.get("Complex"),
perk = sf2.perks.get("core:perks/PERK_MONK_SET_WHIRL"),
equipment = "weapon",
exclude = true,
}

The fields you give pick the form: recipe with selection/tiers, recipe with perk, profile with deviation, or profile with perk and exclude or include. Giving both recipe and profile, or neither, is an error. Two patches that target the same thing conflict, even across mods. Enchantments already made keep their power. See How the forge works.

Removes a core enchantment from one core recipe’s pool for one equipment category. Enchantments already on equipment and prices are unchanged, and so are mod-added candidates. The perk must actually be in that pool.

Adds an existing perk (core or your own) to a core recipe’s pool for one equipment category. Use include = true, or a table with min_level/max_level, min_deviation/max_deviation (the deviation pair must be given together) and before. Without the deviation pair the perk rolls the recipe item’s own power range, which can differ from the recipe’s native candidates.

An included perk is listed after the recipe’s own candidates. before (a perk handle or ID) lists it just in front of one of them instead, in the choose list and in the list of possible enchantments. That perk must be in the recipe’s pool for this category; if a patch excludes it, the included perk still keeps that place. The order does not change the odds of a random roll.

sf2.forge.patch {
profile = sf2.forge.get("Complex"),
perk = my_set_enchantment,
equipment = "weapon",
include = { before = sf2.perks.get("core:perks/PERK_DIRECTOR_SET_PLOT_TWIST") },
}
sf2.forge.patch {
profile = sf2.forge.get("Medium"),
perk = sf2.perks.get("core:perks/PERK_ITEM_SPECIAL_SHOCK"),
equipment = "weapon",
include = { min_deviation = -30, max_deviation = 30 },
}

Deviation only applies to categories with random power (Simple, Medium). Including and excluding the same target conflicts, as does including a perk the recipe already offers.

deviation changes the random power added on top of the base enchantment power for one equipment category of a core recipe; prices and timers stay. Only Simple and Medium are supported. Keep maximum at 134 or less: a saved enchantment 135 or more above its level’s base is reset to base + 30.

sf2.forge.patch {
profile = sf2.forge.get("Simple"),
equipment = "weapon",
deviation = { minimum = 15, maximum = 75 },
}

selection = "choose" with tiers lets the player pick exact enchantments and a strength tier instead of rolling at random; the price follows the picks. When the pick is a combo enchantment, an All gear button also lets the player apply it to every worn piece that can take it in one go, for the sum of those pieces’ prices. recipe can be a short core name ("Simple"), a qualified ID, or a handle from sf2.forge.get or sf2.forge.register. "random" is the default and cannot undo another mod’s choose setting.

A tier’s strength is the share of the item’s full enchantment power for its level that it gives: 1 is the power a shop item of that level carries in list.xml, 0.5 half of it. The recipe’s random deviation range is not used. price multiplies the cost. The tier id is saved with timed orders, so do not rename it after release.

sf2.forge.patch {
recipe = "Simple",
selection = "choose",
tiers = {
{ id = "low", name = sf2.text.get("forge.tier.low"), strength = 1 / 3, price = 0.5 },
{ id = "high", name = sf2.text.get("forge.tier.high"), strength = 1.0, price = 2.0 },
},
}

recipe with perk sets a price multiplier and an optional unlock for one candidate of a choose recipe. The recipe must be switched to "choose" by this mod or one loaded earlier (call order in your script does not matter). Omit equipment to apply to every category; a category-specific setting wins. A perk not in the pool is accepted but does nothing.

unlock = { defeated = { ... } } keeps the candidate locked until the player has beaten any one of the listed opponents (fighter handles or qualified IDs). Core story opponents, including bosses, are named by template, such as core:warrior-templates/hermit_swords. See sf2.profile.has_defeated. A set (combo) enchantment also stays locked until the player owns the whole set.

sf2.forge.patch {
recipe = "Complex",
perk = sf2.perks.get("core:perks/PERK_HERMITSTORM"),
price = 1.5,
unlock = { defeated = { "core:warrior-templates/hermit_swords" } },
locked_text = sf2.text.get("forge.locked.hermit"),
}

Look up a forge price profile, such as a core one, by ID.

Signature: sf2.forge.get(reference)

Parameters

Parameter Type Required
reference string Required

Returns: A price-profile handle.

When: Loading.

local economy = sf2.forge.get("Simple")

A short name is read as "core:forge-profiles/<name>"; "Complex" is the other core profile. An unknown profile fails loading. The handle is an input for recipes, not editable prices; for your own prices use sf2.forge.register.