October 24, 2009 - 11:48

This tutorial is made for somebody beginning at mods (like me Very Happy ),some parts (or even the whole thing Laughing ) may seem too long for more experienced users.
Also take note that i'm french,so if there are stranges things in what I say,tell me,and I will do my best to fix it.

This was made on the 24 of october in 2009,using C&C 3 version 1.9 and MOD SDK v5 (in case somebody dig this up after a long time)

The purpose of this tutorial is to create a drone,like the ones of the aircraft and vehicules facility,but that would repair the structures,and that would be attached to the NOD Crane.

Chapter 1: Before starting

For those who already created mods,this section may be useless,since I will be explaining the setup of the first files and folders to create a mod.

First locate your MOD SDK folder.
In this folder,open the Mods folder,that should already contains at least a mod called SampleMod.
Create a new folder with the name you want for this mod (I will call it YourMod from this point).
Enter your mod folder,create a folder called "data",enter it and we will start creating the basic files for a mod.

At this point,you should be in MOD SDK\Mods\YourMod\data.
Create a new text file and insert this into it:
<?xml version="1.0" encoding="UTF-8"?>
<AssetDeclaration xmlns="uri:ea.com:eala:asset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <!--Common includes for all mods-->
      <Include type="reference" source="DATA:static.xml" />
      <Include type="reference" source="DATA:global.xml" />    


Save it with the name "Mod.xml"

This file allows you to take into account or not modified files put inside your mod folder.
You can put little comments between <!-- and --> if you want to leave a note about something.
The comment I put is unnecessary and can be safely removed (like any comment).
This was the default content for this file.We will go back to it when we have started modding for real.

Create a new text file called mod.str,and put this into it:
// Allow to check if mod was loaded properly
Save it.

This file will allow you to modify various text in games,like units name or description.
Again,there are comments,this time the comments are texts starting with //

The current content will change the text of the quit button on the main menu of the game,allowing you to see if the mod worked or not.
Later,you can modify or remove this content.

3.First try to build the mod
Thanks to mod.str,we have our first modification to the game.
So we will try a build to check if it's working (if it's not working at this point,there will be less things to check for the cause).

Start a command line (either from the Start Menu/Execute and you type "cmd" and enter,or in Programs/Accessories/"Shell" or "Command Line" or something like that).
Then in windows explorer,select the path of your MOD SDK folder,including it (example: "E:\Command & Conquer 3\MOD SDK"),and press Ctrl+C
Then,in the command line,type "cd " (with the space),then insert the " character,do a right click,choose Paste to put the path of MOD SDK here,insert a " again,then press Enter.
If like me you're not on the C drive,type your drive letter follow by : then enter (in my case,I type "E:" then enter)
You're now in MOD SDK,type "BuildMod YourMod" and enter.
Lots of things will be displayed,you may want to have a look at it.At this point,the build process shouldn't fail (we've done nothing yet).
After looking at it as you wanted,you can quit the command line.

Now go in the mods installation folder (help in Where to place Mods so they work (*) tutorial).
You should find a folder called YourMod here,enter it.

If you don't find it,something went wrong in the build,you may want to redo a build to check the text and try to find some clues as to what went wrong,but until it's fixed,you can't continue from here.

4.First try to start the mod
In this folder you should find a (very small since almost empty Laughing ) file called YourMod.big.
This is the main file of the real mod,it contains all the data about your modifications.To play a mod,you need this file,and another file that we are going to create now.

Create a new text file named YourMod.skudef,and put this content in it:
mod-game 1.9
add-big YourMod.big
Save it.

This file is the mod loader.
The first line means that your mod is made for version 1.9 of the game (I think a mod can really start an older version of the game if it was made for it,based on how the game files are organized).
The second line tell the game to use the .big file containing your modifications.

Now it's time for a first launch of the game.2 choices at this point:
-use the mod launcher (when you insert the CD,2nd button I think)
-create a shortcut with command line parameters,to start your mod directly,and maybe use others parameters.
For the shortcut,copy an already existing shortcut,and in the target part,after the last " ,add -modConfig "PATH_OF_YOUR_INSTALLED_MOD\YourMod.skudef"
Replace PATH_OF_YOUR_INSTALLED_MOD with the path leading to the folder where your .skudef and .big file are.

Now start the game with your mod the way you want,and check if the quit button did change.

If it did,congratulations,you have the base to make a mod done.
You might want to make a copy of MOD SDK/Mods/YourMod to be able to start new mods later.
For the skudef file,you just have to change the mod name in it to match the mod folder and the .big file filename,not sure if it's worth a copy.

Now that that is done,time to really start creating the mod.

