Adding new Upgrades

Tutorial for Command & Conquer 3 C&C3

Avatar of Phil

Phil

Category: Code
Level: Beginner
Created: Sunday September 2, 2007 - 10:40
Updated: Monday November 23, 2009 - 9:01
Views: 7859
Summary: Learn how to add new upgrades to C&C3 step by step
Rating
  • Staff-
  • Members-
  • Average-

0 votes

Page 1 2
Okay, we have the upgrade, the command in the right commandset. What we need to do now is creating the new button, which will be displayed at the Command Post, for it. To do that, copy a file called UnitAbilityButtonTemplates.xml into your mod folder and rename it to NewUnitAbilityButtonTemplates.xml. This one is a bit tricky, as we need to keep all the original data in there, but need to rename the id attribute of the UnitAbilityButtonTemplateStore tag. Keep that in mind when you edit this kind of file with a parent tag containing all the rest.
To keep it simple we can just rename the id from UnitAbilityButtonTemplateStore to NewUnitAbilityButtonTemplateStore.
Now copy-paste this code to the top or bottom of the list:

              
Code
    <PlayerUpgradeButton
        Id="Command_PurchaseUpgradeTankRailgun">
        <State
            Image="Button_UpgradeRailGun"
            Title="NAME:PurchaseRailgun"
            Description="DESCRIPTION:PurchaseRailgun" />
    </PlayerUpgradeButton>

and edit it so that it looks like this:

              
Code
    <PlayerUpgradeButton
        Id="Command_PurchaseUpgradePitbullNukeRockets">
        <State
            Image="Button_UpgradeRailGun"
            Title="NAME:PurchasePitbullNukeRockets"
            Description="DESCRIPTION:PurchasePitbullNukeRockets" />
    </PlayerUpgradeButton>

Notice that the Id must be the same as the one of your LogicCommand. The Image refers to a button image and Title and Description are references to the STR file (we will deal with that later).
If you've chosen to add a new button for your upgrade, you probably want to edit this one too, in the original game both the upgrade and the button use the same image.


Perfect, now the new upgrade can be bought from the Command Post. Let's actually make it affect the unit. For that, copy GDIPitbull.xml (in CnC3Xml\GDI\Units) into your mod folder. Keep in mind not to edit any names here, we want to edit the original, not make a new one.

The first step is to tell the game that it should display the upgrade in the unit UI, so the player sees that the Pitbull can be upgraded with the new weapon.
To do that, add this code:

              
Code
<DisplayUpgrade>Upgrade_GDIArmoryPitbullNukeRocketsTech</DisplayUpgrade>

right below the DisplayName Tag. The Pitbull already has one such tag there, so the spot shouldn't be hard to find.
The next step is adding the upgrading logic. Search for a tag called StatusBitsUpgrade and you should find the code for the Mortar upgrade there.
Since we only want to upgrade the weapon and neither audio nor art settings, copying this block:

              
Code
    <StatusBitsUpgrade
        id="ModuleTag_UpgradeWeapon"
        StatusToSet="WEAPON_UPGRADED_01">
        <TriggeredBy>Upgrade_GDIArmoryPitbullMortar</TriggeredBy>
    </StatusBitsUpgrade>

and changing it into this:

              
Code
    <StatusBitsUpgrade
        id="ModuleTag_UpgradeWeaponTwo"
        StatusToSet="WEAPON_UPGRADED_02">
        <TriggeredBy>Upgrade_GDIArmoryPitbullNukeRocketsTech</TriggeredBy>
    </StatusBitsUpgrade>

will be enough for now. Notice the change of id: because every id of a behavior, the "ModuleTag", needs to be unique, we need to change this every time we copy a behavior. What text you write in there doesn't matter though.
The reference to the upgrade in the TriggeredBy block should be pretty obvious.
The weapon status we are setting is simply the one that isn't used for the Mortar (WEAPON_UPGRADED_01) or for veterancy (WEAPON_UPGRADED_03).

The last thing we edit in the Pitbull file is its WeaponSetUpdate, or the WeaponSlotTurret more percisely. By default, it looks like this:

              
Code
    <WeaponSlotTurret
        ID="1"
        AllowInterleavedFiring="false"
        InterleavedStyle="INTERLEAVE_FIRST_AVAILABLE"
        WeaponChoiceCriteria="PREFER_MOST_DAMAGE">
        <Weapon
            Ordering="PRIMARY_WEAPON"
            Template="GDIPitbullRocketWeapon" />
        <TurretSettings
            TurretTurnRate="2000"
            TurretPitchRate="200"
            AllowsPitch="true"
            MinIdleScanTime="1.0s"
            MaxIdleScanTime="5.0s"
            MinIdleScanAngle="0.0"
            MaxIdleScanAngle="90.0">
            <TurretAITargetChooserData
                CanAcquireDynamicIfAssignedOutOfRange="true" />
        </TurretSettings>
    </WeaponSlotTurret>

