Editing User:Alistaire/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:
 
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/>
 
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/>
  
It requires you to have [[Modding Tutorials/Mod folder structure|set up a folder structure]] for your mod.<br/><br/>
+
It requires you to have [[User:Alistaire/Tutorials/Folder structure|set up a folder structure]] for your mod.<br/><br/>
  
=What you'll learn=
+
=First things first=
 
 
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===
 
===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/>
 
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/>
+
<pre>../Mods/MOD NAME/Defs/ThingDefs/Weapons_Guns.xml</pre><br/>
  
 
The first thing in this file should be the following line:<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/>
+
<pre><?xml version="1.0" encoding="utf-8"?></pre><br/>
  
 
After that, the structure of the file consists of '''<ThingDefs>''' and '''<thingDef>''' tags:<br/>
 
After that, the structure of the file consists of '''<ThingDefs>''' and '''<thingDef>''' tags:<br/>
<source lang="xml"><ThingDefs>
+
<pre><ThingDefs>
 
<thingDef>
 
<thingDef>
 
</thingDef>
 
</thingDef>
  
<!-- more <thingDef>s -->
+
(... more <thingDef>s ...)
  
 
<thingDef>
 
<thingDef>
 
</thingDef>
 
</thingDef>
</ThingDefs></source><br/>
+
</ThingDefs></pre><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/>
 
Each '''<thingDef>''' contains something's ''def'' (or definition), which can be used to specify each and every modifiable property for a certain ''thing''.<br/>
Line 45: Line 28:
  
 
'''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/>
 
'''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"?>
+
<pre><?xml version="1.0" encoding="utf-8"?>
 
<ThingDefs>
 
<ThingDefs>
 
<thingDef>
 
<thingDef>
 
</thingDef>
 
</thingDef>
  
<!-- more <thingDef>s -->
+
(... more <thingDef>s ...)
  
 
<thingDef>
 
<thingDef>
 
</thingDef>
 
</thingDef>
</ThingDefs></source><br/>
+
</ThingDefs></pre><br/>
  
 
=BaseGun and BaseBullet parent=
 
=BaseGun and BaseBullet parent=
Line 60: Line 43:
  
 
The first thing in Weapons_Guns.xml is a '''<thingDef>''' with a Name and Abstract ''type'':<br/>
 
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/>
+
<pre><ThingDef Name="BaseGun" Abstract="True"></pre><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/>
 
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/>
+
<pre><category>Item</category></pre><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/>
 
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/>
 
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/>
+
<pre><ThingDef ParentName="BaseGun"></pre><br/>
  
 
'''<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/>
 
'''<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/>
 
Another parent is BaseBullet which holds every standard bullet's commonly repeated properties, such as the property that bullets don't use hitpoints:<br/>
 
Another parent is BaseBullet which holds every standard bullet's commonly repeated properties, such as the property that bullets don't use hitpoints:<br/>
<source lang="xml"><useHitPoints>False</useHitPoints></source><br/>
+
<pre><useHitPoints>False</useHitPoints></pre><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/>
 
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/>
+
<pre><ThingDef Name="BaseHumanGun" ParentName="BaseGun" Abstract="True"></pre><br/>
  
 
===Breakdown===
 
===Breakdown===
  
 
Let's start off with the first chunks of this code:<br/>
 
Let's start off with the first chunks of this code:<br/>
<source lang="xml"><ThingDef Name="BaseGun" Abstract="True">
+
<pre><ThingDef Name="BaseGun" Abstract="True">
 
</ThingDef>
 
</ThingDef>
  
Line 86: Line 69:
  
 
<ThingDef Name="BaseBullet" Abstract="True">
 
<ThingDef Name="BaseBullet" Abstract="True">
</ThingDef></source>
+
</ThingDef></pre>
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 93: Line 76:
 
| &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.
 
| &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.
+
| 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 if 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."
 
| 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."
Line 99: Line 82:
 
!colspan="2"|<ThingDef Name="BaseHumanGun" ParentName="BaseGun" Abstract="True">
 
!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.
+
| 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 if a <thingDef> is to be inherited from, make sure is has the ''Abstract="True"'' type.
 
|}<br/>
 
|}<br/>
  
 
The following tags are relatively straightforward:<br/>
 
The following tags are relatively straightforward:<br/>
<source lang="xml"><ThingDef Name="BaseGun" Abstract="True">
+
<pre><ThingDef Name="BaseGun" Abstract="True">
 
