|
posted 10-28-98 4:28 PM CT (US)
Title: TELEPORT GRENADE
Difficulty: Easy
By: Philip (aka Maj.Bitch)
Email: peblair@gv.net
Date: 10-28-98
Note: Remember to give credit where credit is due.
======================================================
This is a
modification of one of my earlier tutorials
called INSTA-PORT.
ABOUT:
I was playing around
with the grenade function (as I
just yesterday finished the Zylon Gas grenade tutorial)
and I wanted to make a grenade which blew the players
within a certain radius backward a couple of hundred
yards. Well, I made that work but then was thinking
about making a teleport grenade which insta-ports
any players withing a certain radius of the explosion
to random respawn locations as determined by the system's
respawning function. So.. Here is the Teleport Grenade!
GREAT for clearing the room!! Toss this baby into a
frag-fest of dueling players and BOOM! they all vanish
to distant respawners!
GREAT for getting
rid of a player who is on your ass
with a chaingun. Send'em to a distant respawn location
on the map!!
GREAT if you want to
get yourself out of a sticky situation
also! Jump on the grenade and when it explodes, you get
teleported to a new location!!
=========================================================
The player can toggle an aliased key (as discussed below) to
turn their regular grenades into Teleport Grenades. If any
player (including yourself) is within a radius of 300 units
of the blast then they get instantly teleported to a random
respawn location as determined by the world()'s respawn
function. If the grenade hits a player directly, then
the grenade has its normal killing function. A player
only gets teleported if they are with a radius of 300
units of the grenade's blast.
The standard grenade
function is still fully enabled and
quite functional. All the player has to do is to hit
their aliased 'TP_Grenade' key and all their grenades will
be converted to Teleport Grenades. When you want the
regular exploding grenades back again, just hit your
TP_Grenade key again and the original grenades are
enabled again..
Okay, let's get
started..
=====================================================
Open you g_local.h file and let's put a single variable
in place.
At the bottom of
your struct gclient_s record add:
int
Teleport_grenade; // Teleport Grenade 1=ON, 0=OFF
=====================================================
=====================================================
Okay. open up your
g_cmds.c file and at the bottom
of ClientCommand() add the following lines as shown.
else if
(Q_stricmp(cmd, "TP_Grenade") == 0 ) {
ent->client->Teleport_grenade=abs(ent->client->Teleport_grenade-1);
gi.centerprintf(ent,"TELEPORT GRENADE %s!\n",ent->client->Teleport_grenade<1?"DISABLED":_x0022_ENABLED_x0022__x0029__x003b_>
} // end else if
This will toggle the teleport grenades on/off with
a single hit of your aliased 'TP_Grenade' key.
Remember: if you are
also using the zylon gas grenades
you'll have to turn that variable off when this variable
gets turned on!
=====================================================
Okay, now find your InitClientPersistant() function
and at the bottom of this fucntion add this variable
initialization:
client->Teleport_grenade
= 0; // init as OFF
This will set the
teleport grenade to OFF by default.
=====================================================
=====================================================
Open up your
g_weapons.c file and paste in the following
at the top of the file..
Add this little
helper function at the top of g_weapons.c
//======================================================
// True if Ent is valid, has client, and edict_t inuse.
//======================================================
qboolean G_EntExists(edict_t *ent) {
return ((ent) && (ent->client) && (ent->inuse));
}
Also, add this new
function to your g_weapons.c file
just after the G_EntExists() function above..
//======================================================
void Teleport_Grenade(edict_t *grenade){
edict_t *ent = NULL;
vec3_t spawn_origin={0,0,0},
spawn_angles={0,0,0};
// NOTE: if you want
to clear a really large area around the
// blast then change the 300 to 1200 units!! That'll clear
// the bastards out!!
while ((ent = findradius(ent, grenade->s.origin, 300)) != NULL){
if (!G_EntExists(ent)) continue;
// Have System
select a random spawning location
SelectSpawnPoint(ent, spawn_origin, spawn_angles);
// Copy over
player's last movement info.
ent->client->ps.pmove.origin[0] = spawn_origin[0]*8;
ent->client->ps.pmove.origin[1] = spawn_origin[1]*8;
ent->client->ps.pmove.origin[2] = spawn_origin[2]*8;
// Actually Relocate
player to the new spot
VectorCopy(spawn_origin, ent->s.origin);
// Must set Ents
Respawn Time!
ent->client->respawn_time=level.time;
// So Particle
effect at new spot
ent->s.event = EV_PLAYER_TELEPORT;
// play teleport
sound effects.
gi.sound(ent, CHAN_VOICE, gi.soundindex("misc/tele1.wav"), 1,
ATTN_NORM, 0);
} // while
}
=========================================================
Okay, now find your
grenade_explode() function in this
same file and add this code where your T_RadiusDamage()
function is:
-----------------------------------------------
void Grenade_Explode(edict_t *ent) {
.
.
.
if (G_EntExists(ent->owner) // <= NEW LINE HERE
&& ent->owner->client->Teleport_grenade) // <= NEW LINE
HERE
Teleport_Grenade(ent); // <= NEW LINE HERE
else // <= NEW LINE HERE
T_RadiusDamage(ent, ent->owner, ent->dmg, ent->enemy,
ent->dmg_radius, mod);
This will cause the
grenade to activate it's teleport
effect only if the grenade belonged to a real player
entity..
=====================================================
Lastly, be sure to
include the following in your
autoexec.cfg file as shown by example...
bind t
"TP_Grenade"
This will turn the
teleport grenades ON/OFF with a
single keystroke!
=====================================================
That's it!! Now, GO
KILL ALL THOSE BASTARDS!!
regards,
philip
aka Maj.Bitch
|