Chapter 2: Getting the files to modify

Time to go back to MOD SDK/mods/YourMod.

We have to choose the files we will modify (or use as basis for new things).
Before we start,I must say that I put my files in folders in my mod folder,folders like the ones of MOD SDK\CnC3Xml,so I can find things more easily.
This isn't an obligation,you can just put mixed files in your mod folder (this may be different for .ini or .w3x files,but I'm not using that yet).You can adapt that to your style later.

Since we want to add a new kind of drone to the existing NOD Crane,the first file will be:

MOD SDK\CnC3Xml\NOD\Structures\NODCrane.xml

Copy it into YourMod\NOD\data\Structures.
You may have to display the properties of the file and remove read-only mode to be able to edit it.

Then we need a drone.There are 2 drones in MOD SDK\CnC3Xml\NOD\Units: NODRepairAircraftDrone.xml (43 lines) and NODRepairDrone.xml (102 lines).
Editing the shorter should be easier Very Happy ,so copy NODRepairAircraftDrone.xml into YourMod\data\NOD\UnitsNew and rename it NODRepairStructureDrone.xml
Unlike the crane,we won't just modify an existing item,but create a new unit (else the effects of the modifications would spread to the others drones),that's why we called the folder UnitsNew instead of Units,and why
we renamed the file.

We will add more files later,but first,we go back to YourMod\data\mod.xml to include the files we are going to modify.
Open mod.xml and modify it so it's like this:
<?xml version="1.0" encoding="UTF-8"?>
<AssetDeclaration xmlns="uri:ea.com:eala:asset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <!--Common includes for all mods-->
      <Include type="reference" source="DATA:static.xml" />
      <Include type="reference" source="DATA:global.xml" />    
      <!--Modified Structures-->
      <Include type="all" source="DATA:YourMod/Data/NOD/Structures/NODCrane.xml" />
      <!--New Units-->
      <Include type="all" source="DATA:YourMod/Data/NOD/UnitsNew/NODRepairStructureDrone.xml" />   


Save it like that.

Mod.xml look for your files from the mods folder,that's why the paths start with the name of your mod.
The include type for common files is usually "all",but in somes cases it can be "reference".I personnally never used "reference" yet,except for the default files.
About the comments,again it's a personnal choice,you can remove them if you want.

Never forget to add a file you modified to mod.xml
When you have a non-working modification,checking that all the files are included is the first thing you should do.

Chapter 3: Modifying the drone

We have renamed the drone file into NODRepairStructureDrone.xml,but at this point,the content of the file is still the same,and it's a problem.
So let's open YourMod/Data/NOD/UnitsNew/NODRepairStructureDrone.xml

First we will review our objectives for the drone:
-set it as a different unit from vehicule and aircraft repairer drones.
-modify the existing content so the drone repair structures instead of aircrafts (or vehicles)
-adapt the drone to the fact it will be linked to the NOD Crane.
-adapt the repairing ability of the drone to structures (give more HP than to vehicles and aircrafts)

Depending on your approach,you might sometimes find your objectives along the way,or you may prepare and know them before doing any edit.
Since I already made my mod,I've adapted the objectives to fit the modifications I made (I'm cheating a bit Rolling Eyes )

1.Set the Structure Repair Drone as a different unit from vehicule and aircraft repairing drones

