Juz's Slipgate - Tutorials


Ammo SharingTutorial


This tutorial is taken from my mod Classic Quake Arena. Alot of people have been asking me how I got the shotgun and super shotgun to share the same ammo. There's no way (that I could see ;)) to get the two weapons to actually share ammo, so what you need is a bit of a workaround. I'll show you my way of doing it in this short tutorial. This tutorial assumes you have a good working knowledge of both C and the quake3 source code.

Preparatory coding

First of course you'll need the code in place for the two weapons you'd like to share ammo. The Shotgun is set up as normal, as WP_SHOTGUN, and my new single barrelled shotgun is WP_SISHOTGUN. The ammo for the single shotgun in bg_misc is ammo_sishells, but this doesn't matter, as this doesn't get used. Before you do any more coding, you should just check that both of the weapons work properly and use their ammo properly, then you're ready to get on with the rest of the coding.

The Ammo Sharing code

Now onto the actually ammo sharing code itself. The principal is to make sure that every time some ammo is picked up, or one of the sharing weapons is fired, the other weapon has the same amount of ammo. First, in g_items.c, at the end of the function Add_Ammo, after the line ent->client->ps.ammo[weapon] += count; :

if(weapon == WP_SHOTGUN) {


} else if (weapon == WP_SISHOTGUN){

ent->client->ps.ammo [WP_SHOTGUN]=ent->client->ps.ammo[WP_SISHOTGUN];


This makes sure that when ammo for the shotgun gets picked up, the ammo for the single shotgun gets the same amount of ammo, and vice versa. You shouldn't need the second branch of the if/else, as you shouldn't put any ammo for the single shotgun in your maps, but just incase I thought it was a good idea to put it in. This code also handles picking up weapons as well as ammo boxes.

Then you need to make sure that both weapons have the same amount of ammo after one of the sharing weapons has been fired. To do this you need to add some code to bg_pmove.c, in the function PM_Weapon, just before the line PM_AddEvent( EV_FIRE_WEAPON ); :

if(pm->ps->weapon == WP_SISHOTGUN) {

pm->ps->ammo[ WP_SHOTGUN ] = pm->ps->ammo[ WP_SISHOTGUN ];

} else if(pm->ps->weapon == WP_NAILGUN) {

pm->ps->ammo[ WP_SUPERNAILGUN ] = pm->ps->ammo[ WP_NAILGUN ];


Everything is now set up. When you play the game you should find that both weapons always have the same amount of ammo. You can add some extra code so that one of the weapons uses two shells or whatever, you just have to make sure you cover all eventualities, such as the double-shot weapon having only 1 shell left.


You should be able to compile and run your mod as usual. Thanks for sticking with me throughout this tutorial, if you have any problems with it or i've left something out or got something wrong, please contact me at mailto:juz@planetquake.com