Skip to content

Add Weapon to Characters

Kakrain edited this page Jun 15, 2026 · 4 revisions

Distribute Weapon to Holy 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.

Step 1 -> Select your weapon.

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!

Step 1 -> Select the single items

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:


Step 2 -> Select Characters

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.


Check in Game

  1. Open the Kenshi Launcher
  2. Ensure MySuperWeapon is enabled
  3. Start the game
  4. Check all holy characters.

Clone this wiki locally