Main  |  Maps  |  Programming | Links |  Files |  Demos |  Forums

This tut shows you how to make a weapon fire when you release the attack key. Used in my mod for the Sniper Rifle. In this tutorial it will be used for the railgun. It is very easy and I would like to credit soWat for the majority of the code.

Open up bg_public.h and find this:
WEAPON_READY,

and directly beneath it add:
WEAPON_COCKED,

Open up bg_pmove.c and find this:
// check for fire

Then replace it and the function up under it with this:

// check for fire
// if they are pressing attack and their current weapon is the railgun
if ((pm->cmd.buttons & 1) && (pm->ps->weapon == WP_RAILGUN)) {
pm->ps->weaponTime = 0;
// put it in the "cocked" position
pm->ps->weaponstate = WEAPON_COCKED;
return;
}
// check for fire release
// if they arn't pressing attack
if (!(pm->cmd.buttons & 1)) {
// if we had them cocked and then they arnt pressing it then that means they released it
if (pm->ps->weaponstate == WEAPON_COCKED) {
// set to be able to fire
pm->ps->weaponstate = WEAPON_READY;
} else {
// else if they arn't pressing attack, then they just are running around
pm->ps->weaponTime = 0;
pm->ps->weaponstate = WEAPON_READY;
return;
}
}

I spend my time programming and writing these tutorials, so please feel free to use this code in your mod as long as www.inolen.com and the author receive credit.

Design Copyright inolen 2000