Now let's add a new weapon based on our newly set weapon status (WEAPON_UPGRADED_02), so the block should look like this:

              
Code
    <WeaponSlotTurret
        ID="1"
        AllowInterleavedFiring="false"
        InterleavedStyle="INTERLEAVE_FIRST_AVAILABLE"
        WeaponChoiceCriteria="PREFER_MOST_DAMAGE">
        
        <Weapon
            Ordering="PRIMARY_WEAPON"
            Template="GDIUberPitbullRocketWeapon" />
            
        <Weapon
            Ordering="PRIMARY_WEAPON"
            Template="GDIPitbullNukeRockets"
            ObjectStatus="WEAPON_UPGRADED_02" />
            
        <TurretSettings
            TurretTurnRate="2000"
            TurretPitchRate="200"
            AllowsPitch="true"
            MinIdleScanTime="1.0s"
            MaxIdleScanTime="5.0s"
            MinIdleScanAngle="0.0"
            MaxIdleScanAngle="90.0">
            <TurretAITargetChooserData
                CanAcquireDynamicIfAssignedOutOfRange="true" />
        </TurretSettings>
    </WeaponSlotTurret>

As you can see, we've added another primary weapon to the turret weaponset. This weapon will only be activated if the unit is in the defined status, so only after you've bought the upgrade. Since the WeaponChoiceCriteria is set to choose the weapon with the most damage, it will automatically use our new, more harmful weapon.
How the actual weapon code is added is not subject of this tutorial, so I'll just attach the two required files (one for the weapon and one for the projectile).

The very last thing we need to do now is adding the ingame strings to our STR file, so that the user knows what the upgrade does. Remember all the attibutes like NAME:PurchasePitbullNukeRockets or UpgradePrereq:GDIRailGuns? Those are the references to the STR file. So if you don't have one already, create a new file called mod.str (just a plain text file a with special extension) in your mod folder.
Enter the following text:

              
Code
NAME:PurchasePitbullNukeRockets
"Nuke Rockets Upgrade"
END

DESCRIPTION:PurchasePitbullNukeRockets
"Upgrades the Pitbull with Nuke Rockets \n Blows everything up n shit \n \n Left-click to begin researching"
END

UpgradeName:GDIPitbullNukeRockets
"Nuke Rockets"
END

UpgradePrereq:GDIPitbullNukeRockets
"Research at Tech Center"
END

UpgradeType:GDIPitbullNukeRockets
"Weapon Upgrade"
END

UpgradeDesc:GDIPitbullNukeRockets
"Additional Attack Damage"
END

As you can see it's really simple. Just copy-paste each string reference, add your text in quotes ( " " ) below and close the code with an END
If you want, take a look at the original strings to see what the strings for others upgrades are like.

That's it, we're through. Just include all the files in your mod.xml and you have successfully added your first upgrade. Of course this is only one simple example of what can be done with upgrades. I'll leave it to your imagination to find other uses or combinations of upgrade logic. Thanks for taking the time and reading through this whole tutorial.

Links / Downloads

 HitsAdded
Pitbull Nuke Rockets Weapon and Projectile2062September 2, 2007 - 13:27

Comments

Display order: Newest first

Hostile - Sunday September 16, 2007 - 16:11

I am understanding better why this was written the way it was. Because this is an overview of modding the files to achieve a result. Not explaining what each parameter does.

To do that would take another 10 tutorials. If you simply follow the tutorial as copy/paste, than take each section and closely examine it. It does make sense.

              
Code
<UpgradeTemplate id="Upgrade_GDIArmoryRailgunTech"
inheritFrom="BasePurchasableUpgrade"
DisplayName="UpgradeName:GDIRailGuns"
AcquireHint="UpgradePrereq:GDIRailGuns"
TypeDescription="UpgradeType:GDIRailGuns"
Description="UpgradeDesc:GDIRailGuns"
Type="PLAYER"
BuildTime="90.0s"
BuildCost="5000"
IconImage="Button_UpgradeRailGun"
/>


Take this example, many things are self explanitory.

inherit from: means it's a player upgrade. Once you purchase this upgrade all units will recieve the upgrade.

DisplayName: is the name of the upgrade ON the unit as it shows up in the game. This is a direct reference the "String" file that includes the actual text.

AquireHint/TypeDescription/Description: This is the string text that is referenced to show up when you hover over the actual upgrade you want to purchase. Not sure which is which yet.

Type="Player": Is this upgrade for just one unit or is it a global upgrade.

BuildTime/BuildCost/IconImage: These are self explanitory. How long does it take to complete the upgrade, how much does it cost, and what image should be used for this upgrade.

As you can see how much text it is simply to explain one portion of the code. Imagine explaining all that for each code snippet he quoted.

Stokbrood - Tuesday September 11, 2007 - 6:35

Very unclear, I stopped modding along at the beginning of the second page.

I don't like the method of just copying, pasting and adjusting things without knowing what I'm actually doing.

It would be much easier if you explain why we have to change the specific attributes you tell us to change (I got very confused with the sudden pop ups of the words Upgrade and Purchase). Also, at the beginning of the second page I had like 5 .xml files open.

Some very good tips:

- Replace the words containing PitbullRocketSomething with "NameOfYourMod"

- We, or at least I, I don't mind using Ctrl + F in Notepad. I wanna learn to mod, simply copying your text isn't sufficient.

I will absolutely try your tutorial again if you can make it understandable, cause there's no doubt you put quite some effort in making this tutorial, and I think you're halfway there, so thumb up for that :)

Hostile - Sunday September 2, 2007 - 16:10

I find this to be very striaghtfoward and easy to understand. Good work...

Return to top