<category>Item</category>
 
<category>Item</category>
 
<altitudeLayer>Item</altitudeLayer>
 
<altitudeLayer>Item</altitudeLayer>
Line 142: Line 125:
 
<shaderType>Transparent</shaderType>
 
<shaderType>Transparent</shaderType>
 
</graphicData>
 
</graphicData>
</ThingDef></source>
+
</ThingDef></pre>
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 185: Line 168:
  
 
And the last part is somewhat more complicated:<br/>
 
And the last part is somewhat more complicated:<br/>
<source lang="xml"><ThingDef Name="BaseGun" Abstract="True">
+
<pre><ThingDef Name="BaseGun" Abstract="True">
 
<thingClass>ThingWithComps</thingClass>
 
<thingClass>ThingWithComps</thingClass>
 
<equipmentType>Primary</equipmentType>
 
<equipmentType>Primary</equipmentType>
Line 216: Line 199:
 
<thingClass>Bullet</thingClass>
 
<thingClass>Bullet</thingClass>
 
<tickerType>Normal</tickerType>
 
<tickerType>Normal</tickerType>
</ThingDef></source>
+
</ThingDef></pre>
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 249: Line 232:
  
 
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/>
 
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">
+
<pre><ThingDef Name="BaseGun" Abstract="True">
 
<category>Item</category>
 
<category>Item</category>
 
<thingClass>ThingWithComps</thingClass>
 
<thingClass>ThingWithComps</thingClass>
Line 297: Line 280:
 
</smeltProducts>
 
</smeltProducts>
 
</ThingDef>
 
</ThingDef>
 +
  
 
<ThingDef Name="BaseHumanGun" ParentName="BaseGun" Abstract="True">
 
<ThingDef Name="BaseHumanGun" ParentName="BaseGun" Abstract="True">
Line 303: Line 287:
 
</weaponTags>
 
</weaponTags>
 
</ThingDef>
 
</ThingDef>
 +
  
 
<ThingDef Name="BaseBullet" Abstract="True">
 
<ThingDef Name="BaseBullet" Abstract="True">
Line 315: Line 300:
 
<shaderType>Transparent</shaderType>
 
<shaderType>Transparent</shaderType>
 
</graphicData>
 
</graphicData>
</ThingDef></source><br/>
+
</ThingDef></pre><br/>
 
 
=Gun definitions=
 
 
 
Guns inherit from ''BaseHumanGun'' or sometimes from ''BaseGun''. Each gun requires a bunch of tags and additionally accepts some other tags.<br/><br/>
 
 
 
===Breakdown===
 
 
 
Each gun requires the following tags:<br/><br/>
 
 
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
 
<defName>Gun_Pistol</defName>
 
<label>pistol</label>
 
<description>Ancient pattern automatic pistol. Weak and short range, but quick.</description>
 
<graphicData>
 
<texPath>Things/Item/Equipment/WeaponRanged/Pistol</texPath>
 
<graphicClass>Graphic_Single</graphicClass>
 
</graphicData>
 
<soundInteract>InteractPistol</soundInteract>
 
<statBases>
 
<MarketValue>200</MarketValue>
 
<AccuracyTouch>0.91</AccuracyTouch>
 
<AccuracyShort>0.71</AccuracyShort>
 
<AccuracyMedium>0.50</AccuracyMedium>
 
<AccuracyLong>0.32</AccuracyLong>
 
<RangedWeapon_Cooldown>0.66</RangedWeapon_Cooldown>
 
</statBases>
 
<verbs>
 
<li>
 
<verbClass>Verb_Shoot</verbClass>
 
<hasStandardCommand>true</hasStandardCommand>
 
<projectileDef>Bullet_Pistol</projectileDef>
 
<warmupTicks>54</warmupTicks>
 
<range>24</range>
 
<soundCast>ShotPistol</soundCast>
 
<soundCastTail>GunTail_Light</soundCastTail>
 
<muzzleFlashScale>9</muzzleFlashScale>
 
</li>
 
</verbs>
 
</ThingDef></source>
 
 
 
