Skip to content

sf2.game

Game-wide controls: shop, sale and reward prices, forge and battle timers, optional services such as ads and paid offers, optional shop tools, and switching Eclipse mode on and off. Get sf2 with local sf2 = require("sf2").

Scale shop prices, upgrade prices and fight coin rewards, add gems to the fight reward tally, and let the player sell items.

Signature: sf2.game.economy { option?, choice?, shop_coins?, shop_gems?, upgrade_coins?, upgrade_gems?, reward_coins?, reward_gems?, sell_coins? }

Parameters

Parameter Type Required
definition EconomyModifier Required

Fields of EconomyModifier

Field Type Required Meaning
option string Optional One of this mod’s save options; give with choice.
choice string Optional A choice of option; the modifier applies only while the save has it.
shop_coins number Optional 0.01..10, default 1.
shop_gems number Optional 0.01..10, default 1.
upgrade_coins number Optional 0.01..10, default 1.
upgrade_gems number Optional 0..10, default 1; 0 removes gem upgrade prices.
reward_coins table<"story"|"survival"|"tournament"|"challenge"|"boss"|"final"|"ascension"|"replayable"|"periodic"|"raid"|"tutorial"|"other",number> Optional Fight kind = multiplier, 0..10.
sell_coins number Optional 0..1 share of an item’s value the shop pays when the player sells it. Selling is off unless a modifier that applies sets it.
reward_gems RewardGems Optional Gems added to the end-of-fight reward tally, only when the player wins.

Returns: nil.

When: Entrypoint.

sf2.game.economy { option = "difficulty", choice = "relaxed",
shop_coins = 0.85, upgrade_coins = 0.7, sell_coins = 0.25 }
sf2.game.economy { option = "difficulty", choice = "brutal",
reward_coins = { survival = 0.9 } }
-- 3 gems per perfect round, for a 10-hit combo and for Fantastic style,
-- in every fight the player wins except survival.
sf2.game.economy {
reward_gems = { perfect = 3, combo = 3, fantastic = 3, except = { "survival" } },
}

Give option and choice together (one of your own save options), or neither to always apply. Fight kinds for reward_coins and reward_gems.except are in Battle rules.

  • Every modifier that applies, including other mods’, is multiplied. Prices round to a whole number and never drop below 1, unless a multiplier of 0 removes the price (a removed gem price hides that payment button).
  • Changing the choice affects the next price shown and next reward; past purchases are not refunded.
  • Coin rewards are scaled after reward, combo and bonus coins are added. Gems, experience and items are unchanged by reward_coins.
  • reward_gems adds gems to the reward tally at the end of a fight the player wins; a loss, a surrender or a raid that runs out of time pays none of them, and its tally shows no gems. They appear on the Perfect, Combo and style lines and are paid with the fight’s other rewards. perfect is paid for each perfect round, combo once when the fight’s longest combo reaches combo_hits hits (10 unless set), and fantastic once when the player reaches Fantastic style. Unlike the multipliers, gems from several modifiers that apply add up.
  • The shop only offers to sell items while a modifier that applies sets sell_coins; with none, there is no Sell button. Several sell_coins values that apply are multiplied, and 0 switches selling off. Forge and economy explains what an item is worth.

Change forge order duration, or the time limit of timed battles and raids.

Signature: sf2.game.timers { subsystem, seconds?, endless?, skip_enabled?, complete_pending? }

Parameters

Parameter Type Required
definition TimerPolicy Required

Fields of TimerPolicy

Field Type Required Meaning
subsystem "forge"|"battle"|"raid" Required —
seconds integer Optional Seconds. Required unless endless. Forge 0-31536000; battle and raid 1-86400.
endless boolean Optional Battle and raid only: rounds have no time limit. Leave out seconds.
skip_enabled boolean Optional Forge only; leave true for battle and raid.
complete_pending boolean Optional Forge only; leave false for battle and raid.

Returns: nil.

When: Entrypoint.

sf2.game.timers { subsystem = "forge", seconds = 0, complete_pending = true }
sf2.game.timers { subsystem = "battle", seconds = 150 }
sf2.game.timers { subsystem = "raid", endless = true }

