[Tutorial] Creating Custom Items with Special Abilities

By on September 29, 2010 7:48:41 AM from Elemental Forums Elemental Forums

kenata

Join Date 02/2006
+25

I have seen several posts on this subject, but I have not seen a good tutorial on this topic. This reason for this tutorial is simple, give a good example of how to make an item with a special ability, and explain some of the general pitfalls associated.

 

For this part of the tutorial, we are going to make a club which adds an additional attack we will call Club Smash, which does 125%-175% normal dmg and causes the target to lose their counterattacks for a round.

To start let's take the code for the Gnarled Club and rename it to "A Better Club". Remember to change the Internal Name unless you want to override the current gnarled club.

Code: xml
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <GameItemTypes>
  3.     <GameItemType InternalName="A_Better_Club">
  4.         <!-- Equipment Display Name/Description -->
  5.         <DisplayName>A Better Club</DisplayName>
  6.         <Description>Gnarled root of pine, ripped from the ground and fashioned into a club.</Description>
  7.         <!-- Data -->
  8.         <Type>Weapon</Type>
  9.         <WeaponType>Blunt</WeaponType>
  10.         <CanBeEquipped>1</CanBeEquipped>
  11.         <CustomizationPointCost>5</CustomizationPointCost>
  12.         <EquipSFX>Equip_WoodenItem_01</EquipSFX>
  13.         <EquipSFX>Equip_WoodenItem_02</EquipSFX>
  14.         <EquipSFX>Equip_WoodenItem_03</EquipSFX>
  15.         <EquipSFX>Equip_WoodenItem_04</EquipSFX>
  16.         <AttackSFX>Hit_Club1</AttackSFX>
  17.         <AttackSFX>Hit_Club2</AttackSFX>
  18.         <ShopValue>
  19.         </ShopValue>
  20.         <!-- Equipment Graphics -->
  21.         <IconFile>Earth_Club_Icon.png</IconFile>
  22.         <TintR>0</TintR>
  23.         <TintG>0</TintG>
  24.         <TintB>0</TintB>
  25.         <!-- Particles -->
  26.         <OnHitParticleName>Club_Attack</OnHitParticleName>
  27.         <GameItemTypeModel>
  28.             <ModelFile>gfx/hkb/Weapons/K_Club_01.hkb</ModelFile>
  29.             <Texture_All>K_Weapons_Basic_Texture_01.png</Texture_All>
  30.             <Attachment>hand_right_Lcf</Attachment>
  31.         </GameItemTypeModel>
  32.         <!-- Equipment Production Requirements -->
  33.         <ProductionRequirement>
  34.             <Type>Resource</Type>
  35.             <Attribute>Gold</Attribute>
  36.             <Value>2</Value>
  37.         </ProductionRequirement>
  38.         <ProductionRequirement>
  39.             <Type>Resource</Type>
  40.             <Attribute>Materials</Attribute>
  41.             <Value>3</Value>
  42.         </ProductionRequirement>
  43.         <!-- Equipment Prerequisites -->
  44.         <!-- Equipment Modifiers -->
  45.         <GameModifier>
  46.             <ModType>Unit</ModType>
  47.             <Attribute>AdjustUnitStat</Attribute>
  48.             <StrVal>UnitStat_Attack</StrVal>
  49.             <Value>2.0</Value>
  50.         </GameModifier>
  51.         <GameModifier>
  52.             <ModType>Unit</ModType>
  53.             <Attribute>AdjustUnitStat</Attribute>
  54.             <StrVal>UnitStat_BluntDamage</StrVal>
  55.         </GameModifier>
  56.         <GameModifier>
  57.             <ModType>Unit</ModType>
  58.             <Attribute>UnlockCombatAbility</Attribute>
  59.             <StrVal>Club_Smash</StrVal>
  60.         </GameModifier>
  61.     </GameItemType>
  62. </GameItemTypes>

We are not going to worry about most of this code, as we are probably ok with the look of this particular weapon. Remember the trick to easily making new weapons is always to select one that looks close enough to what you want. Our focus here will be on the last GameModifier.

Code: xml
  1. <GameModifier>
  2.     <ModType>Unit</ModType>
  3.     <Attribute>UnlockCombatAbility</Attribute>
  4.     <StrVal>Club_Smash</StrVal>
  5. </GameModifier>

This modifier gives the equipped unit access to a spell during tactical combat. If you try and put a strategic spell here, it will not show up outside of tactical combat. Now, you can add as many of these abilities as you wish to an item, though each requires its own gamemodifier.

*NOTE: Placement of these modifiers is very important. If you intend to put more than one ability on an item place the game modifier tags above the modifier for UnitStat_Attack. I have found that if you place them after a modifier without a value, it will only add the first ability.

So we have given told the game to unlock the Club Smash ability for our better club, now it is time to look at the ability itself.