The main thing is the GameObject id.Find <GameObject then find id="NODRepairAircraftDrone" (the file is quite short,so it's easier than with others units Very Happy ).
Replace it so it becomes id="NODRepairStructureDrone"

Just like the filenames,don't put any spaces.You can put underscore if you really want it.
The id is really important,it allows the other files to identify an unit for various things (building it,deploying into it,giving a command set to it...).
Be careful to not use an already existing name.Maybe I should have made the name a bit more tricky,something like YourMod_NODRepairStructureDrone,at least that would never risk a conflict with an already existing unit.

The inheritFrom="NODRepairDrone",and the include tag at the beginning of the file targeting NODRepairDrone.xml,are not things needed to modify.
It means our drone got a hidden copy of "NODRepairDrone.xml" content,and will use it whenever we didn't redefine some part.
All units (are there exceptions?) inherits from at least one file defined in BaseObjects (we will have the opportunity to see those files a bit later).
In our case,we don't inherit from a BaseObject because NODRepairDrone is the one inheriting from a BaseObject.

Anyway,leaving the inheritFrom as it is,we have 2 more things to change: EditorName and Description.

For EditorName,replace it the same way as the id,with NODRepairStructureDrone.
The EditorName and the id are usually the same.

For Description,replace "Desc:NODRepairAircraftDrone" with "Desc:NODRepairStructureDrone".But you may have guessed that because of those ':',there's a trick here.

You will sometimes see things like that: "Name:unitid","Desc:unitid" or "Type:unitid".
Name is the usual name of the unit,Type the thing written in orange at production structure,and Desc the long description with abilities.
Those are links to texts who have localization.To modify or add this kind of text,you have to use the mod.str file (good,we already created it Smile ).

Open your mod.str file and add this:
//Mod texts

"Structure Repair Drone"

As you can see,I put a comment to separate the texts who are really part of the mod from the previous "default" text (quit button modifier).
The description is,in this case,Structure Repair Drone,it doesn't seem to fit what I said about what desc are,but I'm not quite sure it's used anyway.
Note that you can type \n in a desc to have the text in game go to next line after it.

Save the mod.str and exit it.As for NODRepairStructureDrone.xml,we are done with identity related things (we will talk about the name later,altough it's as unused as the desc)

2.Modify the existing content so the drone repair structures instead of aircrafts (or vehicles)

This part is simple (or at least it seems so Twisted Evil ).Since the aircraft repair drone that we copied to get our file,don't repair the same thing as the vehicle repair drone,then some obvious date should appear.And we have it:
   Relationship="ALLIES" />

Now there are 3 problems:
-the weird xai thing
-the Rule part
-the Include part

First the xai thing seems to be (I'm not sure,I admit) to specify a special way of inheriting data.
For safety we may want to check what NODRepairDrone.xml was using,to see how this filter work...but there's nothing.
NODRepairDrone.xml doesn't have it.So what are we replacing?Well NODRepairDrone.xml himself inherits from a base object,and it's time to check what is in it.
Go in MOD SDK\CnC3Xml\BaseObjects and open BaseRepairDrone.xml
Here we find the same sort of thing,but it look like that:
   Relationship="ALLIES" />

We also see a lot of various data thay may justify the use of xai,if its purpose is to avoid repeating all datas.
But for this object filter,we may as well get rid of the xai by taking the whole thing.
So in your NODRepairStructureDrone.xml,add this:
   Relationship="ALLIES" />
I'm not sure what the Rule thing do,but I prefer the behavior of the Vehicle Factory drones (I'm sure they go far to heal if necessary,never really tried with aircrafts).
I got rid of the xai thing (make things a tiny bit more readable),and I changed Include.For the keyword STRUCTURE,I navigated through various files,looking for "Filter",and i finally found that this was the keyword to use.It's not that obvious,because CIVILIAN_BUILDING also exist,and it uses BUILDING instead of STRUCTURE.But if you know a filter exist,it's easy to find it.

Don't close the BaseRepairDrone yet,we're going to use it again.

3.Adapt the drone to the fact it will be linked to the NOD Crane

If you open MOD SDK\CnC3Xml\NOD\Structures\NODCrane.xml and check the part ProjectedBuildabilityInfo,you will see Radius=150.
We will take that as the range of our drone,so the crane really seems to be able to repair anything in its range.

In AttachUpdate in your
NODRepairStructureDrone.xml file,find the line Range="=$REPAIR_DRONE_LEASH_DISTANCE" and replace it with Range="150".
To be honest,the value of this constant was already 150,but it's better to have it fixed in our drone,in case the constant would change in another version or for some other reason.
Since $REPAIR_DRONE_LEASH_DISTANCE was the only constant used here,you can remove this in your file:
   source="DATA:GlobalData/GlobalDefines.xml" />

4.Adapt the repairing ability of the drone to structures

To finish with NODRepairStructureDrone.xml,we will try to improve a bit our drone since it's working on structures and it's not the same conditions as with vehicles and aircrafts.

First we want it to give back more HP to a structure.But nothing is in our file about that,not even something about a healing weapon or something.
Checking NODRepairDrone.xml is also useless,so it's time to go back to BaseRepairDrone.xml.

SlavedUpdate part isn't useful (there are lot of range related things,but they don't affect the drone as far as I know).
PassiveAreaEffectBehavior is interesting,not only because it contains the hp the drone give to his target,but also because there's another filter here that may get in the way.
Here's the modified version of this part to use in NODRepairStructureDrone
   HealFX="FX_Repair" >
      Relationship="ALLIES" />
HealingPointsPerSecond was increased a bit and the allow filter was adapted like the other one.We keep the whole PassiveAreaEffectBehavior here,maybe some xai thing could allow to keep only what interest us,but I'm not confident about this thing.

Since we are here,let's check the rest of BaseRepairDrone.
SlowDeath is useless (it's the thing that make dead things fade out,used for controllable structures,but not for civilians structures,that leave ruins).
AttachUpdate is useful,since we already have it.The thing that kept my attention here is Flags.There are 2 values that I don't like here.

In NODRepairStructureDrone,in AttachUpdate (and before Object Filter),add this:

I removed SAME_PLAYER_ONLY,to be sure to be able to repair allies,and allied civilian buildings!
I removed ONE_ATTACH_PER_PARENT,so if there are many cranes at range,they will all send their drone.

And that's it for the drone.Next we will take care of the Crane.

Chapter 4: Modifying the NOD Crane

Now is the time to attach our drone to the crane.Our model for this will be the vehicle building structure of NOD.
In MOD SDK\CnC3Xml\NOD\Structures open the file NODDropZone.xml (sometimes it's called Drop Zone,sometimes it's called War Factory,and since I play the french version,I have no clue about the final name,but it's not that important if you can somehow understand what i'm talking about).
Let's look for the word "drone".
The first thing is in <Draws></Draws> section,so it's not interesting (I haven't used it,maybe it's the area on the ground showing the range of repair,but since our drone use the build radius as range,no need to add something like that).
The third thing is in <Behaviors></Behaviors>,a much more interesting area.
In fact,the whole SpawnBehavior things is interesting,so open YourMod\data\NOD\Structures\NODCrane.xml,and copy this at the end of the <Behaviors></Behaviors> section (before </Behaviors>):
      DeathTypes="ALL" />

The id is okay.If you're not sure,check NODHangar.xml (the aircraft builder),it's got the same even if it's using a different drone.
I changed SpawnNumberData and InitialBurst to 1,since I want only 1 drone on the crane (this can always be changed later for your own mod).
I changed what's between <SpawnTemplate></SpawnTemplate>,because we want the Crane to spawn our drone,not the vehicle repair drone.
The rest was OK and kept.

That's it for this chapter,because the AssignSlavesTargetObjectSpecialPower you can see in NODDropZone,that is obviously (or not?) related to drones,is covered in the next chapter.

Chapter 5: The icon to send drones on a target

In this chapter,we will give the NOD Crane a similar ability to the Vehicle Building,a command to send the drones to a specific target.

First,after the SpawnBehavior in your NODCrane.xml file,add this:
   SpecialPowerTemplate="SpecialPower_TargetedRepairStructure" />
This is a modified copy of the code in NODHangar.xml
But here,we are making the drones react to a superpower,but we don't have this superpower,nor a button to use it,yet.So we have to add all that.

Go in MOD SDK\CnC3Xml\GlobalData and copy UnitAbilityButtonTemplates.xml
Paste it into YourMod\Data\GlobalData and rename it NewUnitAbilityButtonTemplates.xml

Now edit your mod.xml file,and add this:
<!--New Global Data content-->
<Include type="all" source="DATA:TestMod/Data/GlobalData/NewSpecialPowerTemplates.xml" />
<Include type="all" source="DATA:TestMod/Data/GlobalData/NewLogicCommand.xml" />
<Include type="all" source="DATA:TestMod/Data/GlobalData/NewLogicCommandSet.xml" />
<Include type="all" source="DATA:TestMod/Data/GlobalData/NewUnitAbilityButtonTemplates.xml" />

NewSpecialPowerTemplates is a file that will allow you to create new superpowers (by taking example on MOD SDK\CnC3Xml\GlobalData\SpecialPowerTemplates.xml),controlling mainly the cost,range,type of targets,not that impressive.
NewLogicCommand is a file that will allow you to create new commands(by taking example on MOD SDK\CnC3Xml\GlobalData\LogicCommand.xml),commands being installed in the command set of an unit/structure,and being the link between ability buttons and the corresponding superpower (and for construction,the unit to be built is specified here)
NewLogicCommandSet is a file that will allow you to create new command sets (by taking example on MOD SDK\CnC3Xml\GlobalData\LogicCommandSet.xml),a command set being the list of commands an units can use (in case of building,commands that can be used on them too,since repair,sell and disable appear in the command set).
NewUnitAbilityButtonTemplates,unlike the others,don't allow to just create your own things,you have to get the whole file (that's what we did),else all the buttons controlled by UnitAbilityButtonTemplates.xml would disappear.Here,you will add a part that set the appearance of the button related to an ability,the cursor related to its use (normal cursor or big radius),and the texts related to the button.If you're looking for the most complicated thing it can do,check Command_AlienMastermindTeleportObjects Very Happy .


In YourMod/GlobalData,create a new file,rename it NewLogicCommand.xml,edit it and put that inside:
<?xml version="1.0" encoding="utf-8"?>
<AssetDeclaration xmlns="uri:ea.com:eala:asset">



How I got to this result:
-From the files in the sample mod,I knew i didn't have to copy the whole file for Armor,LogicCommand,LogicCommandSet and Weapons xml files,to add my changes (and after testing,I saw it was working for SpecialPowerTemplates too,but not for UnitAbilityButtonTemplates).
-I made a file with just the first 2 lines and the last line from
MOD SDK\CnC3Xml\GlobalData\LogicCommand.xml
-I looked for "repair" in the file,until I found Command_RepairVehicle,that had SpecialPower_TargetedRepairVehicle in it,already saw in the AssignSlavesTargetObjectSpecialPower section of the vehicle builder of NOD)
-Copied that to my NewLogicCommand file
-Modified it to get the final code


