|
posted 11-20-98 11:35 AM CT (US)
Title: Nuclear Self-Destruct Add-on
Difficulty: Easy
By: Philip (aka Maj.Bitch)
Email: peblair@gv.net
Date: 11-16-98
Note: Please give credit where credit is due.
======================================================
I was out having a
cup of coffee and I was thinking (as
I usually am) of what new kind of weapon I could build
next. Then, I was thinking of that creature in the move
Predator I, who initiated a self-destruct device on his
forearm just before he was going to die. I thought, "I
could make that!!", so after a bit of coding, HERE IT IS!!
The Nuclear Self-Destruct device.
What is it?
If your health is
less or equal to 10 units, then you should
consider yourself in pretty bad shape!! So, if you are going
to die soon (because you're losing the frag fight or there are
too many more heavily armed opponents around and you are getting
your ass kicked) then trigger your nuclear self-destruct device
on your forearm! It doesn't cost anything because it is now
part of your standard issue weapons arsenal. Every Marine is
set down on a mission deep into Strogg territory has one.
So, hit that button and 4 nuclear BFG fireballs will shoot
out in the N,S,E,W directions from your current position and
completely obliterate everybody and anything in its path!!
If nobody comes into range within 60 seconds then the booby
trapped armor simply disappears.
Also, I've
implemented a shockwave effect too so that anybody
(who by chance happens to survive the bfg fireball) gets
blown up and backwards by your self destruct shockwave. That'll
clear the bastards out! Of course, you die in the explosion
but those bastards won't get a frag out of the deal and you'll
kill'em all on your way out!
Okay, let's get
started!
===============================================================
Open up your
g_cmds.c file and go near the bottom of your
ClientCommand() function and add the following as shown
by example..
---------- IF-ELSE
STATEMENTS --------
else if (Q_stricmp(cmd, "decoy") == 0 )
SP_Decoy(ent);
else if (Q_stricmp(cmd, "drone") == 0 )
Cmd_LaserDrone_f(ent);
else if (Q_stricmp(cmd, "teleport") == 0)
Cmd_Teleport_f(ent);
----------- ADD THESE LINES ------
else if (Q_stricmp(cmd, "selfdestruct") == 0)
Cmd_SelfDestruct_f(ent);
else if .....
This will activate
the self destruct device with
a single stroke of your aliased key.
============================================================
At a point just
above the ClientCommand() function in your
g_cmds.c file, add this new function..
//======================================================
void Cmd_SelfDestruct_f(edict_t *ent) {
edict_t *player=NULL;
vec3_t forward,backward,right,left,up;
int i;
// Don't allow
dead/respawning players to Self Destruct!
if (!G_ClientInGame(ent)) return;
if (ent->health
> 10) {
gi.centerprintf(ent, "Cannot Activate Nuclear Device!\n");
return; }
// For some reason,
must use VectorSet()..
VectorSet(forward,0,1,0);
VectorSet(right,1,0,0);
VectorSet(backward,0,-1,0);
VectorSet(left,-1,0,0);
// Fire BFG fireball
with dmg=200; speed=400; radius=1000
// in direction of each N,S,E,W compass points.
Fire_BFG(ent, ent->s.origin, forward, 200, 400, 1000);
Fire_BFG(ent, ent->s.origin, right, 200, 400, 1000);
Fire_BFG(ent, ent->s.origin, backward, 200, 400, 1000);
Fire_BFG(ent, ent->s.origin, left, 200, 400, 1000);
// Blow backward any
players in 1000 units radius.
for(i=0;i < game.maxclients;i++) {
player=g_edicts+i+1;
if (!G_ClientInGame(player)) continue;
if (ent==player) continue;
if (!G_Within_Radius(player->s.origin, ent->s.origin, 1000)) continue;
AngleVectors(player->s.angles, forward, right, up);
VectorMA(player->velocity, 200, forward, player->velocity);
VectorMA(player->velocity, 2000, up, player->velocity);
} // end for
}
============================================================
Lets open you g_weapons.c file and add these helper routines
and the source code somewhere near the top of the file.
NOTE: I've used
these helper routines in many of my previous
tutorials so you may already have them someplace in your source.
If you already do have them, then you don't need them anymore.
Your compiler should warn you that you've already got these
functions previously defined..
Okay, add the
following text to the top of your g_weapons.c file.
------------------
START HERE ------------------------
//======================================================
// True if start and end are within radius distance.
//======================================================
qboolean G_Within_Radius(vec3_t start, vec3_t end, float rad) {
vec3_t eorg={0,0,0};
int j;
for (j=0; j<3; j++)>
eorg[j]=abs(start[j]-end[j]);
return (VectorLength(eorg) < rad);
}
//======================================================
// True if Ent is valid, has client, and edict_t inuse.
//======================================================
qboolean G_EntExists(edict_t *ent) {
return ((ent) && (ent->client) && (ent->inuse));
}
//======================================================
// True if ent is not DEAD or DEAD or DEAD (and BURIED!)
//======================================================
qboolean G_ClientNotDead(edict_t *ent) {
qboolean b1=ent->client->ps.pmove.pm_type!=PM_DEAD;
qboolean b2=ent->deadflag != DEAD_DEAD;
qboolean b3=ent->health > 0;
return (b3 || b2 || b1);
}
//======================================================
// True if ent is not DEAD and not just did a Respawn.
//======================================================
qboolean G_ClientInGame(edict_t *ent) {
if (!G_EntExists(ent)) return false;
if (!G_ClientNotDead(ent)) return false;
return (ent->client->respawn_time + 5.0 < level.time);
}
---------------------
END HERE -------------------
===============================================================
Lastly..
Remember to bind a
key in your Autoexec.cfg file as shown
by example below:
bind q
"selfdestruct"
That's it!! If you
are gonna die then
KILL ALL THOSE BASTARDS ON YOUR WAY OUT!
Have Fun!!
philip
|