{| class="wikitable"
 
!colspan="3"|<thingDef>
 
|-
 
! Tag !! Values !! Explanation
 
|-
 
| &lt;defName&gt; || ''string'' || The defName, in-script name, of this item that can be referred to by C# or other XML files.<br/>For guns this usually starts with ''Gun_'', and for bullets it usually starts with ''Bullet_''.
 
|-
 
| &lt;label&gt; || ''string'' || The in-game (as opposed to in-script ''defName'') name for this item in lowercase. The game automatically makes the first character uppercase.
 
|-
 
| &lt;description&gt; || ''string'' || The description for this item, shown when the item's information tab is opened. You can use escape characters in this string, like \n for a newline.
 
|-
 
| &lt;soundInteract&gt; || defName<br/>''(from soundDef)'' || What sound is played whenever someone takes or drops the item.
 
|-
 
!colspan="3"|<graphicData>
 
|-
 
| &lt;texPath&gt; || ''path'' || The path relative to ''../Textures/'' in which this thing's texture is stored.
 
|-
 
| &lt;graphicClass&gt; || C# class || The class that is called when generating an image for this thing. Guns in the base game always use Graphic_Single, but there's different values like Graphic_Random etc.
 
|-
 
!colspan="3"|<statBases>
 
|-
 
| &lt;MarketValue&gt; || ''integer'' || The "market value" of this thing.<br/>Please note that ''sellPriceFactor'' halves this value when selling the thing, and that the [[Skills#Social|Social]] skill influences the actual value.<br/>This value is modified by the weapon's [[quality]].
 
|-
 
| &lt;Accuracy...&gt; || ''float'' || The 0.0-1.0 chance this gun hits its target at a certain range. The [[Weapons#Ranged_Weapons|Weapons]] page has an explanation for the effects of different accuracy tags.<br/>This value is modified by the weapon's [[quality]].
 
|-
 
| &lt;RangedWeapon_Cooldown&gt; || ''seconds'' || The amount of seconds the pawn will stand around doing nothing after firing a burst of this weapon.<br/>This value is modified by the weapon's [[quality]].
 
|-
 
!colspan="3"|<verbs> &lt;li&gt; </verbs>
 
|-
 
| &lt;verbClass&gt; || C# class || The class that is called whenever this weapon is shot. Vanilla Rimworld only uses Verb_Shoot, while mods might call their own custom verbClass.
 
|-
 
| &lt;hasStandardCommand&gt; || ''boolean'' ||
 
|-
 
| &lt;projectileDef&gt; || defName || The defName of the bullet this gun fires.
 
|-
 
| &lt;warmupTicks&gt; || ''ticks'' || The amount of [[Tick|game ticks]] it takes to aim this gun.<br/>This aiming time is visualized with a shrinking grey circle in-game - large values increase the circle's starting circumference.
 
|-
 
| &lt;range&gt; || ''tiles'' || How far the weapon can '''aim'''.<br/>This value is modified by the weapon's [[quality]].
 
|-
 
| &lt;soundCast&gt; || defName<br/>''(from soundDef)'' || What sound is played whenever the weapon spawns a bullet (can be read as fires).
 
|-
 
| &lt;soundCastTail&gt; || defName<br/>''(from soundDef)'' || What sound is played after the weapon is fired. This value is not necessarily required, but vanilla Rimworld uses it a lot.
 
|-
 
| &lt;muzzleFlashScale&gt; || ''int'' || The size of the muzzle flash effect which is displayed when the weapon fires.
 
|}<br/>
 
  
===Bullets===
+
=Bullet_Pistol=
  
Bullets hold information regarding damage, bullet speed and whether the bullet will explode, burst into flames, etc.<br/>
 
Each bullet requires the following tags:<br/><br/>
 
  
<source lang="xml"><ThingDef ParentName="BaseBullet">
 
<defName>Bullet_Pistol</defName>
 
<label>pistol bullet</label>
 
<graphicData>
 
<texPath>Things/Projectile/Bullet_Small</texPath>
 
<graphicClass>Graphic_Single</graphicClass>
 
</graphicData>
 
<projectile>
 
<flyOverhead>false</flyOverhead>
 
<damageDef>Bullet</damageDef>
 
<DamageAmountBase>9</DamageAmountBase>
 
<Speed>55</Speed>
 
</projectile>
 
</ThingDef></source>
 
  
{| class="wikitable"
+
=Gun_Pistol=
!colspan="3"|<thingDef>
 
|-
 
! Tag !! Values !! Explanation
 
|-
 
| &lt;defName&gt; || ''string'' || The defName, in-script name, of this item that can be referred to by C# or other XML files.<br/>For guns this usually starts with ''Gun_'', and for bullets it usually starts with ''Bullet_''.
 
|-
 
| &lt;label&gt; || ''string'' || The in-game (as opposed to in-script ''defName'') name for this item in lowercase. The game automatically makes the first character uppercase.
 
|-
 
!colspan="3"|<graphicData>
 
|-
 
| &lt;texPath&gt; || ''path'' || The path relative to ''../Textures/'' in which this thing's texture is stored.
 
|-
 
| &lt;graphicClass&gt; || C# class || The class that is called when generating an image for this thing. Guns in the base game always use Graphic_Single, but there's different values like Graphic_Random etc.
 
|-
 
!colspan="3"|<projectile>
 
|-
 
| &lt;flyOverhead&gt; || ''boolean'' || Whether a missing bullet can fly over walls. Seriously.
 
|-
 
| &lt;damageDef&gt; || defName<br/>''from damageDef'' || The defName of the [[Damage Types|damage type]] this bullet causes.
 
|-
 
| &lt;damageAmountBase&gt; || ''int'' || The amount of base damage the bullet can cause. Hitting a specific object might do a different amount of damage based on the value of ''damageDef''.
 
|-
 
| &lt;speed&gt; || ''int'' || A value denoting some unit of speed at which the bullet travels. It's best to reference existing weapons when choosing a speed for your bullet.
 
|}<br/>
 
 
 
===Source===
 
 
 
<source lang="xml"><ThingDef ParentName="BaseBullet">
 
<defName>Bullet_Pistol</defName>
 
<label>pistol bullet</label>
 
<graphicData>
 
<texPath>Things/Projectile/Bullet_Small</texPath>
 
<graphicClass>Graphic_Single</graphicClass>
 
</graphicData>
 
<projectile>
 
<flyOverhead>false</flyOverhead>
 
<damageDef>Bullet</damageDef>
 
<DamageAmountBase>9</DamageAmountBase>
 
<Speed>55</Speed>
 
</projectile>
 
</ThingDef>
 
 
 
<ThingDef ParentName="BaseHumanGun">
 
<defName>Gun_Pistol</defName>
 
<label>pistol</label>
 
<description>Ancient pattern automatic pistol. Weak and short range, but quick.</description>
 
<graphicData>
 
<texPath>Things/Item/Equipment/WeaponRanged/Pistol</texPath>
 
<graphicClass>Graphic_Single</graphicClass>
 
</graphicData>
 
<soundInteract>InteractPistol</soundInteract>
 
<statBases>
 
<MarketValue>200</MarketValue>
 
<AccuracyTouch>0.91</AccuracyTouch>
 
<AccuracyShort>0.71</AccuracyShort>
 
<AccuracyMedium>0.50</AccuracyMedium>
 
<AccuracyLong>0.32</AccuracyLong>
 
<RangedWeapon_Cooldown>0.66</RangedWeapon_Cooldown>
 
</statBases>
 
<verbs>
 
<li>
 
<verbClass>Verb_Shoot</verbClass>
 
<hasStandardCommand>true</hasStandardCommand>
 
<projectileDef>Bullet_Pistol</projectileDef>
 
<warmupTicks>54</warmupTicks>
 
<range>24</range>
 
<soundCast>ShotPistol</soundCast>
 
<soundCastTail>GunTail_Light</soundCastTail>
 
<muzzleFlashScale>9</muzzleFlashScale>
 
</li>
 
</verbs>
 
</ThingDef></source>
 
 
 
=Special cases=
 
 
 
There's a few cases where guns don't entirely follow the previously described structure.<br/><br/>
 
 
 
===Burstfire===
 
 
 
Some guns, including the [[Assault rifle]] use the following code to add burstfire:<br/>
 
 
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
 
<verbs>
 
<li>
 
<burstShotCount>3</burstShotCount>
 
<ticksBetweenBurstShots>7</ticksBetweenBurstShots>
 
</li>
 
</verbs>
 
</ThingDef></source><br/>
 
 
 
The weapon will fire ''burstShotCount'' times with a ''ticksBetweenBurstShots'' tick delay between each shot.<br/><br/>
 
 
 
===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/>
 
 
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
 
<weaponTags>
 
<li>SniperRifle</li>
 
</weaponTags>
 
</ThingDef></source><br/>
 
 
 
Adding a weaponTag to both your weapon and a custom pawn makes it so the pawn will spawn in with that weapon.
 
 
 
===Bomb projectiles===
 
 
 
<source lang="xml"><ThingDef ParentName="BaseBullet">
 
<thingClass>Projectile_Explosive</thingClass>
 
<projectile>
 
<damageDef>Bomb</damageDef>
 
<explosionRadius>7.8</explosionRadius>
 
</projectile>
 
</ThingDef></source><br/>
 
 
 
Things with a Bomb damageDef need an explosionRadius and will explode upon impact.<br/><br/>
 
 
 
===Flame bullets===
 
 
 
The Incendiary Launcher's bullet uses <damageDef>Flame</damageDef>:<br/>
 
 
 
<source lang="xml"><ThingDef ParentName="BaseBullet">
 
<projectile>
 
<damageDef>Flame</damageDef>
 
<explosionRadius>1.1</explosionRadius>
 
<postExplosionSpawnThingDef>Puddle_Fuel</postExplosionSpawnThingDef>
 
<explosionSpawnChance>0.7</explosionSpawnChance>
 
</projectile>
 
</ThingDef></source><br/>
 
 
 
This bullet will explode into flames in a radius of 1.1 tiles, and it will spawn a Puddle_Fuel 70% of all impacts.<br/><br/>
 
 
 
===Bigger muzzleflash===
 
 
 
Some weapons have a bigger muzzleflash:<br/>
 
 
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
 
<verbs>
 
<li>
 
<muzzleFlashScale>14</muzzleFlashScale>
 
</li>
 
</verbs>
 
</ThingDef></source><br/>
 
 
 
Most weapons have a scale of 9, while some of the bigger weapons have a scale of 14.<br/><br/>
 
 
 
===Spacer technology===
 
 
 
Guns like the [[Charge rifle]] only spawn on pawns with Spacer technology:<br/>
 
 
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
 
<techLevel>Spacer</techLevel>
 
</ThingDef></source><br/>
 
 
 
===Turret gun===
 
 
 
Turrets use a gun from Weapons_Guns.xml which uses the following code:<br/>
 
 
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
 
<menuHidden>true</menuHidden>
 
<canBeSpawningInventory>false</canBeSpawningInventory>
 
<tradeability>Never</tradeability>
 
<weaponTags>
 
<li>TurretGun</li>
 
</weaponTags>
 
</ThingDef></source><br/>
 
 
 
This gun can't be seen in the colony inventory screen, can't be spawned in with a newly spawned pawn, isn't tradable (so it won't show up on traders) and its weaponTag is TurretGun to prevent it from being spawned in by accident.<br/><br/>
 
 
 
===Heavy weapons===
 
 
 
Heavy weapons have additional weaponTags and equippedStatOffsets:<br/>
 
 
 
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
 
<weaponTags>
 
<li>MechanoidGunHeavy</li>
 
<li>GunHeavy</li>
 
</weaponTags>
 
<equippedStatOffsets>
 
<MoveSpeed>-0.25</MoveSpeed>
 
</equippedStatOffsets>
 
</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 25%.<br/><br/>
 
 
 
===Doomsday rocket===
 
 
 
<source lang="xml"><ThingDef ParentName="BaseBullet">
 
<shaderType>TransparentPostLight</shaderType>
 
<thingClass>Projectile_DoomsdayRocket</thingClass>
 
</ThingDef></source><br/>
 
 
 
The Doomsday rocket uses a different shaderType which isn't effected by light levels to simulate it giving off light itself. It also has a different thingClass.<br/>
 
 
 
<source lang="xml"><ThingDef ParentName="BaseGun">
 
<tradeTags>
 
<li>Exotic</li>
 
</tradeTags>
 
<verbs>
 
<li>
 
<verbClass>Verb_ShootOneUse</verbClass>
 
<onlyManualCast>true</onlyManualCast>
 
<targetParams>
 
<canTargetLocations>true</canTargetLocations>
 
</targetParams>
 
</li>
 
</verbs>
 
</ThingDef></source><br/>
 
 
 
The gun is only traded by Exotic traders due to its tradeTags, is a single use (Verb_ShootOneUse) weapon which can only be shot by the player itself. It can target floor tiles, not only wall tiles.<br/><br/>
 
 
 
===Miss radius===
 
 
 
<source lang="xml"><ThingDef ParentName="BaseGun">
 
<verbs>
 
<li>
 
<forcedMissRadius>2.0</forcedMissRadius>
 
</li>
 
</verbs>
 
</ThingDef></source><br/>
 
  
Even after applying the accuracy checks, this gun is still going to miss its target by 2.0 tiles.<br/><br/>
 
  
 
[[Category:Modding tutorials]]
 
[[Category:Modding tutorials]]

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)

This page is a member of 1 hidden category: