Melee Weapon Def

From RimWorld Modding Wiki
Jump to navigation Jump to search

Both theory and practice will be covered in this page. A full tutorial that shows step-by-step what to do, and explain why.

You will learn how to make your own craftable melee weapon, which is something a lot of people start with.
You will make a mini-mod, only including this Def as content. And you will be able to test it in-game!

Requirements

Folders

Make a basic folder structure, containing the About, Defs, and Textures folders.
Make an About file under the About folder.

Def content

Use your XML editor to create an XML file under the Defs folder.
We will be making a ThingDef very similar to vanilla's Mace.
Remember that ThingDefs are used for a lot of things, a power generator building doesn't have tags for attack power and cooldown because it doesn't need it, right? However, if we are making an equippable weapon, we must add those required tags. WARNING: Only the most used tags will be covered.

<?xml version="1.0" encoding="utf-8"?>
<Defs>
<ThingDef ParentName="BaseMeleeWeapon_Blunt_Quality">
    <defName>CustomPrefix_Sledgehammer</defName><!--REQUIRED!-->
    <label>sledgehammer</label><!--REQUIRED!-->
    <description>A heavy, long tool used mainly for construction tasks, but can also serve as a slow but powerful weapon.</description><!--REQUIRED!-->
    <possessionCount>1</possessionCount>
    <graphicData><!--REQUIRED!-->
      <texPath>Things/Item/Equipment/WeaponMelee/Mace</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <uiIconScale>1.1</uiIconScale>
    <techLevel>Industrial</techLevel><!--REQUIRED!-->
    <costStuffCount>100</costStuffCount>
    <statBases> <!--REQUIRED-->
      <WorkToMake>10000</WorkToMake>
      <Mass>4</Mass>
    </statBases>
    <equippedAngleOffset>-65</equippedAngleOffset>
    <recipeMaker>
      <researchPrerequisite>Smithing</researchPrerequisite>
      <skillRequirements>
        <Crafting>5</Crafting>
      </skillRequirements>
      <displayPriority>400</displayPriority>
    </recipeMaker>
    <stuffCategories>
      <li>Metallic</li>
    </stuffCategories>
    <weaponTags>
      <li>MedievalMeleeDecent</li>
    </weaponTags>
    <weaponClasses>
      <li>Melee</li>
    </weaponClasses>
    <tools> <!--REQUIRED!-->
      <li>
        <label>handle</label>
        <capacities>
          <li>Poke</li>
        </capacities>
        <power>9</power>
        <cooldownTime>2.3</cooldownTime>
      </li>
      <li>
        <label>head</label>
        <labelUsedInLogging>false</labelUsedInLogging>
        <capacities>
          <li>Blunt</li>
        </capacities>
        <power>18</power>
        <cooldownTime>2.5</cooldownTime>
      </li>
    </tools>
 </ThingDef>
</Defs>

Breakthrough

All elements labeled as "Required" are mandatory, the rest should be used only when necessary.

Tags Explanation
<?xml version="1.0" encoding="utf-8"?>
XML_Basics#Prolog
<Defs>...</Defs>
The root element. A group of Defs. We can put as many Defs as we want inside our root element, or we can separate them in different XML files. This would be only for organization.
<ThingDef ParentName="BaseMeleeWeapon_Blunt_Quality">...</ThingDef>
ThingDef is the type of Def used for most things, including weapons. BaseMeleeWeapon_Blunt_Quality is our Parent Def, our Def will inherit all the tags from it (unless specified not to). This Parent Def has a lot of necessary tags to make our ThingDef be used as an equippable weapon, like making it have Quality, as well as adding base values for stats if we don't specify them, like a base Flammability stat of 1 and Beauty of -3.
<description>A heavy, long tool...</description>
Required. Self-explanatory. The description of our ThingDef.
<graphicData>
 <texPath>Things/Item/Equipment/WeaponMelee/Mace</texPath>
 <graphicClass>Graphic_Single</graphicClass>