Code: xml
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <Spells>
  3.     <SpellDef InternalName="Club_Smash">
  4.         <DisplayName>Club Smash</DisplayName>
  5.         <Description>Target enemy receives 125%-175% damage and can not counter for rest of it's turn.</Description>
  6.         <Image>WaterCrystal_Medallion.png</Image>
  7.         <IconFG>Crushing_Blow.png</IconFG>
  8.         <IconColor>32,45,243</IconColor>
  9.         <Range>1</Range>
  10.         <SoundFX>Hit_Hammer1</SoundFX>
  11.         <ManaCost>0</ManaCost>
  12.         <Cooldown>-1</Cooldown>
  13.         <SpellLevel>1</SpellLevel>
  14.         <SpellType>Tactical</SpellType>
  15.         <SpellClass>Offensive</SpellClass>
  16.         <SpellTargetType>EnemyUnit</SpellTargetType>
  17.         <IsSpecialAbility>1</IsSpecialAbility>
  18.         <GameModifier>
  19.           <ModType>Unit</ModType>
  20.           <Attribute>DefendableDamage</Attribute>
  21.           <Calculate InternalName="AttackerAttack" ValueOwner="CastingUnit">
  22.             <Expression><![CDATA[[UnitStat_Attack]]]></Expression>
  23.           </Calculate>
  24.           <Calculate InternalName="MinValue">
  25.             <Expression><![CDATA[[AttackerAttack] * -1.25]]></Expression>
  26.           </Calculate>
  27.           <Calculate InternalName="MaxValue">
  28.             <Expression><![CDATA[[AttackerAttack] * -1.75]]></Expression>
  29.           </Calculate>
  30.         </GameModifier>
  31.         <GameModifier>
  32.             <ModType>Unit</ModType>
  33.             <Attribute>DoesNotCounterAttack</Attribute>
  34.             <Duration>1</Duration>
  35.         </GameModifier>
  36.     </SpellDef>
  37. </Spells>

This is this club smash spell. This is a melee spell, with no spell effect, so it will look like just a normal attack. If you wish to add a spell effect, you can simply take the code for spell you like and append it like any other spell.

When looking at the code for the club smash spell, we will note the normal additions of descriptions,icons, colors, and sounds. For this spell, we have choosen to use the crushing blow icons and the hammer hit sound fx for flavor.

Our first point is the range of the spell, which we have set to 1, indicating it as a melee type spell, and spell radius, which is unshown. You can use any unsigned integer for the range if you wish, though to make it have unlimited range, use -1. If you use a 1 range and a 1 radius, your effect will take place in the three squares in front of the unit.


Next, we will talk about ManaCost as it is very important for our purposes. If you specify a non-zero mana cost, only units which have some mana will be capable of using your ability. While it will show up as available, it will always be marked as unusable by any unit which has no mana.

You have several options as to how to handle this particular issue.

The first which I do not recommend is to add a game modifier to your item which give essence to the unit. This could work, but unless you specify the item as not usable by champions and sovereigns, any champion who gets the item will immediately get essence and be capable of adding level up points to it.

The Second, which is shown here, is to make the ability cost 0 mana. Now a 0 mana spell can be cast as often as a normal attack. Since this spell is fairly powerful, we want to limit how often it can be used. To this end, we can either increase the movement cost associated with using the ability using a form of the tag, <MoveCost>10</MoveCost>, right under mana cost or we can add some kind of cool down to the spell. A Move cost of 10 is the same as using 1.0 combat speed for a normal unit.

*NOTE: Adding a tactical cooldown is currently broken as of v1.08 and will cause a CTD if you use the tag <cooldown> with an unsigned integer. However, if you set cooldown to -1, as we have done above, the ability becomes one time use.

After you have modified the frequency of the spell, you will want to add the tag <IsSpecialAbility>1</IsSpecialAbility>.

Once you have finished all of this, you can add in any game modifiers you would like. More than likely you will probably just take whatever spell you are trying to emulate and toss that code into this section. For Club Smash, we have set it to do a defendable hit ( a normal style hit) and then remove the targets counter attack for a turn. There are any number of things your items can be made to do, as it is as simple as making a spell to do them.

*NOTE: From my tests, defendable damage requires that you use a negative value for the damage. If you look at the calculations, you will see we have set them to be -1.25 and -1.50 which are 125% and 150% respectively.


Now that we have our spell completed and our item completed. Simply take your files containing these two things, throw them into your my games\elemental\Items Folder and you should see the new item in the design screen to make a new unit with them. If you did everything right, your new club man should have the club smash ability shown, and once used, a notice of the spell should be shown above the target to indicate the application of the counterattack debuff.

 

*Advanced: In the course of making my own mod, I wanted to make some abilities which did percentage buffs and debuffs. I found when calculating a value with these amounts that the results would be moderately unreliable. The problem it seemed was that the value would be calculated based on the final stat, but then added to the base with all other bonuses then taking effect. Instead of using a calculation for value, use the multiplier tag, as it will ensure that your changes take place after the other bonuses are applied.

