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 [[ | + | It requires you to have [[User:Alistaire/Tutorials/Folder structure|set up a folder structure]] for your mod.<br/><br/> |
− | = | + | =First things first= |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===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/> | ||
− | < | + | <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 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/> | ||
− | < | + | <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 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/> | ||
− | < | + | <pre><ThingDef Name="BaseGun" Abstract="True"></pre><br/> |
− | The Name type means the contents of this '''<thingDef>''' can be ''inherited'' by | + | The Name type means the contents of this '''<thingDef>''' can be ''inherited'' 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 | + | The full BaseGun parent only has to be defined once in a file, and can then be referenced to 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 | + | Another parent is BaseBullet which holds every bullet and its 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 | + | 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 every normal gun ''<thingDef>'':<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 69: | ||
<ThingDef Name="BaseBullet" Abstract="True"> | <ThingDef Name="BaseBullet" Abstract="True"> | ||
− | </ThingDef></ | + | </ThingDef></pre> |
{| class="wikitable" | {| class="wikitable" | ||
Line 93: | Line 76: | ||
| <ThingDef> || 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. | | <ThingDef> || 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 | + | | 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 certain Name is to be inherited from, make sure the Name is Abstract. |
|- | |- | ||
| 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 | + | | 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 certain Name is to be inherited from, make sure the Name is Abstract. |
|}<br/> | |}<br/> | ||
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 125: | ||
<shaderType>Transparent</shaderType> | <shaderType>Transparent</shaderType> | ||
</graphicData> | </graphicData> | ||
− | </ThingDef></ | + | </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/> | ||
− | < | + | <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></ | + | </ThingDef></pre> |
{| class="wikitable" | {| class="wikitable" | ||
Line 235: | Line 218: | ||
| <inspectorTabs> || ''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). | | <inspectorTabs> || ''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). | ||
|- | |- | ||
− | !colspan="3"| ''<comps>'' | + | !colspan="3"| ''<comps>'' <li> ''</comps>'' |
|- | |- | ||
| <compClass> || ... || A C# class describing what should happen when the thing is interacted with in a specific way. This class might need additional tags to work. | | <compClass> || ... || A C# class describing what should happen when the thing is interacted with in a specific way. This class might need additional tags to work. | ||
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/> | ||
− | < | + | <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></ | + | </ThingDef></pre><br/> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | = | + | =Bullet_Pistol= |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | =Gun_Pistol= | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
[[Category:Modding tutorials]] | [[Category:Modding tutorials]] |