Main
Tutorials











 

Custom Crosshairs: Coding

Compared to the rest of this tutorial, coding is cake

Before we even start writing code, we need to get some folders set up first
Go to your UT2004 directory(C:/UT2004 by default) and create a folder called DemoXHairs(This can be anything, but we'll go this route for now)
Now open DemoXHairs and create a folder inside it called Classes. It is important you call it that or 2k4 won't be able to find the code



Now that the folders are set up, it's coding time.
Open up Notepad* or whatever you wish to use.
*There is a freeware program called ConText that has a code template for UScript. It's handy, but just worry about Notepad for now.

Now, in order to get your own pack in, you have to subclass UT2004's class for crosshairs.
This is how you subclass CrosshairPack(the 'parent' class)

class DemoCrosshairs extends CrosshairPack
     notplaceable;

NotPlaceable means that 2k4 will not allow it to be placed in a map(unlike teleporters, playerstarts, etc)
That isn't all, you also need to make sure 2k4 loads your UTX when the game loads.
You do that by adding an EXEC function.

#EXEC OBJ LOAD FILE=XHairDemo.utx

Spelling here is crucial, if you misspell the name of the UTX or parts of the code, the pack simply won't work.

Now for the DefaultProperties, which tell 2k4 which texture goes with which name.
This is what an empty DefaultProperties looks like. Make sure to add it to your code file

defaultproperties
{

}


Now, this is the code that needs to go between the brackets.

Crosshair(0)=(FriendlyName="DemoDot",CrosshairTexture=XHairDemo.imagename)

FriendlyName is the name that will be displayed in 2k4. Make sure it's in quotes. CrosshairTexture is where you reference the texture to be used. It goes in order of PackageName, GroupName and TextureName.
If no Group was made, it isn't needed.
Always make sure each texture is labelled differently. UT2004 messes up if 2 textures have the same name, even if in different groups.

If you plan on having multiple xhairs in your pack, each one needs their own line of code.
Here is an example from K-Aus Crosshairs

defaultproperties
{
     Crosshair(0)=(FriendlyName="[KAus] Adon",CrosshairTexture=KWS_XC.Adon)
     Crosshair(1)=(FriendlyName="[KAus] Aimbo",CrosshairTexture=KWS_XC.aimbo)
     Crosshair(2)=(FriendlyName="[KAus] Brac",CrosshairTexture=KWS_XC.brac)
}


Always start with Crosshair(0). And be smart with the FriendlyName. There are some characters that will cause 2k4 to abort the compile of the code.
So stick with what's on your keyboard(except for the | character, I think that might mess things up)

Assuming you followed the instructions correctly, your new code should look like this:

Class DemoCrosshairs extends Crosshairpack
     notplaceable;
     #EXEC OBJ LOAD FILE=XHairDemo.utx

defaultproperties
{
     Crosshair(0)=(FriendlyName="DemoDot",CrosshairTexture=XHairDemo.imagename)
}


If the code matches, you're Ok, time to save.
Click File -> Save As. The dialog box will appear with your save options.
Navigate to your UT2004\DemoXHairs\Classes folder but don't hit Save just yet, since 2k4 won't recognize .txt files.
Click in the FileName field and change the extension to .uc The filename should now be DemoCrosshairs.UC
And I cannot stress this more, the saving name of your file should match the Class name.
If you were to save it as DemoXhairs.uc instead of DemoCrosshairs.uc, when you go to compile, it will abort with a name mismatch.
Click Save and you're almost ready to compile.


Before you can compile, you need to make sure UCC will know it needs to compile your new code.
Open your UT2004.Ini with Notepad then do a quick search for EditPackages=
At the bottom of the list, add an extra line and add in EditPackages=DemoXHairs Always make sure your EditPackages line has the name of the folder your code is in.
If you put the name of your code file in there, UCC will not be able to find it.

Once you have that done, you should see something like this:

EditPackages=StreamlineFX
EditPackages=UTV2004c
EditPackages=UTV2004s
EditPackages=DemoXHairs


If you have the BonusPack installed, you'll see OnslaughtBP below UTV2004s.
Save the changes to your UT2004.Ini and you'll be ready to compile.


Next Page: UCC and Settings