Chapter 4: Super Duper New Person Guide
The Hello World of Cortex Command.
Here, I will attempt to create a tutorial that will let any new member quickly start on the path of modding greatness, as well as instill a sense of modding that keep them from making boring generic mods. Success ensues. Also, the number one thing I would like for this particular tutorial is criticism. Please tell me how you would like this changed to better help the learning process.
So you want to make a mod?
Well, first thing you're going to have to do is download Cortex Command. Got that? Good.
Now navigate to your Cortex Command folder. In it you will see many files. Most of these are useless to you, but there are a few important ones.
- Cortex Command.exe (Pretty important)
- Base.rte (Super important)
- PromGrounds.rte (A bit important)
If you cannot see the extensions on the files (.exe, .rte, .ini), you need to turn that option on. In Windows, open any folder. Find the "Folder Options" option, switch to the "View" tab, and where it says "Hide extensions for known filetypes", uncheck that box. You want to see the extensions, so that you can edit them later.
Personally, I learn best by example, but this tutorial isn't for me, so I won't tell you to just look at the code until you get it. I'll walk you through the mod creation process. The hardest part for most people is syntax. Syntax is the grammar of the game's language. If you don't make your mods according to a very specific syntax, it will give you lots of errors. If you have really, really bad spelling, turn back now. Also, I'll be comparing your new mod's structure to PromGrounds.rte a lot, because that's how the original modmakers learn how to create mods. Data doesn't like us enough to give us documentation.
I won't go over the exact details of every file in Base.rte. Eventually, all that info will be available on the wiki, but for now, let's just start by creating a fresh modding set up for you to work with. To begin, right click and create a new folder in the Cortex Command folder (Not inside base.rte or promgrounds.rte). You can name your folder whatever you want, but for the game to see it, you'll have to add a ".rte" at the end, just like "PromGrounds.rte". Data has never really told us what "rte" stands for, but I'd guess something like "Run Time Environment" or "Ready To Eat" or something fancy like that. You don't really need to know all the fancy behind-the-scenes info, though.
You have so far:
If you look inside PromGrounds.rte, you'll see that it has a few files. These are going to be very important to your modmaking career. The first, most important file is the "Index.ini". Without this file, your mod won't run. Don't be frightened of the ".ini" suffix, either. It's really just a text file. Try opening "Index.ini" with a text editor like notepad or my favorite Notepad++. I wouldn't use Word, though. Word saves files kind of weird, so the game probably won't be able to read it.
Once you open Index.ini in PromGrounds.rte, you'll see.. not much:
Code:
DataModule
IncludeFile = Promgrounds.rte/Scenes.ini
The DataModule part tells the game that this is infact a CC mod, and it should be included in the game.
The IncludeFile part tells the game which files in your mod to use. In this case, to use the Scenes.ini file.
This gets a bit tricky, because if you're a first time modder/coder you might not understand exactly how this syntax works. There are rules, see.
For just this small file, you have to know all this:
- The file has to be called "Index.ini"
- DataModule has to be spelled exactly that way, captialization counts. IncludeFile, too.
- DataModule has to be the first thing the game sees. No putting stuff in front of it. (Except comments)
- IncludeFile has to be on it's own line.
- IncludeFile has to have a tab infront of it. (Or equivalent whitespace. You can also use 4 spaces, but that's just more work. But not 3 spaces or 5 spaces.)
- After the word IncludeFile, there must be a space and then an "=" sign, and then another space.
- After that, you must have a valid file path. You must use forward slashes ("/"), and correctly spell everything. (Capitalization doesn't count here)
- The file path is always relative to your top folder in the mod. This means that you can't use any files that aren't inculded inside your mod's folder. (MyNewMod.rte)
- You must always include the mod's .rte folder in the path. Or, you can use Base.rte, but you can't use any other .rtes. (I.E. You can't use files in PromGrounds.rte from your MyNewMod.rte.
Intimidating, I know. But other than that, you can do quite a lot. For instance, you can add another "IncludeFile" line, and include more files. So you don't have to put everything in one file.
To make a new .ini file, all you have to do is right click, go to New..., and then choose Text Document. It will give you a New Text Document.txt. Rename this to "Index.ini" (Make sure it doesn't have the ".txt" at the end. Just ".ini". If you don't see the .txt in the first place, go up a bit and make Windows show you the file extensions like I told you to). Windows will tell you that changing the file extension might break things, but in this case, it won't, so just click "Yes".
For now let's just do something like this:
Code:
DataModule
IncludeFile = MyNewMod.rte/MyNewGun.ini
Of course, as you're following this, you can always change the name to something else. But if you do, you have to change it everywhere that it's used.
So, to start off, we're going to make a gun. It is good coding to give each prominent object in your mod it's own file. This way, you can quickly find the object if there's an error. If you start to get up to around 1000-2000 lines of code, you're not going to be able to debug it quickly, and it's best to seperate it into a couple of files.
So, since you've said that there's a MyNewGun.ini in your Index.ini, go ahead and make that file the same way you make the "Index.ini".
Now for the Hello World bit.
Since you can use objects that have already been defined in Base.rte, I'll show you how to make a gun using some of the default objects.
First thing to do when creating a new gun:
Code:
AddDevice = HDFirearm
Put this as the first line of your "MyNewGun.ini" file. This tells the game that you're creating a new weapon, and you want that weapon to be added to the game's internal list of weapons, so that you can use it later.
On the next line (hit enter once), You want to define some of the properties of your new gun. The way to do this is by adding one (1) more tab than the last line. For instance, since your new gun (The AddDevice line) has no tabs in front of it, all of the properties of that gun will be on the lines with one tab. If your gun had an object as a property (We'll get to this in a sec, hang with me), the properties of that object would have two tabs in front of them.
A good start would be to name your gun.
Add:
Code:
InstanceName = Hello World
Make sure that you have the one (1) tab on that new line.
So far, the code looks like this:
Code:
AddDevice = HDFirearm
InstanceName = Hello World
What you've done is created a new weapon (HDFirearm) and set the InstanceName property of that object (Hello World). This means that the game will call the gun "Hello World". I hope this is all clear.
Since this will be the most basic of guns, we'll skip some of the less-needed properties, and just let them be their default values. A great thing about Cortex Command coding is that you don't actually need to set all of the properties of an object. Just that ones that will make your object unique.
However, you do need a few basic properties set if you want to be able to use the gun. For an HDFirearm, you have to have at least:
- InstanceName (needed by all objects)
- GetsHitByMOs (so you can interact with the object)
- SpriteFile (if you want to be able to see your object, I mean you could leave it out, but then you can't see it. And not the cool invisibility kind of not see, I mean like the I can't hit it or pick it up or load it without an error probably kind of not see)
- AtomGroup (this tells the game about the object's collision and how it will hit other objects and the terrain)
- Magazine (to hold the bullets. If you don't have a magazine, the bullets will all fall out.)
- RateOfFire (or else it defaults to 0, which is not a very high rate of fire.)
That's pretty much it. Course, that would be one boring gun. It would have default values for all the cool stuff like RateOfFire and FireSound.
But let's just start out by creating a boring gun. You can add fancyness to it later, if you want.
Next up on the list is the GetsHitByMOs property. This property can either be set to 1 or 0. On or off. If you try to set it to something like 1337, it'll give you an error. Right now, we want to set it to 1, so that way MOs (Moving Objects) will be able to collide. Specifically, we want the actors to be able to collide their hands with it and be able to pick it up.
Add this code right under InstanceName:
Next let's do the SpriteFile property.
You're going to need a .bmp image to assign to the gun.
I'm sure you can find some tutorials around here on the specifics of creating paletted .bmp images for CC, but that takes a long time to explain, and instead, I'll just give you an wholly original image to use.
Attachment:
MyNewImage.bmp
Download that, and stick it in your mod folder. If you've got your own image, you can use that too. But beware, because the CC palette is a finicky thing, and just any image won't do.
Now that you've got your image, go back to MyNewGun.ini, and add these lines:
Code:
SpriteFile = ContentFile
FilePath = MyNewMod.rte/MyNewImage.bmp
Lets explain this a bit, it's easy really. SpriteFile is the property of the HDFirearm that sets what the image will be. The SpriteFile is set to a ContentFile object. Remember back when I told you you could set properties to other objects? Here, setting the SpriteFile to a ContentFile creates a new ContentFile object. ContentFile objects have their own properties that need to be set, so you go to a new line, and add another tab to show that you're setting the ContentFile's properties and not the HDFirearm's properties.
ContentFile has one property that you can set, which is FilePath. FilePath tells the game where to find this sprite. It works a lot like how IncludeFile works from the Index.ini, except now you want it to point to an image. Cortex Command only accepts .bmps in it's special palette, so set the FilePath to the path of the image. Now your gun will show up with that image ingame.
Next you'll need to set an AtomGroup property. These are a bit tricky and complex. Infact, I'm not 100% certain what all of it does, suffice to say, I would just go ahead and copy this stuff:
Code:
AtomGroup = AtomGroup
AutoGenerate = 1
Material = Material
CopyOf = Military Stuff
Resolution = 2
Depth = 0
Technical description is that AtomGroups are groups of "Atoms" that CC uses to calculate collision on a pixel-by-pixel basis somehow fancy. The material is what the atoms are made of, which in turn changes how the pixels collide. Military Stuff is one of the default materials. Resolution is something fancy. Depth is how deep into the sprite the atomgroup starts generating atoms.
But that's all for another tutorial. You don't need to know any of it. AtomGroups are generated automatically by themselves.
Now we need to give the gun a magazine. The Magazine property tells the gun what kind and how many bullets to fire. Magazines are actual objects in CC, but we'll put off making a whole new magazine, and I'll show you a different way to add objects. Instead of creating whole new objects, you can copy the properties of other objects of the same type to save time.
Add this code to the end:
Code:
Magazine = Magazine
CopyOf = Magazine Pistol
What you've done is set the Magazine property of the HDFirearm to a new Magazine object. Then you set all the properties of the new Magazine to be the same as the properties of the object "Magazine Pistol", which happens to be the magazine used in the pistol's code.
Lastly, set the RateOfFire. You might be able to figure it out yourself even. All you need to do is go to a new line, press tab, type out RateOfFire, use an equals sign, and then give it any number between 1 and 2147483647. I would recommend a nice round number like 500. The rate of fire in CC is actually number of bullets per minute. So setting it to 500 would mean that your gun will fire 500 bullets if you were firing it for a full minute and you had enough ammo. If you don't set RateOfFire, it won't give you an error, but your gun won't fire any bullets either.
And that is it.
Now all you have to do is save your .ini file, make sure everything is in the right place, and start up Cortex Command. While it's loading, you should see your mod zip by quickly at the end. If you don't, then you've probably named the .rte wrong.
Once the game finishes loading, just start up a skirmish on a scene where you can place stuff, go down to "Weapons", and you should see "Hello World" if all went well. Place your gun, pick it up, and be amazed at the power of Cortex Command .ini modification!
Questions/Comments feel free to PM me or post in this thread. Tell me what you'd like me to add or change.
Where to next?
- Try looking at the Wiki (The tutorials area is a bit more filled out right now).
- Download other people's mods and learn from them.
- Ask some of the fancy cool mod makers. Most of them like feeling smart and answering questions. Make sure you use PMs, though. That's the best way to get your question answered.
- Try out the Minor Mod Compendium Thread: viewtopic.php?f=1&t=11394
- Look at the Base.rte code and see how the master himself, Data, created the basic stuff.