In YourMod/GlobalData,create a new file,rename it NewSpecialPowerTemplates.xml,edit it and put that inside:
   MaxCastRange="150" >

How I got to this result:
-From the files in the sample mod,I knew i didn't have to copy the whole file for Armor,LogicCommand,LogicCommandSet and Weapons xml files,to add my changes (and after testing,I saw it was working for SpecialPowerTemplates too,but not for UnitAbilityButtonTemplates).
-I made a file with just the first 2 lines and the last line from
MOD SDK\CnC3Xml\GlobalData\SpecialPowerTemplates.xml
-I looked for "repair" in the file,until I found SpecialPower_TargetedRepairVehicle,a name I saw everywhere Very Happy
-Copied that to my NewSpecialPowerTemplates file
-Changed the id with the name I've been using in all other files (SpecialPower_TargetedRepairStructure),changed the MaxCastRange to 150 (the range of the drone,but maybe it should be bigger than normal range after all,not sure),and finally changed the filter to the same thing that I put in my drone file.

3.NewLogicCommandSet .xml

In YourMod/GlobalData,create a new file and rename it NewLogicCommandSet.xml.
Open LogicCommandSet and look for NODCrane.
Here you have to copy the whole command set to avoid loosing some of the crane constructions.
Paste it in NewLogicCommandSet.
Copy/paste the first 2 lines and the last line from LogicCommandSet to NewLogicCommandSet.
Finally,you have to add a line of command between <Cmd></Cmd>,using the name of the command we made earlier
In the end it look like this:
<?xml version="1.0" encoding="utf-8"?>
<AssetDeclaration xmlns="uri:ea.com:eala:asset">

