Quake DeveLS - An antimissile system

Author: Cryect
Difficulty: Medium

Here is a tutorial that protects you against missile. You need to do Chris Hilton's tutorial on Vulnerable Rockets. Without it this tutorial won't work.

Create a new file called "antimissile.c". Put into it this code.

#include "g_local.h"
The antimissile device
void toggle_antimissile(edict_t *ent)//This toggles it on and off
	if (ent->anti)
		ent->anti = 0;
		gi.cprintf (ent, PRINT_HIGH, "Anti-Missile Device deactivated!\n");
		ent->anti = 1;
		gi.cprintf (ent, PRINT_HIGH, "Anti-Missile Device activated!\n");

Put this into the edict_t structure. This is the variable for toggling

	//antimissile toggle
	int anti;	

Now we are going to insert this code below into "p_client.c". THis will go into ClientBeginServerFrame right after the declarations.

vec3_t start, target, dir;
edict_t *blip;
trace_t tr;
if (ent->anti)
	blip = NULL;
	//scans for a target
	while ((blip = findradius(blip, ent->s.origin, 500)) != NULL)

		//This checks for rockets
		if ((strcmp(blip->classname, "rocket") != 0)/*&&(strcmp(blip->classname, "grenade") != 0)*/) //Uncomment the part I commented out if you wish it to work with grenades
		if(ent == blip->owner)
		tr = gi.trace (ent->s.origin, NULL, NULL, blip->s.origin, ent, MASK_SOLID);
		if (tr.fraction != 1.0)
		ent->enemy = blip;//Set the enemy the target
		//checks for ammo
		if (ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]>0)
			start[0] = ent->s.origin[0];
			start[1] = ent->s.origin[1];
			start[2] = ent->s.origin[2];

			// calc direction to where we targetd
			VectorMA (ent->enemy->s.origin, -0.05, ent->enemy->velocity, target);
			VectorSubtract (target, start, dir);
			VectorNormalize (dir);
			//fire bullet
			fire_bullet (ent, start, dir, 8, 0, 425, 425, MOD_SENTRY);

			// send muzzle flash
			gi.WriteByte (svc_muzzleflash);
			gi.WriteShort (ent - g_edicts);
			gi.WriteByte (MZ_SHOTGUN );
			gi.multicast (start, MULTICAST_PVS);
			//Play over the shotgun sound
			gi.sound(ent, CHAN_VOICE, gi.soundindex("boss3\xfire.wav"), 1, ATTN_NORM, 0);

This should interesting code for you to experiment with. I hope you enjoy this!

Tutorial by Cryect

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 there great help and support with hosting.
Best viewed with Netscape 4 or IE 3