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 7: Line 7:
 
You'll learn the default structure of thingDef files:<br/>
 
You'll learn the default structure of thingDef files:<br/>
  
<source lang="xml"><?xml version="1.0" encoding="utf-8"?>
+
<pre><?xml version="1.0" encoding="utf-8"?>
 
<ThingDefs>
 
<ThingDefs>
 
<thingDef Name="Parent" Abstract="True">
 
<thingDef Name="Parent" Abstract="True">
Line 15: Line 15:
 
</thingDef>
 
</thingDef>
  
<!-- more <thingDef>s -->
+
(... more <thingDef>s ...)
</ThingDefs></source><br/>
+
</ThingDefs></pre><br/>
  
 
.. Along with what most tags inside Weapons_Guns.xml do, and how inheritance using Name, ParentName and Abstract works.<br/><br/>
 
.. Along with what most tags inside Weapons_Guns.xml do, and how inheritance using Name, ParentName and Abstract works.<br/><br/>
Line 24: Line 24:
  
 
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 45:
  
 
'''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 60:
  
 
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 86:
  
 
<ThingDef Name="BaseBullet" Abstract="True">
 
<ThingDef Name="BaseBullet" Abstract="True">
</ThingDef></source>
+
</ThingDef></pre>
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 103: Line 103:
  
 
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 142:
 
<shaderType>Transparent</shaderType>
 
<shaderType>Transparent</shaderType>
 
</graphicData>
 
</graphicData>
</ThingDef></source>
+
</ThingDef></pre>
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 185: Line 185:
  
 
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 216:
 
<thingClass>Bullet</thingClass>
 
<thingClass>Bullet</thingClass>
 
<tickerType>Normal</tickerType>
 
<tickerType>Normal</tickerType>
</ThingDef></source>
+
</ThingDef></pre>
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 249: Line 249:
  
 
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 315: Line 315:
 
<shaderType>Transparent</shaderType>
 
<shaderType>Transparent</shaderType>
 
</graphicData>
 
</graphicData>
</ThingDef></source><br/>
+
</ThingDef></pre><br/>
  
 
=Gun definitions=
 
=Gun definitions=
Line 325: Line 325:
 
Each gun requires the following tags:<br/><br/>
 
Each gun requires the following tags:<br/><br/>
  
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
+
<pre><ThingDef ParentName="BaseHumanGun">
 
<defName>Gun_Pistol</defName>
 
<defName>Gun_Pistol</defName>
 
<label>pistol</label>
 
<label>pistol</label>
Line 354: Line 354:
 
</li>
 
</li>
 
</verbs>
 
</verbs>
</ThingDef></source>
+
</ThingDef></pre>
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 407: Line 407:
 
Each bullet requires the following tags:<br/><br/>
 
Each bullet requires the following tags:<br/><br/>
  
<source lang="xml"><ThingDef ParentName="BaseBullet">
+
<pre><ThingDef ParentName="BaseBullet">
 
<defName>Bullet_Pistol</defName>
 
<defName>Bullet_Pistol</defName>
 
<label>pistol bullet</label>
 
<label>pistol bullet</label>
Line 420: Line 420:
 
<Speed>55</Speed>
 
<Speed>55</Speed>
 
</projectile>
 
</projectile>
</ThingDef></source>
+
</ThingDef></pre>
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 450: Line 450:
 
===Source===
 
===Source===
  
<source lang="xml"><ThingDef ParentName="BaseBullet">
+
<pre><ThingDef ParentName="BaseBullet">
 
<defName>Bullet_Pistol</defName>
 
<defName>Bullet_Pistol</defName>
 
<label>pistol bullet</label>
 
<label>pistol bullet</label>
Line 494: Line 494:
 
</li>
 
</li>
 
</verbs>
 
</verbs>
</ThingDef></source>
+
</ThingDef></pre>
  
 
=Special cases=
 
=Special cases=
Line 504: Line 504:
 
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">
+
<pre><ThingDef ParentName="BaseHumanGun">
 
<verbs>
 
<verbs>
 
<li>
 
<li>
Line 511: Line 511:
 
</li>
 
</li>
 
</verbs>
 
</verbs>
</ThingDef></source><br/>
+
</ThingDef></pre><br/>
  
 
The weapon will fire ''burstShotCount'' times with a ''ticksBetweenBurstShots'' tick delay between each shot.<br/><br/>
 
The weapon will fire ''burstShotCount'' times with a ''ticksBetweenBurstShots'' tick delay between each shot.<br/><br/>
Line 519: Line 519:
 
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">
+
<pre><ThingDef ParentName="BaseHumanGun">
 
<weaponTags>
 
<weaponTags>
 
<li>SniperRifle</li>
 
<li>SniperRifle</li>
 
</weaponTags>
 
</weaponTags>
</ThingDef></source><br/>
+
</ThingDef></pre><br/>
  
 
Adding a weaponTag to both your weapon and a custom pawn makes it so the pawn will spawn in with that weapon.
 
Adding a weaponTag to both your weapon and a custom pawn makes it so the pawn will spawn in with that weapon.
Line 529: Line 529:
 
===Bomb projectiles===
 
===Bomb projectiles===
  
<source lang="xml"><ThingDef ParentName="BaseBullet">
+
<pre><ThingDef ParentName="BaseBullet">
 
<thingClass>Projectile_Explosive</thingClass>
 
<thingClass>Projectile_Explosive</thingClass>
 
<projectile>
 
<projectile>
Line 535: Line 535:
 
<explosionRadius>7.8</explosionRadius>
 
<explosionRadius>7.8</explosionRadius>
 
</projectile>
 
</projectile>
</ThingDef></source><br/>
+
</ThingDef></pre><br/>
  
 
Things with a Bomb damageDef need an explosionRadius and will explode upon impact.<br/><br/>
 
Things with a Bomb damageDef need an explosionRadius and will explode upon impact.<br/><br/>
Line 543: Line 543:
 
The Incendiary Launcher's bullet uses <damageDef>Flame</damageDef>:<br/>
 
The Incendiary Launcher's bullet uses <damageDef>Flame</damageDef>:<br/>
  
<source lang="xml"><ThingDef ParentName="BaseBullet">
+
<pre><ThingDef ParentName="BaseBullet">
 
<projectile>
 
<projectile>
 
<damageDef>Flame</damageDef>
 
<damageDef>Flame</damageDef>
Line 550: Line 550:
 
<explosionSpawnChance>0.7</explosionSpawnChance>
 
<explosionSpawnChance>0.7</explosionSpawnChance>
 
</projectile>
 
</projectile>
</ThingDef></source><br/>
+
</ThingDef></pre><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/>
 
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/>
Line 558: Line 558:
 
Some weapons have a bigger muzzleflash:<br/>
 
Some weapons have a bigger muzzleflash:<br/>
  
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
+
<pre><ThingDef ParentName="BaseHumanGun">
 
<verbs>
 
<verbs>
 
<li>
 
<li>
Line 564: Line 564:
 
</li>
 
</li>
 
</verbs>
 
</verbs>
</ThingDef></source><br/>
+
</ThingDef></pre><br/>
  
 
Most weapons have a scale of 9, while some of the bigger weapons have a scale of 14.<br/><br/>
 
Most weapons have a scale of 9, while some of the bigger weapons have a scale of 14.<br/><br/>
Line 572: Line 572:
 
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">
+
<pre><ThingDef ParentName="BaseHumanGun">
 
<techLevel>Spacer</techLevel>
 
<techLevel>Spacer</techLevel>
</ThingDef></source><br/>
+
</ThingDef></pre><br/>
  
 
===Turret gun===
 
===Turret gun===
Line 580: Line 580:
 
Turrets use a gun from Weapons_Guns.xml which uses the following code:<br/>
 
Turrets use a gun from Weapons_Guns.xml which uses the following code:<br/>
  
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
+
<pre><ThingDef ParentName="BaseHumanGun">
 
<menuHidden>true</menuHidden>
 
<menuHidden>true</menuHidden>
 
<canBeSpawningInventory>false</canBeSpawningInventory>
 
<canBeSpawningInventory>false</canBeSpawningInventory>
Line 587: Line 587:
 
<li>TurretGun</li>
 
<li>TurretGun</li>
 
</weaponTags>
 
</weaponTags>
</ThingDef></source><br/>
+
</ThingDef></pre><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/>
 
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/>
Line 595: Line 595:
 
Heavy weapons have additional weaponTags and equippedStatOffsets:<br/>
 
Heavy weapons have additional weaponTags and equippedStatOffsets:<br/>
  
<source lang="xml"><ThingDef ParentName="BaseHumanGun">
+
<pre><ThingDef ParentName="BaseHumanGun">
 
<weaponTags>
 
<weaponTags>
 
<li>MechanoidGunHeavy</li>
 
<li>MechanoidGunHeavy</li>
Line 603: Line 603:
 
<MoveSpeed>-0.25</MoveSpeed>
 
<MoveSpeed>-0.25</MoveSpeed>
 
</equippedStatOffsets>
 
</equippedStatOffsets>
</ThingDef></source><br/>
+
</ThingDef></pre><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/>
 
[[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/>
Line 609: Line 609:
 
===Doomsday rocket===
 
===Doomsday rocket===
  
<source lang="xml"><ThingDef ParentName="BaseBullet">
+
<pre><ThingDef ParentName="BaseBullet">
 
<shaderType>TransparentPostLight</shaderType>
 
<shaderType>TransparentPostLight</shaderType>
 
<thingClass>Projectile_DoomsdayRocket</thingClass>
 
<thingClass>Projectile_DoomsdayRocket</thingClass>
</ThingDef></source><br/>
+
</ThingDef></pre><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/>
 
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">
+
<pre><ThingDef ParentName="BaseGun">
 
<tradeTags>
 
<tradeTags>
 
<li>Exotic</li>
 
<li>Exotic</li>
Line 629: Line 629:
 
</li>
 
</li>
 
</verbs>
 
</verbs>
</ThingDef></source><br/>
+
</ThingDef></pre><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/>
 
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/>
Line 635: Line 635:
 
===Miss radius===
 
===Miss radius===
  
<source lang="xml"><ThingDef ParentName="BaseGun">
+
<pre><ThingDef ParentName="BaseGun">
 
<verbs>
 
<verbs>
 
<li>
 
<li>
Line 641: Line 641:
 
</li>
 
</li>
 
</verbs>
 
</verbs>
</ThingDef></source><br/>
+
</ThingDef></pre><br/>
  
 
Even after applying the accuracy checks, this gun is still going to miss its target by 2.0 tiles.<br/><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: