A Somewhat Less Brief History of How to Add Weapons


 

Posted by Thp (12.79.114.*) on April 29, 2000 at 15:01:21:
In reply to: A Brief History of How to Add Weapons posted by Thp (12.79.122.*) on April 29, 2000 at 09:29:31

: 9. Change the MOD_RAILGUN to MOD_DEATHRAY, and copy the Weapon_Railgun function in p_weapon.c, along with its related functions, change all "Railgun" to "DeathRay", and modify the functions to your heart's content.

Okay, I'm back. Lemme clarify.

9a. change MOD_RAILGUN to MOD_DEATHRAY. Open p_client.c, search through to where it reads "case MOD_RAILGUN:". add another entry like thus:

case MOD_DEATHRAY:
     message = "was taken care of by";
     message2 = "'s Death Ray";
     break;


9b. open p_weapon.c, and make a duplicate of the entire "railgun" section. rename Weapon_Railgun to Weapon_DeathRay, and rename weapon_railgun_fire to weapon_deathray_fire. Then change the line:


    Weapon_Generic (ent, 3, 18, 56, 61, pause_frames, fire_frames, weapon_railgun_fire);

to read


    Weapon_Generic (ent, 3, 18, 56, 61, pause_frames, fire_frames, weapon_deathray_fire);

Also change the call to "fire_rail" to call a function named "fire_deathray".

9c. Open g_weapon.c now, and add a function thusly to the end of it:


void fire_deathray(edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick) {

    // ...

    // Insert your code to fire the weapon here.

    // ...

}


Note that if you want to use a projectile weapon like the blaster or rocket launcher, you should copy the bulk of the code from one of these, as it includes checks to make monsters dodge properly and so forth. If you want a bullet-type weapon, there's no need to create a fire_deathray function at all, simply call fire_bullet with appropriate parameters.

Essentially, try to copy as much code as you can from the original Q2 weapons, because they're well-written and tested, then just change the parts you want to alter.

An example: In my mod, the Death Ray is a different-skinned railgun, and has a slightly different behavior in which it fires a random number of beams in a shotgun-like spread that do a very high *total* damage. The fire_deathray function simply chooses a random number of rays, then divides the "damage" value by that number. Then it loops through a block which is essentially the same as fire_rail that many times, so the sum total of all the damage delivered is 300. I copied the bulk of the code from the railgun, and modified only the effects and control.

: -- Thp