Make your first mod
You will make Training Blade, a katana that appears in the weapon shop at level 1 for one coin. You need Eclipse, a text editor and one sample image. You do not need Unity or a Lua installation; Eclipse runs the script for you.
If code is new to you, keep Lua basics open alongside this page. Copy each file first, get the mod working, then experiment. If you use VS Code, the editor extension can create all of these files for you with Create Mod.
1. Create the folder
Section titled “1. Create the folder”Open the game’s Mods folder (see Install and
enable mods if you are not sure where it is) and make a folder called
tutorial.blade. Inside it, create these folders and files:
Mods/ tutorial.blade/ mod.toml scripts/ main.lua localizations/ eng.toml assets/ sprites/ weapon.asset textures/ weapon.pngShow file extensions in your file manager so you do not end up with
main.lua.txt or mod.toml.txt. Save text files as UTF-8. mod.toml must be
directly inside the mod folder, with no extra folder around it.
2. Describe the mod
Section titled “2. Describe the mod”Create mod.toml:
schema = 1id = "tutorial.blade"name = "Training Blade"version = "1.0.0"authors = ["Your Name"]entrypoint = "scripts/main.lua"
[[dependencies]]id = "core"version = ">=2.0 <3.0"id is the mod’s permanent identity and name is what players see.
entrypoint names the first script to run. The core dependency lets your mod
reuse the game’s own katana model. How
mods work explains every field.
3. Name the weapon
Section titled “3. Name the weapon”Create localizations/eng.toml:
weapon.training_blade = "Training Blade"The left side is a key your script asks for. The right side is the text players
see. To translate the name later, add another file such as pol.toml with the
same key. For this first test, select English in the game.
4. Add the shop image
Section titled “4. Add the shop image”Download the sample weapon PNG
and save it as assets/textures/weapon.png. If your browser opens the image,
use Save image as and keep the .png extension.
Create assets/sprites/weapon.asset:
type=spritetexture=textures/weapon.pngpixels_per_unit=100A texture is the picture file. A sprite tells the game how to use a
picture. The texture line points at the PNG, starting inside assets/. The
.asset file is a small text file, not a Unity file. The PNG becomes the shop
icon. The weapon in the fight looks like the katana model you borrow in the next
step.
5. Register the weapon
Section titled “5. Register the weapon”Create scripts/main.lua:
local sf2 = require("sf2")
sf2.items.register { category = "weapon", id = "training_blade", display_name = sf2.text.get("weapon.training_blade"), icon = sf2.assets.sprite("sprites/weapon"), model = sf2.assets.model("core:gamedata/models/mdl_weapon_katana_ritual"), subtype = "Katana", shop = { level = 1, price = { coins = 1 } },}
sf2.log.info("Training Blade registered")What the script does:
require("sf2")loads the Eclipse API into a variable calledsf2.sf2.items.registerwithcategory = "weapon"creates the item.sf2.text.getfinds the translated name from step 3.sf2.assets.spritefinds your sprite file (write the path without.asset).sf2.assets.modelborrows the core katana model. Keepsubtype = "Katana"with this model, because the subtype decides which moves the weapon uses.shopputs the weapon in the weapon shop from level 1, andprice = { coins = 1 }makes it cost one coin. Withoutshop, the weapon exists but nobody can buy it.sf2.log.infowrites a line to the game log so you can tell the script reached the end.
The weapon’s full ID becomes tutorial.blade:items/weapon/training_blade.
register also returns a handle, a value standing for the item. This script
does not need it, but you can keep it for later with
local blade = sf2.items.register { ... } to use the weapon in a reward or a rule.
6. Turn it on and test it
Section titled “6. Turn it on and test it”- Start Eclipse and open Mods on the title screen.
- Switch on Training Blade. Open Details if it reports a problem, then choose Apply & Restart.
- Enter Campaign and open the weapon shop. Use a profile that has reached the shop.
- Buy Training Blade for one coin, equip it and enter a fight. It uses the borrowed katana model.
If something fails, see Troubleshooting.
A missing mod usually means the folder or mod.toml is wrong. A listed mod with
an error usually means a dependency, a script line, a translation key or a file
path needs fixing.
7. Make one change
Section titled “7. Make one change”Exit the game, change the name in eng.toml and launch again. The shop shows the
new name. Next, change the price from 1 to 5. Saving a script never updates
a running game; restart to see changes (while developing, F9 reloads
your Lua).
To share the mod, change the folder name, id, name and authors. Use a
unique ID such as yourname.training, and keep it and the item’s local ID the
same once other people use them, because saves refer to them.
Where to go next
Section titled “Where to go next”- Different ways to make a weapon, including an in-game editor: Weapons.
- Give it a special ability: Perks and enchantments.
- A fight against a character of your own: Story battles.
- Every function, with a working example: the items reference and the other pages under Reference.