Grenades that stick
to walls?
This is
a very short and simple tutorial.
In Quake3, when a grenade hits something that cannot be damaged, it will
bounce off. We are going to change the grenade launcher so that instead of
bouncing, they will stick.
Note: I am not the worlds greatest programmer by a long shot, so don't go crazy if you see a bit of bad programming in this tutorial. I would appreciate any suggested improvements or corrections you can offer. The code has been tested extensively and works fine.
In doing this tutorial I assume you know how to compile the source, and have played with the code before.
Okay, on with the tutorial. This is a server side modification.
Files to be
modified
g_missile.c
g_missile.c
Go down to the G_MissileImpact() function.
This is called by G_RunMissile everytime a missile
hits something.
Find this block of code:
// check for bounce
if ( !other->takedamage
&&
( ent->s.eFlags & ( EF_BOUNCE | EF_BOUNCE_HALF ) ) )
{
G_BounceMissile( ent, trace );
G_AddEvent( ent,
EV_GRENADE_BOUNCE, 0 );
return;
}
This is the code that is run when our grenade bounces.
If the missile hits something that cannot be
damaged, and it is the type of missile that bounces
if ( !other->takedamage
&& ( ent->s.eFlags & ( EF_BOUNCE | EF_BOUNCE_HALF ) ) )
{
Bounce the missile, and send an event (the
grenade bounce noise)
G_BounceMissile( ent, trace
);
G_AddEvent( ent, EV_GRENADE_BOUNCE, 0 );
To make the grenade stick and not bounce is a very simple modification of this code. The grenade is the only missile that can bounce, so a change to this code will not effect any other weapons.
Change the above block of code
to:
if ( !other->takedamage
&&
( ent->s.eFlags & ( EF_BOUNCE | EF_BOUNCE_HALF ) ) )
{
// G_BounceMissile( ent, trace );
// G_AddEvent( ent,
EV_GRENADE_BOUNCE, 0 );
G_SetOrigin( ent, trace->endpos ); //
ZYGOTE NEW LINE
return;
}
You will see that we have commented
(//) out
the line to tell the missile to bounce, and the line that sends a client side
event.
The new line
is:
G_SetOrigin( ent, trace->endpos ); // ZYGOTE NEW
LINE
This sets the origin of the grenade (where the grenade is in the world), to the surface of whatever it hit (the end of the trace).
That's
It!
That is all
there is to it.
Compile the
code. Now load up your favorite map with a grenade launcher and test it
out!