Repository navigation
Add Weapon to Characters
This guide walks you through writing a specific kind of .patch.
You will learn:
- How to select a single specific record
- How to add References to multiple records.
This time, let us assume you made a super awesome sword.
You want to add your sword to all characters which already have the Holy Flame
Your mod named this time MySuperWeapon.mod contains the weapon Holy Bonk with stringId 10-MySuperWeapon.mod
The the Holy Flame is an ITEM with stringId 42322-changes_otto.mod
You will notice:
Some CHARACTERs have this item referenced in its inventory
So, let's cook!
Open MySuperWeapon.patch in a text editor and write:
sword:=(MySuperWeapon.mod)(E:WEAPON|GetField("_stringId_")=="10-MySuperWeapon.mod")
holy_flame:=(all)(E:ITEM|GetField("_stringId_")=="42322-changes_otto.mod")
What this does:
| Text | Meaning |
|---|---|
| (MySuperWeapon.mod) | This time, i don't want to search everywhere, just in my mod. |
| E: | I only need 1 record, so only returns the first record it finds |
| GetField("_stringId_") | searches specifically for the string id. |
If everything is correct, the log should tell you, you found 1 record of each:
This time we will add a couple of additional lines:
sword:=(MySuperWeapon.mod)(E:WEAPON|GetField("_stringId_")=="10-MySuperWeapon.mod")
holy_flame:=(all)(E:ITEM|GetField("_stringId_")=="42322-changes_otto.mod")
holy_characters:=(all)(A:CHARACTER|hasAnyAsExtraData(holy_flame,"inventory"))
holy_characters->AddExtraData(sword,"weapons",[1,0,100])
hasAnyAsExtraData is a function that requires a record group (this time only holy_flame) and a category as string ("inventory") and returns true if any in the record group is referenced in that category
AddExtraData is a function that requires a record group (this time sword only) a category ("inventory") and sometimes a vector of 3 integers as arguments "[1,0,100]"
Rerun this Patch with KenshiPatcher.
Open this mod with FCS, you will be able to see the generated changes
This way, you could create a mod with a new weapon, and add it to all relevant vanilla characters but also distribute it to all modded characters with a KenshiPatcher patch.
- Open the Kenshi Launcher
- Ensure MySuperWeapon is enabled
- Start the game
- Check all holy characters.
-
Getting Started
-
Cookbook
-
Patch Language
-
Variable Types
-
Miscellaneous
-
Support