Plague Gun/XML Stage

From RimWorld Wiki
Jump to navigation Jump to search

Modding Tutorials

This tutorial was originally written by Jecrell. Thread.

XML Stage

  1. Create a mod folder.
    RimWorld>Mods>PlagueGun
    • Go to your RimWorld's base folder. For myself, that is D:\SteamLibrary\steamapps\common\RimWorld\. Others may find it in C:\Program Files (x86)\Steam\steamapps\common\RimWorld or a custom directory.
    • Go into the Mods folder.
    • Make a new folder with our mod's title: PlagueGun
  2. Inside PlagueGun, make an About folder.
    RimWorld>Mods>PlagueGun>About
  3. Inside the About folder, make a new text file and rename it About.xml.
    RimWorld>Mods>PlagueGun>About>About.xml
    • You will need a good text editor to make a proper XML file -- see required items. I always make a .TXT file first and change it to .XML. If you can't rename your file's type, make sure you have filetypes visible in your view settings.
    • About.xml is the file that shows your mod in the mod list inside the RimWorld game. It is also used when creating a Workshop upload for Steam.
    • At the top of an XML file, always include this for RimWorld.
      <?xml version="1.0" encoding="utf-8"?>
      
    • Then add the MetaData tags for the Workshop and in-game Mod list.
      <ModMetaData>
        <name>Test Mod - Plague Gun</name>
        <author>YourNameHere</author>
        <supportedVersions>
          <li>1.0</li>
        </supportedVersions>
        <description>V1.0
          This mod adds a plague gun, a weapon that has a chance to give your enemies the plague.
        </description>
      </ModMetaData>
      
    • Save the file.
  4. Add a Preview.png or Preview.jpeg to your About folder.
    RimWorld>Mods>PlagueGun>About>Preview.png
    • This lets users see what your mod looks like in the RimWorld mod list or on the Steam Workshop.
    • I prefer the dimensions of 480x300 pixels, but the Steam Workshop will be able to work with almost any resolution you specify.
      • Editors note: 480x360 works better, max 1MB.
    • Example: Preview.png
  5. Make a Defs folder in your Mod's directory.
    RimWorld>Mods>PlagueGun>Defs
    • RimWorld will read your XML files in any directory. You can name your directories however you like under the /Defs/ subfolder. Defs/StrangeNewAlienGuns/MyGuns.xml will work. For the purposes of this tutorial, however, we will use the RimWorld standard structure.
      • What are Defs? Main article XML Defs
        • RimWorld uses something called Defs like blueprints for in-game objects. Instead of using hidden C# code, RimWorld will look up an XML Def and copy it to the game world. This makes things easier for us, the modders. Everything from characters, animals, floors, damages, buildings, and even diseases in RimWorld use Defs. We're going to make Defs for our Plague Gun and Plague Bullet.
  6. Make a new ThingDefs folder in your Defs folder.
    RimWorld>Mods>PlagueGun>Defs>ThingDefs
  7. Make a new text file in your ThingDefs folder, and change it to RangedWeapon_PlagueGun.xml.
    RimWorld>Mods>PlagueGun>Defs>ThingDefs>RangedWeapon_PlagueGun.xml
    • This file will contain the blueprints (ThingDefs or Thing Definitions) for our new gun and bullets.
    • Next we will fill out our XML file by copying an existing revolver's ThingDef and a revolver bullet ThingDef.
    • In RimWorld, it is often best to use the XML attribute ParentName="BaseBullet" when making a bullet, because it will copy XML code from a pre-existing BaseBullet ThingDef, which can save us time and key taps. Main article Inheritance
  8. First add our favourite line to the top.
    <?xml version="1.0" encoding="utf-8"?>
    
    • Again, this line of code shows RimWorld that this is an XML file to extract data from.
  9. Add the <Defs> opening and closing tags to the XML to hold our new code.
     <?xml version="1.0" encoding="utf-8"?>
    <Defs>
    
    </Defs>
    
  10. Use your text editor. Use its "Find in Files" function to reference and copy Bullet_Revolver to your XML file.
    • For me, Find in Files is a function I use repeatedly. In Notepad++, if you press CTRL+SHIFT+F, you can go to the Find in Files screen. From there, you can enter a phrase to search for, and then you can enter the file path to search through. This makes it wildly easier to search for examples in RimWorld's Core. RimWorld holds copies of all of its weapons, items, buildings, etc. inside the Mods/Core directory.
    • So, start by using Find in Files... and find this: defName>Bullet_Revolver
    • When you find Bullet_Revolver, copy from its beginning <ThingDef> all the way until its closing </ThingDef> tag into your XML File.
  11. Use your text editor. Use its "Find in Files" function to reference and copy Gun_Revolver to your XML file.
    • Typically, Gun_Revolver is right below Bullet_Revolver in XML, so hopefully this will be easy to find and copy.
    • Repeat copying ThingDef code to your new XML file.
  12. Change the defName, labels, and other stats of Bullet_Revolver and Revolver in your XML file to make them unique.
    • Change the <defaultProjectile> tag inside the PlagueGun's Verbs to use the defName of your bullet (TST_Bullet_PlagueGun). Failing to do this will result in a no errors, but your gun will shoot regular bullets (and not give the plague effect).
      Once again, under the verbs. Please make sure <defaultProjectile> references the bullet. e.g.
      <defaultProjectile>TST_Bullet_PlagueGun</defaultProjectile>
      
    • TIP Use prefixes to avoid conflicting with other mods. RimWorld doesn't distinguish between two mods that both use <defName>Tobacco</defName>, for instance. If two modders use different prefixes, however, e.g. <defName>VegetableGarden_Tobacco</defName> and <defName>ROM_Tobacco</defName>, no conflict will occur, and both mods can co-exist. This tutorial uses TST_ for its example prefix. Main article Compatibility