<?xml version="1.0" encoding="ISO-8859-1"?>
<GameItemTypes>
    <GameItemType InternalName="GnarledClub">
        <!-- Equipment Display Name/Description -->
        <DisplayName>Gnarled Club</DisplayName>
        <Description>Gnarled root of pine, ripped from the ground and fashioned into a club.</Description>
        <!-- Data -->
        <Type>Weapon</Type>
        <WeaponType>Blunt</WeaponType>
        <CanBeEquipped>1</CanBeEquipped>
        <CustomizationPointCost>5</CustomizationPointCost>
        <EquipSFX>Equip_WoodenItem_01</EquipSFX>
        <EquipSFX>Equip_WoodenItem_02</EquipSFX>
        <EquipSFX>Equip_WoodenItem_03</EquipSFX>
        <EquipSFX>Equip_WoodenItem_04</EquipSFX>
        <AttackSFX>Hit_Club1</AttackSFX>
        <AttackSFX>Hit_Club2</AttackSFX>
        <ShopValue>
        </ShopValue>
        <!-- Equipment Graphics -->
        <IconFile>Earth_Club_Icon.png</IconFile>
        <TintR>0</TintR>
        <TintG>0</TintG>
        <TintB>0</TintB>
        <!-- Particles -->
        <OnHitParticleName>Club_Attack</OnHitParticleName>
        <GameItemTypeModel>
            <ModelFile>gfx/hkb/Weapons/K_Club_01.hkb</ModelFile>
            <Texture_All>K_Weapons_Basic_Texture_01.png</Texture_All>
            <Attachment>hand_right_Lcf</Attachment>
        </GameItemTypeModel>
        <!-- Equipment Production Requirements -->
        <ProductionRequirement>
            <Type>Resource</Type>
            <Attribute>Gold</Attribute>
            <Value>2</Value>
        </ProductionRequirement>
        <ProductionRequirement>
            <Type>Resource</Type>
            <Attribute>Materials</Attribute>
            <Value>3</Value>
        </ProductionRequirement>
        <!-- Equipment Prerequisites -->
        <!-- Equipment Modifiers -->
        <GameModifier>
            <ModType>Unit</ModType>
            <Attribute>AdjustUnitStat</Attribute>
            <StrVal>UnitStat_Attack</StrVal>
            <Value>2.0</Value>
        </GameModifier>
        <GameModifier>
            <ModType>Unit</ModType>
            <Attribute>AdjustUnitStat</Attribute>
            <StrVal>UnitStat_BluntDamage</StrVal>
        </GameModifier>
        <GameModifier>
            <ModType>Unit</ModType>
            <Attribute>UnlockCombatAbility</Attribute>
            <StrVal>Club_Smash</StrVal>
        </GameModifier>
    </GameItemType>
</GameItemTypes>
Locked Post 6 Replies +2
Search this post
Subscription Options


Reason for Karma (Optional)
Successfully updated karma reason!
September 29, 2010 9:00:28 AM from Elemental Forums Elemental Forums

Thanks Kenata. These are awesome. for you.

Reason for Karma (Optional)
Successfully updated karma reason!
September 30, 2010 5:05:07 AM from Elemental Forums Elemental Forums

Just a quick noob question: Why do you multiply by -1.25 and -1.75 instead of 1.25 and 1.75?  Excellent tutorial, by the way!

Reason for Karma (Optional)
Successfully updated karma reason!
September 30, 2010 6:44:36 AM from Elemental Forums Elemental Forums

Pretty sure it's because you are doing damage, the value is subtracted from HP. It seems a bit repetitive since you already stated that the modifier is "damage" but that's how it works. *shrugs*

Reason for Karma (Optional)
Successfully updated karma reason!
September 30, 2010 5:36:06 PM from Elemental Forums Elemental Forums

I am fairly certain that defendable dmg uses some form of curHealth internally, which would requires that you negate the current health. I'll make a note in the tutorial about this though.

Reason for Karma (Optional)
Successfully updated karma reason!
December 11, 2010 11:06:48 PM from Elemental Forums Elemental Forums

A quick note:

If you are designing an accessory that doesn't have a prerequisite, it might not appear in the shop until you have added it to the K_CityHubs.xml or F_CityHubs.xml.  These files are in the Elemental/Data/English/Core Improvements folder.        

<UnlocksShopItem>YourItemHere</UnlocksShopItem>

 

You'll need to add this for each city level in said file.  Note that this allows you to limit item availability to larger cities only, if you so wish.

And, of course, you'll need to save the modified file to My Documents/My Games/Elemental/Mods/Data... and have mods enabled.  Remember that this file will override any subsequent changes made to the Core Improvements file (should Stardock choose to update the CityHubs files).

 

Reason for Karma (Optional)
Successfully updated karma reason!
December 11, 2010 11:16:22 PM from Elemental Forums Elemental Forums

It will also show up in the store if you have the item prereq'd with a tech. Once the tech is researched, it will show up in the store.

 

Reason for Karma (Optional)
Successfully updated karma reason!
Stardock Forums v1.0.0.0    #101114  walnut1   Server Load Time: 00:00:00.0001015   Page Render Time: