As a reminder, this requires modloader version 0.10.0 [Click for Modloader]
I use Notepad++ to write my XML code and I suggest you download it as well.
1. A word on IDs and Navigating the XML code
Numeric IDs is how the game sorts relevant pieces of data, and you'll need to assign them as you build your mod. Mid, eid, tid, etc. These all are some type of ID.
The easiest way to keep track of IDs is to use a spreadsheet. Remember your mod ID? Well, that will prefix the other 5 digits that makes up your numeric IDs. So if your mod ID is 5257 then your numeric ID's will be all 5257XXXXX (Nine digits). I like starting with 525700000 and then incrementing by 100 or so, for each grouping of id's. This might sound confusing at first, but this will help you down the line if you want to add in more content.
I use LibreOffice but Google Docs works too.
My spreadsheet looks like this:

Now a word on navigating the XML code.
Remember:
1.XML is hierarchical
2. It must be well formed (free of syntax errors)
3. it's simply a way of storing data.
Thus, this leads us to the next thing. The parent node for the haven document is:
<data>
<NextTag>...</NextTag>
</data>
Everything within the haven.xml file is enclosed with a set of data tags. This is necessary for the xml to be well formed (see rule 2).
2. Setting up the haven.xml file
Setting up the haven file is fairly simple. Within the data tags we'll create another set of tags, but first we need to answer our questions from part 2.
We're going to use the five seven pistol as our base item, as described in part 2, and we're going to assume that we want to use an in-game animation, icon and condition for the effect. We're going to make an electric pistol!
To finish setting up our haven file, we need one more set of tags. Replace <NextTag></NextTag> with <Item></Item>.
(This is based on the five seven pistol item found in the haven_annonated.xml file)
<data>
<Item></Item>
</data>
3. Setting the weapon up
This is the easy part, it's mostly copy paste. But it gets slightly more difficult from here on in.
Copy and paste the item definition for the five seven pistol into your mods haven.xml file. This should look like this:
<data>
<Item>
<item _annotation="Five-Seven Pistol" eid="0" handness="SingleHand" mid="760">
<name tid="506" />
<desc tid="507" />
<anims>
<l dir="D1" inFront="true" leftArmInFront="true" lx="5" ly="-8" rightArmInFront="false" rx="-7" ry="2" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-3" />
</l>
<l dir="D6" inFront="true" leftArmInFront="false" lx="4" ly="1" rightArmInFront="true" rx="2" ry="-2" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-2" />
</l>
<l dir="D2" inFront="true" leftArmInFront="false" lx="8" ly="-7" rightArmInFront="false" rx="-10" ry="-5" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-6" />
</l>
<l dir="D3" inFront="true" leftArmInFront="false" lx="13" ly="-2" rightArmInFront="true" rx="1" ry="-9" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-1" />
</l>
<l dir="D9" inFront="true" leftArmInFront="false" lx="-2" ly="-1" rightArmInFront="true" rx="6" ry="-3" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-3" />
</l>
<l dir="D8" inFront="true" leftArmInFront="false" lx="-8" ly="-7" rightArmInFront="false" rx="7" ry="-6" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-4" />
</l>
<l dir="D4" inFront="true" leftArmInFront="true" lx="-1" ly="-13" rightArmInFront="false" rx="-2" ry="-9" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-8" />
</l>
<l dir="D7" inFront="true" leftArmInFront="true" lx="2" ly="-5" rightArmInFront="false" rx="8" ry="-3" type="ItemSingleS" useFlipped="true">
<animation aid="pistol1-1" />
</l>
</anims>
<invIcon aid="pistol1inv" />
<fabricateable cat="Weapons">
<GUIAnim aid="pistol1inv" />
<cost buildTools="0" partsPerTile="1" type="Defined">
<resources>
<l _annotation="Steel Plates" consumeEvery="3" element="1922" howMuch="1" />
<l _annotation="Plastics" consumeEvery="1" element="175" howMuch="1" />
</resources>
<difficultyLevel level="1" skill="Industry" />
</cost>
</fabricateable>
<weapon fullLight="true" gunType="Pistol" id="0" speed="14" type="Gun" weaponSkillLevel="1">
<flare>
<flareProjectile aid="smallProjectile1" />
<flareEffect effect="718" />
</flare>
<gunModes>
<l accuracy="-10" afterCool="0.7" defMode="false" preCool="0.05" type="SnapShot" />
</gunModes>
<weaponAnims>
<l dir="D1" inFront="true" leftArmInFront="true" lx="2" ly="-8" rightArmInFront="false" rx="-11" ry="-1" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-1" />
</l>
<l dir="D2" inFront="true" leftArmInFront="false" lx="12" ly="-4" rightArmInFront="false" rx="-5" ry="-4" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-2" />
</l>
<l dir="D3" inFront="true" leftArmInFront="false" lx="17" ly="2" rightArmInFront="true" rx="5" ry="-6" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-3" />
</l>
<l dir="D4" inFront="false" leftArmInFront="true" lx="-9" ly="-6" rightArmInFront="false" rx="-11" ry="-2" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-4" />
</l>
<l dir="D6" inFront="false" leftArmInFront="false" lx="10" ly="3" rightArmInFront="true" rx="8" ry="-1" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-6" />
</l>
<l dir="D7" inFront="false" leftArmInFront="true" lx="-14" ly="-2" rightArmInFront="false" rx="-8" ry="1" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-7" />
</l>
<l dir="D8" inFront="false" leftArmInFront="true" lx="-13" ly="-2" rightArmInFront="true" rx="3" ry="-2" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-8" />
</l>
<l dir="D9" inFront="false" leftArmInFront="false" lx="4" ly="3" rightArmInFront="true" rx="10" ry="0" type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-9" />
</l>
</weaponAnims>
<projectile aid="smallProjectile2" />
<hit aid="3explosion" />
<audio ignoreZoomLevel="false" noise="10.0">
<audio auid="990" />
</audio>
<bulletEffect effect="755" />
<light color="3a4e59fe" powerTier="None" skipCenter="false">
<offset x="0" y="0" />
<flood brightness="300" distance="6" />
</light>
<projectileLight color="401b00fe" powerTier="None" skipCenter="false">
<flood brightness="200" distance="2" />
</projectileLight>
<damageTypes>
<l damageType="Bullet" type="Person">
<level max="3" min="1" />
</l>
<l damageTier="HeavyFurniture" type="Structure" />
</damageTypes>
<positions>
<l direction="D1" offX="-12" offY="24" />
<l direction="D2" offX="-5" offY="18" />
<l direction="D3" offX="6" offY="21" />
<l direction="D6" offX="10" offY="24" />
<l direction="D9" offX="10" offY="31" />
<l direction="D8" offX="4" offY="37" />
<l direction="D7" offX="-7" offY="33" />
<l direction="D4" offX="-9" offY="30" />
</positions>
<bulletEffectPos>
<l direction="D1" offX="4" offY="3" />
<l direction="D2" offX="0" offY="4" />
<l direction="D3" offX="-4" offY="3" />
<l direction="D6" offX="-5" offY="0" />
<l direction="D9" offX="-4" offY="-1" />
<l direction="D8" offX="0" offY="-3" />
<l direction="D7" offX="4" offY="1" />
<l direction="D4" offX="5" offY="0" />
</bulletEffectPos>
<muzzle instance="10_AllMuzzles_muzzle1s" />
</weapon>
<backPackItem id="747" />
</item>
</Item>
</data>
Included in this definition is everything that makes the pistol function, down to the animations. We'll leave most of these sections unchanged, but take your time to familiarize yourself with some of the XML tags.
Of particular interest is the eid, mid, name id, desc id, the anims section (controls stored animations), the weapon anims section (controls equipped animations), the projectile aid (controls the projectile), the hit aid, the audio aid (controls sound effect), and muzzle instance="...". There is much more here though that I'm not totally sure what it all does. Trial and error might produce the effect you want, but as a note, bullet effect is a graphics sfx and not a pawn condition. The custom condition is something that occurs within the damageTypes tag that's near the bottom of the definition (more on this later).
4. Baby steps
Modding our weapon involves assigning ID's to the relevant sections and making sure that our XML document is well formed according to the data structure required by the game and modloader.
Enter these id's into a spreadsheet and fill in the appropriate information in the adjacent box to identify them.
A. assign an ID to the item mid (525700000), this is used to identify the item.
B. assign an ID for the name (525700051) and description tid (525700053). Notice that theres a gap between the last assigned id (the mid) of about 50 id's. This is if we decide to expand our mod later, and need more room for mids. Also notice the gap between the name and description tid. This is because each tool tip has two id's a tid (text ID as far as i know) and a pid (unknown). The pid seems to be unused but could be used later and I recommend assigning a new id to the name pid (525700051) and description pid (525700052) to keep things clean.
C. assign an ID to the eid, we'll use the number after the mid (525700001)
D. change the weapon costs, this is under the <fabricabtable></fabricateable> section. We'll change the Steel Plates cost to 0.5 and plastics cost to 0.5 by changing the consumeEvery value to 2.
E. add in the weapon cost section for energy cells. This requires searching the haven_annotated.xml file for the energy cell eid, and copying the existing definition to be where the rest of the definitions are. It should look like this:
<l _annotation="Energy Cell" consumeEvery="5" element="1926" howMuch="1" />
F. change the projectile to be blue. Enter smallProjectileBlue1 instead of smallProjectile1 for <projectile aid="..." />
G. change the muzzle to use the laser pistols (gasp!) muzzle - search the haven file using ctrl+f - then enter the appropriate muzzle name (10_AllMuzzles_muzzle1sBlue)
H. change the icon. We'lll use an ingame icon, meant for a laser pistol, but perfect for our laser pistol. Search the animations file for laserPistol1Inv. then enter that into the <GUIAnim aid="..." /> section
I. change the weapon sound. See the <audio></audio> section near the bottom? Change the aiud to the energy turrets aiud sound, found either thru the base game haven.xml or audio file.
I've put the code below to show you the changes.
<data>
<Item>
<item _annotation="Five-Seven Pistol" eid="525700001" handness="SingleHand" mid="525700000">
<name tid="525700051" />
<desc tid="525700053" />
<anims>
<l dir="D1" inFront="true" leftArmInFront="true" lx="5"
ly="-8" rightArmInFront="false" rx="-7" ry="2" type="ItemSingleS"
useFlipped="false">
<animation aid="pistol1-3" />
</l>
<l dir="D6" inFront="true" leftArmInFront="false"
lx="4" ly="1" rightArmInFront="true" rx="2" ry="-2" type="ItemSingleS"
useFlipped="false">
<animation aid="pistol1-2" />
</l>
<l dir="D2" inFront="true" leftArmInFront="false"
lx="8" ly="-7" rightArmInFront="false" rx="-10" ry="-5"
type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-6" />
</l>
<l dir="D3" inFront="true" leftArmInFront="false"
lx="13" ly="-2" rightArmInFront="true" rx="1" ry="-9" type="ItemSingleS"
useFlipped="false">
<animation aid="pistol1-1" />
</l>
<l dir="D9" inFront="true" leftArmInFront="false"
lx="-2" ly="-1" rightArmInFront="true" rx="6" ry="-3" type="ItemSingleS"
useFlipped="false">
<animation aid="pistol1-3" />
</l>
<l dir="D8" inFront="true" leftArmInFront="false"
lx="-8" ly="-7" rightArmInFront="false" rx="7" ry="-6"
type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-4" />
</l>
<l dir="D4" inFront="true" leftArmInFront="true"
lx="-1" ly="-13" rightArmInFront="false" rx="-2" ry="-9"
type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-8" />
</l>
<l dir="D7" inFront="true" leftArmInFront="true" lx="2"
ly="-5" rightArmInFront="false" rx="8" ry="-3" type="ItemSingleS"
useFlipped="true">
<animation aid="pistol1-1" />
</l>
</anims>
<invIcon aid="pistol1inv" />
<fabricateable cat="Weapons">
<GUIAnim aid="laserPistol1inv" />
<cost buildTools="0" partsPerTile="1" type="Defined">
<resources>
<l _annotation="Steel Plates" consumeEvery="2" element="1922" howMuch="1" />
<l _annotation="Plastics" consumeEvery="2" element="175" howMuch="1" />
<l _annotation="Energy Cell" consumeEvery="5" element="1926" howMuch="1" />
</resources>
<difficultyLevel level="1" skill="Industry" />
</cost>
</fabricateable>
<weapon fullLight="true" gunType="Pistol" id="0" speed="14" type="Gun" weaponSkillLevel="1">
<flare>
<flareProjectile aid="smallProjectile1" />
<flareEffect effect="718" />
</flare>
<gunModes>
<l accuracy="-10" afterCool="0.7" defMode="false" preCool="0.05" type="SnapShot" />
</gunModes>
<weaponAnims>
<l dir="D1" inFront="true" leftArmInFront="true"
lx="2" ly="-8" rightArmInFront="false" rx="-11" ry="-1"
type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-1" />
</l>
<l dir="D2" inFront="true" leftArmInFront="false"
lx="12" ly="-4" rightArmInFront="false" rx="-5" ry="-4"
type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-2" />
</l>
<l dir="D3" inFront="true" leftArmInFront="false"
lx="17" ly="2" rightArmInFront="true" rx="5" ry="-6" type="ItemSingleS"
useFlipped="false">
<animation aid="pistol1-3" />
</l>
<l dir="D4" inFront="false" leftArmInFront="true"
lx="-9" ly="-6" rightArmInFront="false" rx="-11" ry="-2"
type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-4" />
</l>
<l dir="D6" inFront="false" leftArmInFront="false"
lx="10" ly="3" rightArmInFront="true" rx="8" ry="-1" type="ItemSingleS"
useFlipped="false">
<animation aid="pistol1-6" />
</l>
<l dir="D7" inFront="false" leftArmInFront="true"
lx="-14" ly="-2" rightArmInFront="false" rx="-8" ry="1"
type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-7" />
</l>
<l dir="D8" inFront="false" leftArmInFront="true"
lx="-13" ly="-2" rightArmInFront="true" rx="3" ry="-2"
type="ItemSingleS" useFlipped="false">
<animation aid="pistol1-8" />
</l>
<l dir="D9" inFront="false" leftArmInFront="false"
lx="4" ly="3" rightArmInFront="true" rx="10" ry="0" type="ItemSingleS"
useFlipped="false">
<animation aid="pistol1-9" />
</l>
</weaponAnims>
<projectile aid="smallProjectile2" />
<hit aid="3explosion" />
<audio ignoreZoomLevel="false" noise="10.0">
<audio auid="2357" />
</audio>
<bulletEffect effect="755" />
<light color="3a4e59fe" powerTier="None" skipCenter="false">
<offset x="0" y="0" />
<flood brightness="300" distance="6" />
</light>
<projectileLight color="401b00fe" powerTier="None" skipCenter="false">
<flood brightness="200" distance="2" />
</projectileLight>
<damageTypes>
<l damageType="Bullet" type="Person">
<level max="3" min="1" />
</l>
<l damageTier="HeavyFurniture" type="Structure" />
</damageTypes>
<positions>
<l direction="D1" offX="-12" offY="24" />
<l direction="D2" offX="-5" offY="18" />
<l direction="D3" offX="6" offY="21" />
<l direction="D6" offX="10" offY="24" />
<l direction="D9" offX="10" offY="31" />
<l direction="D8" offX="4" offY="37" />
<l direction="D7" offX="-7" offY="33" />
<l direction="D4" offX="-9" offY="30" />
</positions>
<bulletEffectPos>
<l direction="D1" offX="4" offY="3" />
<l direction="D2" offX="0" offY="4" />
<l direction="D3" offX="-4" offY="3" />
<l direction="D6" offX="-5" offY="0" />
<l direction="D9" offX="-4" offY="-1" />
<l direction="D8" offX="0" offY="-3" />
<l direction="D7" offX="4" offY="1" />
<l direction="D4" offX="5" offY="0" />
</bulletEffectPos>
<muzzle instance="10_AllMuzzles_muzzle1sBlue" />
</weapon>
<backPackItem id="747" />
</item>
</Item>
</data>
5. Last steps - setting up the texts.xml file
The texts.xml file is fairly simple to set up. Everything is enclosed in a single set of <t></t> tags. Then the tags are individually named to represent what they are.
<t>
...
</t>
We need two things here, the pistol name tool tip and description tool tip. These each have a tid and a pid. Remember from before, the IDs we assigned? We'll use them in our texts.xml file now to link our tooltips in.
Find the relevant section of five seven pistol by either searching the base game texts.xml file for five-seven or by searching with id's found in the five-seven pistol entry item (506 for the name, 507 for the description.)
Copy and paste them into the texts.xml file in your mod folder, and then change the tags to reflect what item we're making. I've enclosed the code below to show you what I mean. Also change the id's and pid's to their appropriate valeus that we assigned above (this is where the spreadsheet comes in handy).
<t>
<item_electroPistol_name id="525700051" pid="525700052">
<EN>Electro Pistol</EN>
</item_electroPistol_name>
<item_electroPistol_desc id="525700053" pid="525700054">
<EN>A small electro shock pistol, very effective!</EN>
</item_electroPistol_desc>
</t>
6. Done!
Well, that was quite a bit to take in but we've made it to the end. If you've followed everything correctly, you should be left with a electro pistol that shoots a blue projectile, pew pew! This weapon should be buildable from the item fabricator.
Stay tuned for the next part of this tutorial where we explore custom anims, icons and conditions.
Cheers.
---
To be continued.
0 comments