If all you were interested in is making a gun mod, you are done. You'll of course want to edit values like the damage it does, and test your mod. You'll also want to change the texturePath to your unique art, and whatever else.

Completed example

Note: The example is up-to-date for 1.0.1250 and will likely be outdated in the future. The above steps should always be relevant.

<?xml version="1.0" encoding="utf-8" ?>
<Defs>

  <!-- ================================= Industrial ==================================== -->

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

  <ThingDef ParentName="BaseHumanMakeableGun">
    <defName>TST_Gun_PlagueGun</defName>
    <label>plague gun</label>
    <description>A curious weapon notable for its horrible health effects.</description>
    <graphicData>
      <texPath>Things/Item/Equipment/WeaponRanged/Revolver</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <soundInteract>Interact_Revolver</soundInteract>
    <statBases>
      <WorkToMake>4000</WorkToMake>
      <Mass>1.4</Mass>
      <AccuracyTouch>0.80</AccuracyTouch>
      <AccuracyShort>0.75</AccuracyShort>
      <AccuracyMedium>0.45</AccuracyMedium>
      <AccuracyLong>0.35</AccuracyLong>
      <RangedWeapon_Cooldown>1.6</RangedWeapon_Cooldown>
    </statBases>
    <weaponTags>
      <li>SimpleGun</li>
      <li>Revolver</li>
    </weaponTags>
    <costList>
      <Steel>30</Steel>
      <ComponentIndustrial>2</ComponentIndustrial>
    </costList>
    <recipeMaker>
      <skillRequirements>
        <Crafting>3</Crafting>
      </skillRequirements>
    </recipeMaker>
    <verbs>
      <li>
        <verbClass>Verb_Shoot</verbClass>
        <hasStandardCommand>true</hasStandardCommand>
        <defaultProjectile>TST_Bullet_PlagueGun</defaultProjectile>
        <warmupTime>0.3</warmupTime>
        <range>25.9</range>
        <soundCast>Shot_Revolver</soundCast>
        <soundCastTail>GunTail_Light</soundCastTail>
        <muzzleFlashScale>9</muzzleFlashScale>
      </li>
    </verbs>
    <tools>
      <li>
        <label>grip</label>
        <capacities>
          <li>Blunt</li>
        </capacities>
        <power>9</power>
        <cooldownTime>2</cooldownTime>
      </li>
      <li>
        <label>barrel</label>
        <capacities>
          <li>Blunt</li>
          <li>Poke</li>
        </capacities>
        <power>9</power>
        <cooldownTime>2</cooldownTime>
      </li>
    </tools>
  </ThingDef>
</Defs>

See also

  1. Required Items
  2. XML Stage <- You are here.
  3. Connecting XML and C#
  4. C# Assembly Setup
  5. C# Coding
  6. Localisation

More in-depth