Modding Tutorials/Plague Gun (old)/Connecting XML and Csharp
|Modding Tutorials/Plague Gun (old)/Connecting XML and Csharp has been deprecated or removed completely from the game; it is no longer applicable to current versions. Reason: This page is obsolete for the current version of RimWorld and is kept as a resource for modders of previous versions. For the current version see: Plague Gun (1.1)|
|This article is suggested to be merged with Modding Tutorials/Plague Gun (old). |
Reason: Consider merging into single page
This tutorial was originally written by Jecrell. Thread.
Connecting XML and C#
For the next part of the tutorial, we are going to use C# code to create a custom ThingDef blueprint type, and we're going to create a custom class for our Thing to use in-game when it spawns. Before we can get to C# however, we need to "bridge" XML and C# by pointing the XML to use our C# code. First, decide your mod's namespace. This prevents RimWorld from being confused by other mods. This is the name RimWorld knows to use for your C# code. For the purposes of this tutorial, we're going to use Plague.
The following XML will not work in-game until we've written the C# code and created an assembly (.dll file) for our mod.
- Change the line for the ThingDef to reference a custom ThingDef class.
<ThingDef Class="Plague.ThingDef_PlagueBullet" ParentName="BaseBullet"> <defName>TST_Bullet_PlagueGun</defName>
- Add three more lines to the thing def before the closing tag (</ThingDef>).
<AddHediffChance>0.05</AddHediffChance> <HediffToAdd>Plague</HediffToAdd> <thingClass>Plague.Projectile_PlagueBullet</thingClass>
- AddHediffChance and HediffToAdd will give us a percentage of success to add a Hediff of our choice in XML (in this case we're using Plague). We will code how these parameters are used in the C# Coding section.
<?xml version="1.0" encoding="utf-8" ?> <Defs> <!-- ================================= Industrial ==================================== --> <ThingDef Class="Plague.ThingDef_PlagueBullet" ParentName="BaseBullet"> <defName>TST_Bullet_PlagueGun</defName> <label>plague bullet</label> <graphicData> <texPath>Things/Projectile/Bullet_Small</texPath> <graphicClass>Graphic_Single</graphicClass> </graphicData> <projectile> <flyOverhead>false</flyOverhead> <damageDef>Bullet</damageDef> <damageAmountBase>12</damageAmountBase> <stoppingPower>1</stoppingPower> <speed>55</speed> </projectile> <AddHediffChance>0.05</AddHediffChance> <HediffToAdd>Plague</HediffToAdd> <thingClass>Plague.Projectile_PlagueBullet</thingClass> </ThingDef> <!-- The Plague Gun has been left out of this example for the sake of brevity. --> </Defs>
- Required Items
- XML Stage
- Connecting XML and C# <- You are here.
- C# Assembly Setup
- C# Coding