Only one mod may set the policy for each subsystem; a second one fails loading.

Battle and raid. The policy replaces each timed fight’s round_time when a round starts; training and untimed fights are unchanged. "raid" overrides "battle" for raid fights (including mod Underworld pages and kind = "raid" modes). skip_enabled and complete_pending are forge-only. An endless round hides the clock and ends only on defeat or a rule, but elapsed time still counts. seconds of 999 or more hides the clock but does run out. A fight-prepare plan can still set round time afterwards.

Forge. With complete_pending = true, orders already running finish at the next delivery update and the game saves; materials are not charged again. With false, they keep their saved deadlines. Disabling the mod before an order settles restores its original time. Completing an order still rolls its enchantment, and if nothing qualifies at that moment the order closes without refunding materials.

Switch the story map between normal and Eclipse mode, like the map’s own Eclipse button.

Signature: sf2.game.set_eclipse_mode(enabled)

Parameters

Parameter Type Required
enabled boolean Required

Returns: true if the requested mode is now active (including already being in it); false if the switch did not happen, for example while the game’s own story quests are still running. After false, do not assume the mode is unchanged.

When: From a player-action or story callback on the story map. Raises an error in UI on_close cleanup.

local function continue_in_normal_mode(view)
if sf2.game.set_eclipse_mode(false) then
sf2.ui.close(view)
end
end

This follows the game’s own switch rules: it does not unlock Eclipse mode or skip its tutorial.

Re-run the game’s swap between normal battles and their Eclipse counterparts.

Signature: sf2.game.refresh_eclipse_battles()

Returns: true when it ran; false when no profile is loaded or a profile or screen change is in progress.

When: After a profile has loaded, e.g. from a session story event handler.

sf2.story.on("session", function()
sf2.map.reveal { battle = "training" }
sf2.map.reveal { battle = "training_eclipse" }
sf2.game.refresh_eclipse_battles()
end)

Applies to every battle with an eclipse_toggle_name (see sf2.battles.register). A pair is skipped until the normal battle’s last fight has been won. The normal entry is then hidden in Eclipse mode and shown otherwise, and the counterpart the reverse. Call this after revealing a pair whose normal battle is already complete; the game’s own switches only start after the Eclipse replay tutorial (or the Act VI final battle).

Switch off groups of optional service features, such as ads or paid offers.

Signature: sf2.game.disable { name, ... }

Parameters

Parameter Type Required
services ("paid_offers"|"battle_pass"|"ads"|"rewarded_video"|"online_services"|"payments")[],One or more service groups to switch off. Required

Returns: nil.

When: Entrypoint.

sf2.game.disable { "ads", "battle_pass" }

This can only switch features off. Disabling a service the offline build already lacks may have no visible effect.

Switch on optional features: shop search and sorting, and the weapon lab’s weapon mechanics.

Signature: sf2.game.enable { name, ... }

Parameters

Parameter Type Required
features ("shop_search"|"shop_sort"|"charge_attacks"|"polearm_tip"|"scythe_execute"|"kusarigama_pull"|"katars_point_first")[],One or more optional features to switch on. Required

Returns: nil.

When: Entrypoint.

sf2.game.enable { "shop_search", "shop_sort" }
Name What it turns on
shop_search A Search button in the shop, and an Equipped button that jumps to the item being worn (shop_sort adds this too). See Forge and economy.
shop_sort Sorting on the equipment tabs, and a subtype filter on the weapon, ranged and magic tabs.
charge_attacks Weapon lab: holding the forward slash charges it.
polearm_tip Weapon lab: spears and polearms hit hardest at the tip.
scythe_execute Weapon lab: a scythe hit knocks out an opponent under 10% health.
kusarigama_pull Weapon lab: the Kusarigama’s forward slash pulls the opponent in.
katars_point_first Weapon lab: Katars win weapon clashes against all but heavy weapons.

If several mods enable features, all of them are on. None of them affects a save. The shop tools only change how menus look. The weapon lab mechanics change fights: every fight while the mod is on, online included. Options has no switches for them. See Weapons.