Editing Modding Tutorials/Weapons Guns

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
{{BackToTutorials}}
 
 
{{Credit|[[User:Alistaire|Alistaire]]}}<br/>
 
{{Credit|[[User:Alistaire|Alistaire]]}}<br/>
  
In this tutorial we will take a look at a specific item and break down its components, link this knowledge with other items and ultimately learn how to create your own items.<br/><br/>
+
In this tutorial we will take a look at a specific item and break down its components, link this knowledge with other items and ultimately learn how to create your own items.<br/>
  
=Requirements=
+
It requires you to have [[Modding Tutorials/Mod folder structure|set up a folder structure]] for your mod.<br/><br/>
  
* [[Modding Tutorials/XML file structure|XML File Structure]] for knowledge on XML file structures and basic inheritance;
+
=What you'll learn=
* (Optional) [[Modding Tutorials/Mod folder structure|Mod Folder Structure]] in case you want to set up a weapons mod;
+
 
* (Optional) An XML code editor ([[Modding Tutorials/Recommended software#XML Code Editors|recommended software]]) in case you want to set up a weapons mod.<br/><br/>
+
You'll learn the default structure of thingDef files:<br/>
 +
 
 +
<source lang="xml"><?xml version="1.0" encoding="utf-8"?>
 +
<ThingDefs>
 +
<thingDef Name="Parent" Abstract="True">
 +
</thingDef>
 +
 
 +
<thingDef ParentName="Parent">
 +
</thingDef>
 +
 
 +
<!-- more <thingDef>s -->
 +
</ThingDefs></source><br/>
 +
 
 +
.. Along with what most tags inside Weapons_Guns.xml do, and how inheritance using Name, ParentName and Abstract works.<br/><br/>
 +
 
 +
=Default thingDef structure=
 +
===Introduction===
 +
 
 +
Create a .xml file in your mod's folder. A recommended location and name for this file, starting from your Rimworld download location and "MOD NAME" replaced with your mod's name, is:<br/>
 +
<source lang="xml">../Mods/MOD NAME/Defs/ThingDefs/Weapons_Guns.xml</source><br/>
 +
 
 +
The first thing in this file should be the following line:<br/>
 +
<source lang="xml"><?xml version="1.0" encoding="utf-8"?></source><br/>
 +
 
 +
After that, the structure of the file consists of '''<ThingDefs>''' and '''<thingDef>''' tags:<br/>
 +
<source lang="xml"><ThingDefs>
 +
<thingDef>
 +
</thingDef>
  
=What you'll learn=
+
<!-- more <thingDef>s -->
 +
 
 +
<thingDef>
 +
</thingDef>
 +
</ThingDefs></source><br/>
 +
 
 +
Each '''<thingDef>''' contains something's ''def'' (or definition), which can be used to specify each and every modifiable property for a certain ''thing''.<br/>
 +
 
 +
===Source===
 +
 
 +
'''It is important that your file follows this structure to the point where the Weapons_Guns.xml file won't work with multiple <ThingDefs> or <thingDef>s outside of <ThingDefs>:'''<br/>
 +
<source lang="xml"><?xml version="1.0" encoding="utf-8"?>
 +
<ThingDefs>
 +
<thingDef>
 +
</thingDef>
 +
 
 +
<!-- more <thingDef>s -->
  
You'll learn what most tags inside Weapons_Guns.xml do.<br/><br/>
+
<thingDef>
 +
</thingDef>
 +
</ThingDefs></source><br/>
  
 
=BaseGun and BaseBullet parent=
 
=BaseGun and BaseBullet parent=
{{main|Modding Tutorials/XML file structure#Inheritance}}
+
===Introduction===
 +
 
 +
The first thing in Weapons_Guns.xml is a '''<thingDef>''' with a Name and Abstract ''type'':<br/>
 +
<source lang="xml"><ThingDef Name="BaseGun" Abstract="True"></source><br/>
 +
 
 +
The Name type means the contents of this '''<thingDef>''' can be ''inherited'' by (read: copied by) another '''<thingDef>'''. This way you can write everything you're going to repeat a lot throughout the file in a single location, such as the following:<br/>
 +
<source lang="xml"><category>Item</category></source><br/>
  
To further understand the BaseGun and BaseBullet parents, we will now do the following:<br/>
+
Which notifies that this '''<thingDef>''' is of the ''Item'' category, as opposed to those of the ''Building'' category. Because there's a lot of ''tags'' repeated throughout every gun, this greatly compacts the XML file.<br/>
 +
The full BaseGun parent only has to be defined once in a file, and can then be inherited (copied) with:<br/>
 +
<source lang="xml"><ThingDef ParentName="BaseGun"></source><br/>
  
* Firstly we'll break down the simple parts of their code;
+
'''<thingDef ParentName="X">''' inherits all contents from '''<thingDef Name="X">'''. It is common practice to copy the vanilla BaseGun parent and paste it on top of a mod's Weapons_Guns.xml file.<br/>
* Next up we're breaking down the more complicated part;
+
Another parent is BaseBullet which holds every standard bullet's commonly repeated properties, such as the property that bullets don't use hitpoints:<br/>
* Lastly I'll post the source code for both of them - they shouldn't be or have to be edited.<br/><br/>
+
<source lang="xml"><useHitPoints>False</useHitPoints></source><br/>
 +
 
 +
The last '''<thingDef>''' on top of the file is one with the Name type ''BaseHumanGun'' and the ParentName type ''BaseGun''. It inherits the contents of BaseGun and is inherited by everything with '''<thingDef ParentName="BaseHumanGun">''':<br/>
 +
<source lang="xml"><ThingDef Name="BaseHumanGun" ParentName="BaseGun" Abstract="True"></source><br/>
  
 
===Breakdown===
 
===Breakdown===
  
Now that we know about inheritance, we can take another look at the BaseGun Parent. All the code inside this parent is inherited by BaseHumanGun, which is in turn inherited by almost all weapons in ''Weapons_Guns.xml''.<br/>
+
Let's start off with the first chunks of this code:<br/>
Let's break down the rest of the code in BaseGun.<br/>
+
<source lang="xml"><ThingDef Name="BaseGun" Abstract="True">
 +
</ThingDef>
 +
 
 +
<ThingDef Name="BaseHumanGun" ParentName="BaseGun" Abstract="True">
 +
</ThingDef>
 +
 
 +
<ThingDef Name="BaseBullet" Abstract="True">
 +
</ThingDef></source>
 +
 
 +
{| class="wikitable"
 +
!colspan="2"|<ThingDef Name="BaseGun" Abstract="True">
 +
|-
 +
| &lt;ThingDef&gt; || The name of this ''tag'', which is read by the game and processed into a correct definition based on this name.<br/>All tags in ''../Mods/Core/Defs/ThingDefs/'' can be of this type.
 +
|-
 +
| Name="BaseGun" || The Name ''type'' of this tag. This tag is a parent with the Name value of "BaseGun".<br/>If you find the only purpose of a <thingDef> is to be inherited from, make sure is has the ''Abstract="True"'' type.
 +
|-
 +
| Abstract="True" || The [https://en.wikipedia.org/wiki/Abstract_type Abstract type] of this tag is True.<br/>This makes it so that the contents of this tag aren't ''instantiated'', which in practice means the contents of it can only be inherited by other tags and won't be loaded into the game because its only purpose is in inheritance, in being a parent.<br/><br/>"Is the only use of this '''<thingDef>''' to be inherited from? Yes: add Abstract="True". No: don't."
 +
|-
 +
!colspan="2"|<ThingDef Name="BaseHumanGun" ParentName="BaseGun" Abstract="True">
 +
|-
 +
| ParentName="BaseGun" || The ParentName type of this tag. This tag inherits from a parent with the Name value of "BaseGun".<br/>If you find the only purpose of a <thingDef> is to be inherited from, make sure is has the ''Abstract="True"'' type.
 +
|}<br/>
  
 
The following tags are relatively straightforward:<br/>
 
The following tags are relatively straightforward:<br/>
Line 157: Line 233:
 
| &lt;drawGUIOverlay&gt; || ''boolean'' || Whether GUI will show up when you select this thing.
 
| &lt;drawGUIOverlay&gt; || ''boolean'' || Whether GUI will show up when you select this thing.
 
|-
 
|-
| &lt;tickerType&gt; || Never<br/>Normal<br/>... || Whether this thing has a C# Tick() function; whether something happens to the thing every in-game [[Tick]].
+
| &lt;tickerType%gt; || Never<br/>Normal<br/>... || Whether this thing has a C# Tick() function; whether something happens to the thing every in-game [[Tick]].
 
|-
 
|-
 
| &lt;inspectorTabs&gt; || ''ITab list'' || A list of ITabs that will show up in the inspector when you select this item. These ITabs are for example the "Bills" buttons (ITab_Bills) and the art description (ITab_Art).
 
| &lt;inspectorTabs&gt; || ''ITab list'' || A list of ITabs that will show up in the inspector when you select this item. These ITabs are for example the "Bills" buttons (ITab_Bills) and the art description (ITab_Art).
Line 174: Line 250:
 
===Source===
 
===Source===
  
It's not recommended to edit these parents. A recent copy of them can be taken from ''../Mods/Core/Defs/ThingDefs/Weapons_Guns.xml'', and the RimWorld834Win (Version 0.11.834) version is shown below:<br/>
+
It's not recommended to edit these parents. A recent copy of them can be taken from ''../Mods/Core/Defs/ThingDefs/Weapons_Guns.xml'', and the RimWorld834Win version is shown below:<br/>
 
<source lang="xml"><ThingDef Name="BaseGun" Abstract="True">
 
<source lang="xml"><ThingDef Name="BaseGun" Abstract="True">
 
<category>Item</category>
 
<category>Item</category>
Line 428: Line 504:
 
===Burstfire===
 
===Burstfire===
  
Some guns, including the [[Assault rifle]] use the following code to add burstfire:<br/>
+
Some guns, including the [[Assault Rifle]] use the following code to add burstfire:<br/>
  
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
Line 443: Line 519:
 
===Sniper rifles===
 
===Sniper rifles===
  
The [[Sniper rifle]] is only used by specific [[Raider]]s, and won't be used by the rest. This is because of the following code:<br/>
+
The [[Sniper Rifle]] is only used by specific [[Raider]]s, and won't be used by the rest. This is because of the following code:<br/>
  
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
Line 496: Line 572:
 
===Spacer technology===
 
===Spacer technology===
  
Guns like the [[Charge rifle]] only spawn on pawns with Spacer technology:<br/>
+
Guns like the [[Charge Rifle]] only spawn on pawns with Spacer technology:<br/>
  
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
Line 531: Line 607:
 
</ThingDef></source><br/>
 
</ThingDef></source><br/>
  
[[Mechanoid#Centipede|Centipedes]] will spawn with MechanoidGunHeavy weaponry. Heavy raiders will spawn with GunHeavy. The equippedStatOffsets of MoveSpeed of -0.25 slows its wearer down by 0.25 c/s<br/><br/>
+
[[Mechanoid#Centipede|Centipedes]] will spawn with MechanoidGunHeavy weaponry. Heavy raiders will spawn with GunHeavy. The equippedStatOffsets of MoveSpeed of -0.25 slows its wearer down by 25%.<br/><br/>
  
 
===Doomsday rocket===
 
===Doomsday rocket===

Please note that all contributions to RimWorld Wiki are considered to be released under the CC BY-SA 3.0 (see RimWorld Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)