</graphicData>
Required. graphicData is a set of parameters that handle the textures of something, in this case our item/weapon. It has two main parameters: textPath and graphicClass.

textPath has the exact location of our item.
graphicClass is the type of graphic that we need. The ones you will see the most are Graphic_Single and Graphic_StackCount, the former refers to using one single texture, and the latter for multiple textures based on how many items are stacked in one place.

<uiIconScale>1.1</uiIconScale>
Expands or shrinks the size of the texture when shown as an icon. Useful if your texture is a bit small. If not specified, the value will be 1.
<techLevel>Industrial</techLevel>
TechLevel is a fixed list of fixed values. The available TechLevels are Undefined, Animal, Neolithic, Medieval, Industrial, Spacer, Ultra, Archotech. They are used for item generation. In this case, since a sledgehammer is not a medieval weapon, we will be using Industrial.
<costStuffCount>100</costStuffCount>
This tag works together with <stuffCategories>. As well as having the category, we need the amount.
<statBases>
   <WorkToMake>10000</WorkToMake>
   <Mass>4</Mass>
</statBases>
There are hundreds of available stats. Following vanilla's steps, we will only have custom <WorkToMake> and <Mass> to something in-between base game's mace and Royalty's Warhammer.
<equippedAngleOffset>-65</equippedAngleOffset>
A number that rotates the texture by a number of degrees.
<recipeMaker>
  <researchPrerequisite>Smithing</researchPrerequisite>
  <skillRequirements>
    <Crafting>5</Crafting>
  </skillRequirements>
  <displayPriority>412</displayPriority>
</recipeMaker>
To make something craftable, we need recipes. There are two ways: making a RecipeDef, or using a <recipeMaker> tag. The latter will take care of the recipe in-game in a simpler way. It has the following child tags:
researchPrerequisite refers to the research projet needed to craft the item. <skillRequirements> is a list of Skills and its level. In this case, the recipe requires a Crafting skill of level 5. <displayPriority> is the order of the recipe when it appears on the list of craftable items. The gladius uses a priority of 410, so our priority will make our sledgehammer appear later on the list.
<stuffCategories>
  <li>Metallic</li>
</stuffCategories>
A list of StuffCategoryDefs. It refers to the category of a material, like Metallic (steel, uranium, plasteel, etc), Woody (wood), Stony (several stone types), Fabric (cloth, devilstrand, etc), and Leathery (several leather types).
<weaponTags>
  <li>MedievalMeleeDecent</li>
</weaponTags>
This is a list of arbitrary text items that are later used when a humanlike pawn is spawned. For example, raiders from tribal factions spawn with "NeolithicMeleeBasic", while royal guards may spawn with "UltratechMelee".
We will still be using "MedievalMeleeDecent" because a lot of raiders use that one, so it saves us the task of introducing a new one into the system.
<weaponClasses>
  <li>Melee</li>
</weaponClasses>
This tag isn't that much important. They are mainly for ideoligion weapon preferences.
<tools>
      <li>
        <label>handle</label>
        <capacities>
          <li>Poke</li>
        </capacities>
        <power>9</power>
        <cooldownTime>2.3</cooldownTime>
      </li>
      <li>
        <label>head</label>
        <labelUsedInLogging>false</labelUsedInLogging>
        <capacities>
          <li>Blunt</li>
        </capacities>
        <power>18</power>
        <cooldownTime>2.5</cooldownTime>
      </li>
</tools>
tools is a list of "melee attacks" that something can perform. Weapons and races have tools. Each "attack" is enclosed by a li tag. Its child tags label, power, cooldownTime are self-explanatory, cooldownTime is on seconds. <labelUsedInLogging> prevents the label from being used in combat logs, usually used when it would sound silly or weird ("Patrick used the head of his hammer to hit Joe"). capacities defines which capacity to use, since capacities are a bit tricky to explain, check here for more information.

Textures