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/> | ||
− | < | + | <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 ...) | |
− | </ThingDefs></ | + | </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/> | ||
− | < | + | <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/> | ||
− | < | + | <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/> | ||
− | < | + | <pre><ThingDefs> |
<thingDef> | <thingDef> | ||
</thingDef> | </thingDef> | ||
− | + | (... more <thingDef>s ...) | |
<thingDef> | <thingDef> | ||
</thingDef> | </thingDef> | ||
− | </ThingDefs></ | + | </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/> | ||
− | < | + | <pre><?xml version="1.0" encoding="utf-8"?> |
<ThingDefs> | <ThingDefs> | ||
<thingDef> | <thingDef> | ||
</thingDef> | </thingDef> | ||
− | + | (... more <thingDef>s ...) | |
<thingDef> | <thingDef> | ||
</thingDef> | </thingDef> | ||
− | </ThingDefs></ | + | </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/> | ||
− | < | + | <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/> | ||
− | < | + | <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/> | ||
− | < | + | <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/> | ||
− | < | + | <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/> | ||
− | < | + | <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/> | ||
− | < | + | <pre><ThingDef Name="BaseGun" Abstract="True"> |
</ThingDef> | </ThingDef> | ||
Line 86: | Line 86: | ||
<ThingDef Name="BaseBullet" Abstract="True"> | <ThingDef Name="BaseBullet" Abstract="True"> | ||
− | </ThingDef></ | + | </ThingDef></pre> |
{| class="wikitable" | {| class="wikitable" | ||
Line 103: | Line 103: | ||
The following tags are relatively straightforward:<br/> | The following tags are relatively straightforward:<br/> | ||
− | < | + | <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></ | + | </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/> | ||
− | < | + | <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></ | + | </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/> | ||
− | < | + | <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></ | + | </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/> | ||
− | < | + | <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></ | + | </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/> | ||
− | < | + | <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></ | + | </ThingDef></pre> |
{| class="wikitable" | {| class="wikitable" | ||
Line 450: | Line 450: | ||
===Source=== | ===Source=== | ||
− | < | + | <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></ | + | </ThingDef></pre> |
=Special cases= | =Special cases= | ||
− | There's a few | + | There's a few guns that don't entirely follow the previously described structure. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
[[Category:Modding tutorials]] | [[Category:Modding tutorials]] |