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 2: | Line 2: | ||
{{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. | + | 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/> | |
− | + | =What you'll learn= | |
− | + | ||
− | + | 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:<br/> | ||
+ | |||
+ | YourModName/ | ||
+ | Defs/ | ||
+ | ThingDefs/ | ||
+ | Weapons_Guns.xml | ||
+ | |||
+ | <source lang="xml">../Mods/YourModName/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> | ||
+ | |||
+ | <!-- 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 --> | ||
− | + | <thingDef> | |
+ | </thingDef> | ||
+ | </ThingDefs></source><br/> | ||
=BaseGun and BaseBullet parent= | =BaseGun and BaseBullet parent= | ||
− | + | ===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/> | ||
− | + | 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/> | |
+ | |||
+ | '''<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/> | ||
+ | <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=== | ||
− | + | Let's start off with the first chunks of this code:<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"> | ||
+ | |- | ||
+ | | <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 <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 240: | ||
| <drawGUIOverlay> || ''boolean'' || Whether GUI will show up when you select this thing. | | <drawGUIOverlay> || ''boolean'' || Whether GUI will show up when you select this thing. | ||
|- | |- | ||
− | | <tickerType | + | | <tickerType%gt; || Never<br/>Normal<br/>... || Whether this thing has a C# Tick() function; whether something happens to the thing every in-game [[Tick]]. |
|- | |- | ||
| <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). | ||
Line 174: | Line 257: | ||
===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 | + | 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 511: | ||
===Burstfire=== | ===Burstfire=== | ||
− | Some guns, including the [[Assault | + | 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 526: | ||
===Sniper rifles=== | ===Sniper rifles=== | ||
− | The [[Sniper | + | 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 579: | ||
===Spacer technology=== | ===Spacer technology=== | ||
− | Guns like the [[Charge | + | 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 614: | ||
</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 | + | [[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=== |