
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"); } else { 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 toggleint 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 continue; if(ent == blip->owner) continue; tr = gi.trace (ent->s.origin, NULL, NULL, blip->s.origin, ent, MASK_SOLID); if (tr.fraction != 1.0) continue; ent->enemy = blip;//Set the enemy the target } if(ent->enemy) { //checks for ammo if (ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]>0) { ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]--; 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); } ent->enemy=NULL; }}
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, |