Custom Drug

From RimWorld Wiki
Jump to navigation Jump to search

Modding Tutorials

?
Under Review
This tutorial or guide is currently undergoing review and may be subject to further revision.

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:

Single graphic
CustomDrug Xylin a.png
Full stack graphic
CustomDrug Xylin b.png

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 texPath tag tells RimWorld which folder contains the textures.
The graphicClass tag defines what type of texture is used to represent the item. Specifically, Graphic_StackCount instructs the game to display a different texture depending on how many items are stacked.

<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>

WorkToMake refers to how many ticks producing this item takes.
The MarketValue tag provides the item's price in silver, before modifiers such as colony disadvantage are applied.
Mass refers to the weight of the item for caravan purposes.
DeteriorationRate is a tag instructing the game how many points of damage per day the item should take if left outdoors.
The Flammability tag provides how quickly the item will deteriorate from direct fire.

<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>

FoodType -> TBA
The baseIngestTicks tag refers to how many ticks a pawn will take to consume this item.
nurseable -> TBA
The drugCategory tag separates drugs into types. Social drugs will be used for recreation, hard drugs will be consumed during certain mental breaks, and medical drugs won't be consumed unless instructed to manually or via policy.
ingestHoldUsesTable refers to whether pawns will seek out a table to consume this item.
useEatingSpeedStat instructs the game whether to take the eating stat into account when calculating consumption time.

<recipeMaker>
	<recipeUsers>
		<li>DrugLab</li>
	</recipeUsers>
	<workSpeedStat>DrugCookingSpeed</workSpeedStat>
	<workSkill>Cooking</workSkill>
	<displayPriority>2000</displayPriority>
</recipeMaker>

recipeUsers refers to what workbenches can create this item. Multiple things may be added.
workSkill is a tag instructing the game what skill producing this item trains and uses.
The DrugCookingSpeed tag provides what modifier affects crafting time.

<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>

severityPerDay -> TBA
showHoursToRecover refers to whether the health tab will show how many hours the effect has left.

<stages>
	<li>
		<painOffset>-0.9</painOffset>
		<capMods>
			<li>
				<capacity>Consciousness</capacity>
				<offset>-0.1</offset>
			</li>
		</capMods>
	</li>
</stages>

TBA.