Q3 Coding
Making a Rail Arena Mod

Date : 24/01/99
Author(s) : Wilka
Skill(s) : Easy
Source Project(s) : Game
Revision : 2

This tutorial will cover the steps needed to make a 'Rail Arena' type mod (all weapons are Railgun's, and all the ammo boxes are  slugs). 

Setting Start Weapon

The first thing we need to do is make sure that the players don't start with a machine gun, cos then they would just use that until they pick up a Railgun, and we don't want that. You could make the player start with a Railgun, but I'd rather have then running about helplessly with the gauntlet until the get a real weapon :)

So open up g_client.c and go down to line 1008, then add the code follow the code (the stuff in between //Wilka and //W is the new code)

This is added after an triggers have been fired, so that any target_give entities wont start the player with a Railgun (all weapons are going to be Railgun's, so you wont be able to the give player any other weapon)

Spawning Railgun's

Now that we've stopped the player running about with a machine gun, we need to change all weapons to Railgun's. For that we need to edit the G_CallSpawn function in g_spawn.c (line 248). Just after the classname is checked to make sure it's not NULL, we need to add our code to change class name to the one we want (a Railgun). So add the following code to G_CallSpawn.

If you compile and test the mod, you'll see that all the Rocket Launchers are now Railgun's. But we want all weapons to be Railgun's, so this isn't good enough. We could check each for each weapon_* class name, using lots of if/else statements, the same way ClientCommand in g_cmds.c works, but since we only need to check if the class name starts with "weapon_" there's a much better way to do this. We need to write a function that will return the left part of a string for us. Instead of returning the first 7 chars, or the text up the first '_', we should pass an int telling the function how much of the string we want. Doing it this way means that the function could be used in other situations, without us needed to re-write any of it (and therefore change the old code that uses the function). So scroll up to just before the comment for G_CallSpawn (around line 253), and add this function.

This G_WLK_GetLeft function copies the source string (pszSource) using the strcpy function, then sets the char at position iSize to NULL ('/0', NULL and 0 are all the same thing. But it's better to use '/0' when working with text ) . In C, a string is terminated by a NULL. So we're marking the end of the string, at the position iSize. Now we can go back to G_ClassSpawn and change our code to use the function we just created. We can also add the code for ammo, since it's almost the same. So change the stuff inside of the //Wilka //W comments to look like this.

Now when you run this mod, all weapons will be replaced with Railgun's and all ammo will be replaced with Slugs. A good way to expand on this mod would be to add a cvar that sets the weapon to use, so it doesn't always need to be the Railgun. Something like g_arenaWeapon, then you can use a switch block to see what class name should be used instead of weapon_railgun. If you don't know how to create new cvars, or how switch statements works, have a look at my tutorial on creating a basic mod.

I Fixed the textboxes in Netscape (I'd missed the form tag), thanks to WarZone for letting me know.


Tutorial by Wilka
Wiretap Development
Wiretap HQ