Custom Drug
In this simple RimWorld tutorial, we will create a custom drug, complete with its own hediff and sprite.
Goals[edit]
In this tutorial you will:
- Create ThingDefs for a new drug: xylin, a potent painkiller.
- Assign custom stackable textures to your new drug
- Create a new RecipeDef to craft xylin, yielding this new drug
Folder Setup[edit]
First, you will want to set up your mod folder in this order:
Mods
└ MyModFolder
├ About
│ └ About.xml
├ Defs
│ └ ThingDefs_Items
│ └ ExampleItem_Xylin.xml
└ Textures
└ ExampleMod
└ Xylin
├ Xylin_a.png
└ Xylin_b.png
About.xml[edit]
The about.xml is used to register the mod with RimWorld; the template below should act as a baseline.
<?xml version="1.0" encoding="UTF-8"?>
<ModMetaData>
<name>CustomDrug</name>
<author>YourName</author>
<!-- Package IDs must be unique; RimWorld will not load two mods with the same ID. -->
<packageId>YourName.CustomDrug</packageId>
<!-- Your description goes here. -->
<description>ExampleDescription</description>
<supportedVersions>
<!-- This field tells RimWorld which versions of the game this mod works on. For this tutorial, we will be working with the latest update, 1.6. -->
<li>1.6</li>
</supportedVersions>
</ModMetaData>
Sample Assets[edit]
You can use these as the example textures:
Instructions[edit]
1. Create drug ThingDefs[edit]
Internally, the addiction system is relatively consistent across all drugs, so we will be using the def block of Smokeleaf as a template. The XML for Smokeleaf can be found in Data/Core/Defs/Drugs/Smokeleaf.xml
There are two main defs we'll be working with, the ThingDef for the drug item, and the HediffDef for the effect.
<?xml version="1.0" encoding="utf-8" ?> <Defs> <!--ParentName makes the thing inherit properties from its parent--> <ThingDef ParentName="MakeableDrugBase"> <!--a defName is an ID unique to every def, allowing the game to distinguish things from one another--> <defName>XylinDrug</defName> <!--a label is the text shown to the player--> <label>xylin</label> <description>Description goes here.</description> <!--properties go here--> </ThingDef> <HediffDef> <defName>XylinHigh</defName> <label>high on xylin</label> <labelNoun>a xylin high</labelNoun> <description>Xylin's active chemical in the bloodstream. Dulls pain.</description> <!--properties go here--> </HediffDef> </Defs>
2. Add properties[edit]
XylinDrug[edit]
| XML | Description |
|---|---|
<possessionCount>5</possessionCount> |
This defines how many instances of said item pawns will carry in their inventory, if instructed to do so via policy or manually. |
<descriptionHyperlinks> <HediffDef>XylinHigh</HediffDef> </descriptionHyperlinks> |
This defines what other things will be hyperlinked on the item's info page. |
<graphicData> <texPath>ExampleMod/Xylin</texPath> <graphicClass>Graphic_StackCount</graphicClass> </graphicData> |
The |
<rotatable>false</rotatable> |
TBA |
<techLevel>Industrial</techLevel> |
TBA |
<statBases> <WorkToMake>450</WorkToMake> <MarketValue>16</MarketValue> <Mass>0.05</Mass> <DeteriorationRate>6</DeteriorationRate> <Flammability>1.3</Flammability> </statBases> |
|
<ingestible>
<foodType>Plant, Fluid</foodType>
<baseIngestTicks>80</baseIngestTicks>
<nurseable>true</nurseable>
<drugCategory>Medical</drugCategory>
<ingestSound>Ingest_Inject</ingestSound>
<ingestEffectEat>EatVegetarian</ingestEffectEat>
<ingestHoldOffsetStanding>
<northDefault>
<offset>(0.18,0,0)</offset>
</northDefault>
</ingestHoldOffsetStanding>
<ingestHoldUsesTable>false</ingestHoldUsesTable>
<ingestCommandString>Inject {0}</ingestCommandString>
<ingestReportString>Injecting {0}.</ingestReportString>
<ingestReportStringEat>Consuming {0}.</ingestReportStringEat>
<useEatingSpeedStat>false</useEatingSpeedStat>
<outcomeDoers>
<li Class="IngestionOutcomeDoer_GiveHediff">
<hediffDef>XylinHigh</hediffDef>
<severity>1.0</severity>
</li>
</outcomeDoers>
</ingestible>
|
|
<recipeMaker> <recipeUsers> <li>DrugLab</li> </recipeUsers> <workSpeedStat>DrugCookingSpeed</workSpeedStat> <workSkill>Cooking</workSkill> <displayPriority>2000</displayPriority> </recipeMaker> |
|
<costList> <Chemfuel>4</Chemfuel> </costList> |
The ingredients required to produce one instance of this item. |
<comps> <li Class="CompProperties_Drug"> <listOrder>20</listOrder> </li> </comps> |
TBA |
<allowedArchonexusCount>50</allowedArchonexusCount> |
TBA |
| XML | Description |
|---|---|
<hediffClass>Hediff_High</hediffClass> |
This defines what type of effect this is. |
<defaultLabelColor>(1,0,0.5)</defaultLabelColor> |
The color that the hediff appears as in the health tab. |
<scenarioCanAdd>true</scenarioCanAdd> |
Whether custom scenarios can add this hediff as a starting effect. |
<maxSeverity>1.0</maxSeverity> |
TBA |
<isBad>false</isBad> |
Whether this qualifies as a bad effect. Used by healer mech serum and resurrection mech serum in order to determine whether to remove this effect. |
<comps> <li Class="HediffCompProperties_SeverityPerDay"> <severityPerDay>-0.5</severityPerDay> <showHoursToRecover>true</showHoursToRecover> </li> </comps> |
|
<stages> <li> <painOffset>-0.9</painOffset> <capMods> <li> <capacity>Consciousness</capacity> <offset>-0.1</offset> </li> </capMods> </li> </stages> |
TBA. |

