Quake DeveLS - Rolling Grenades

Author: TDaemon
Difficulty:
Easy(Well, it wasn't for me because I didn't have a tutorial, heheh)

Ok, so it's not the most exciting new weapon you've ever seen, but it's interesting and would be a good bases for a bowling ball, etc. It turns the grenade launcher into a rolling bomb of death launcher. Here we go.

Open up g_weapon.c and go down to the fire_grenade function.
Change it to this:

void fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed,
float timer, float damage_radius)
{
        edict_t *grenade;
        vec3_t  dir;
        vec3_t  forward, right, up;
        
        vectoangles (aimdir, dir);
        AngleVectors (dir, forward, right, up);
        grenade = G_Spawn();
        VectorCopy (start, grenade->s.origin);
        VectorScale (aimdir, speed, grenade->velocity);
        VectorMA (grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
        VectorMA (grenade->velocity, crandom() * 10.0, right, grenade->velocity);
        VectorSet (grenade->avelocity, 300, 300, 300);
        grenade->movetype = MOVETYPE_FLYMISSILE;              // changed this junk
        grenade->clipmask = MASK_SHOT;
        grenade->solid = SOLID_BBOX;
        grenade->s.effects |= EF_GRENADE;
        VectorClear (grenade->mins);
        VectorClear (grenade->maxs);
        grenade->s.modelindex = gi.modelindex ("models/objects/grenade/tris.md2");                 grenade->owner = self;
        grenade->touch = Grenade_Touch;
        grenade->nextthink = level.time + timer;
        grenade->think = Grenade_Explode;
        grenade->dmg = damage;
        grenade->dmg_radius = damage_radius;
        grenade->classname = "grenade";
        gi.linkentity (grenade);
 
        grenade->think = Grenade_Think;                         // added this junk
        grenade->nextthink = level.time + FRAMETIME;          // added this junk
}

Alright, let's see what we've done so far. Why'd we change the movetype to flymissile? Well shut your dirty mouth, I'm trying to explain. We don't want the rolling grenade to bounce, and we don't want it to slow down. Now, notice the extra "think" function. That stuff comes in right here. Above fire_grenade, type this:

void Grenade_Think (edict_t *self)
{
        int big_hairy_ape;
 
        for(big_hairy_ape = 0; big_hairy_ape < 150; big_hairy_ape++)  // constantly go down
        {
               self->s.origin[2] -= .25;
               M_CheckGround(self);                  // check and see if on ground
               if (self->groundentity)
               {
                       self->s.origin[2] += 5;               // if on ground, raise it a bit
                       self->groundentity = NULL;
               }
        }
        self->nextthink = level.time + FRAMETIME;
}

Alright, that's basically it. Easy huh? Yeah, well shut up! I spent some mad time figuring that stuff out! :) Anyway, do you see how the Grenade_Think function works?

The loop makes it lower on it's z axis. If you decrease the number 150 it will fall more slowly (See if you can make it most resemble the game's gravity.) During this loop, it constantly checks to see if it's on the ground, using M_CheckGround(self). If it is, then it raised a little bit. Hey, we don't want it to fall through the floor do we?

Now here is the cool part. By decreasing the loop number drastically you can make cool affects, like a rocket launcher that slowy loses speed and slowly falls.

Alright. See you later.

This site, and all content and graphics displayed on it,
are Šopyrighted to the Quake DeveLS team. All rights received.
Got a suggestion? Comment? Question? Hate mail? Send it to us!
Oh yeah, this site is best viewed in 16 Bit or higher, with the resolution on 800*600.
Thanks to Planet Quake for their great help and support with hosting.
Best viewed with Netscape 4