I put empty lines before and after the added command,you don't have to do it if you don't want to,but in this case it help to see what's different.


Time for the final boss.
Open your NewUnitAbilityButtonTemplates file (no need for the original since it's already a complete copy).
Find Command_RepairVehicle,make a copy of it right after the original (keep an empty line like between each button definition,like it's made) and modify it so it's like that:
   ValidTargetCursor="Bombard" >
      Description="DESC:AbilityRepairStructure" />

I changed the id to the name of the right command,kept the original image,and changed Title and Description to use new texts,that we will create.

But before we create the new texts,there's something we still have to do in this file.
Special thanks to Ju-Jin for answering my question on the forum,allowing me to figures why my mod ignored my NewUnitAbilityButtonTemplates file.

Go at the beginning of the file,and change the id from "UnitAbilityButtonTemplateStore" to "NewUnitAbilityButtonTemplateStore".

Save the file.

After the boss: Back to mod.str

It's like Ecco the Dolphin 2,still things to do after beating the final boss.But don't worry,unlike the game I named,it will be short and easy.

Open your mod.str file,and add an entry for NAME:AbilityRepairStructure and DESC:AbilityRepairStructure,I put that:
"Repair Structure"

"Send the drone to repair structures"

And we're done!

Chapter 6: Conclusion

Once you compile your mod,it's done.You can try and play it.
If you don't remember how to compile,it's at chapter 1,and 3.First try to build the mod.
After you compile,if you took the tutorial from the beginning,you should already have a working .skudef file,else in the same chapter,in ]4.First try to start the mod,I explained how to do it.

I would like to thank everybody in the forum for making it exist and/or live on by posting (even if it doesn't happen that often in C&C3 section or so it seems).
Special thanks for those who read my post before (I actually made more than 1,but it was as guest before Very Happy ),and tried to answer it,especially to Ju-Jin who gave me the final answer.

Good luck for all the modders,that will use my tutorial or not.

Sorry if my mod isn't enough to make a good beginning (didn't create a new ordinary unit and didn't use the weapon section,strange way to start I know),but I explained lots of things on the way,and it should useful anyway.

If I do another tutorial one day,as I do new things learning how to mod,I will skip chapters 1 and 2 Very Happy .

See you.

More than 450 lines,wonder if somebody will really read it all......