Your first mod
This guide makes a small mod that changes the warrior and adds a new unit. It takes a few minutes and shows the files that most mods use.
1. Install PolyMod
Install PolyMod with the PolyMod Launcher and start the game once from the launcher. PolyMod then makes the Mods folder in the game folder.
2. Make the mod folder
Make a folder Mods/first_mod and add a manifest.json:
{
"id": "first_mod",
"name": "My First Mod",
"version": "1.0.0",
"authors": [
"YourName"
]
}
The id can only contain lowercase letters and underscores. See Manifest.
3. Change a vanilla value
Add a patch.json that gives the warrior 3 attack instead of 2:
{
"unitData": {
"warrior": {
"attack": 30
}
}
}
Unit attack, defence and health are stored as ten times the value that the game shows, so 30 is 3 attack. See UnitData.
Start the game and train a warrior. Its attack is now 3. Open the PolyMod Hub with Ctrl + Tab to see that your mod has the status Success.
4. Add a new unit
Extend patch.json to add a new unit and let the Imperius tribe train it with the Riding tech:
{
"unitData": {
"warrior": {
"attack": 30
},
"lancer": {
"idx": -1,
"health": 100,
"defence": 10,
"movement": 2,
"range": 1,
"attack": 25,
"cost": 4,
"weapon": "sword",
"unitAbilities": [
"dash",
"fortify",
"land"
],
"movementTerrain": [
"field",
"forest",
"mountain"
]
}
},
"techData": {
"riding": {
"unitUnlocks": [
"+lancer"
]
}
}
}
"idx": -1tells PolyMod thatlanceris new content. PolyMod gives it a free index when the game starts."+lancer"addslancerto the existingunitUnlocksarray of the Riding tech instead of replacing the whole array. See Merge rules.- All ids are lowercase.
5. Give it a name
The game shows a new unit by its localization key, unit.names.lancer. Add a localization.json:
{
"unit_names_lancer": {
"English": "Lancer",
"German (Germany)": "Lanzenreiter"
}
}
Underscores in the key become dots. See Localization.
6. Give it a look
Without a prefab, a new unit uses a fallback look. To build a real look, add a unit prefab and textures. The easiest way is to start from a dumped vanilla prefab:
- Turn on debug mode in the hub config, open the hub again, and press Dump. See Debugging and dumping.
- In
DumpedData/Prefabs/prefabs.json, copy the entry of a unit whose shape you like. - Save it as
unitPrefab_lancer.jsonin your mod, and changeskinnedKey.unitTypetolancer. - Change the
defaultSpriteNameof the visual parts to your own names, and add.pngfiles with those names.
7. Share it
Zip the contents of Mods/first_mod (so that manifest.json is at the root of the archive) and rename the archive to first_mod.polymod. Players put that file in their Mods folder.
Next steps
- GLD patching: all merge rules, new tribes, skins and PolyMod-only fields.
- Game logic data reference: every GLD section and field.
- PolyScripts: change game code with C#.