Periscope Add-On


 

Posted by Maj.Bitch (208.140.33.*) on May 12, 1999 at 12:27:14:

Title: Periscope Add-On
By: Maj.Bitch
Difficulty: Easy
Email: peblair@frontiernet.com
Date: 05-12-99
Note: Please give credit where credit is due.
============================================================

Have you ever wanted to look into a window which was out of
your reach and one that you couldn't rocketjump to so that you
could see if there were badguys in there waiting for you? Wish
you could pull out of your backpack your Q3Pscope (which will
raise to just about any height so you could check something out
before you ventured into there and got wasted? Well... Now
you can!

How it works..

Simple.. You hit your aliased periscope key and your periscope
is enabled with your view increasing by 10 units (adjustable)
automatically, and then using your "RAISE" or "LOWER" aliased keys,
you crank up the scope to get just the perfect view! But watch out,
while your doing this scoping out of the badguys, you may be wasted!

Cool new feature, especially for SinglePlayer!!!

Okay! Let's get started!

============================================================
We need to add a new variable to your gclient_s structure..


  int      periscope;       // Periscope 1=ON, 0=OFF


And add this to the bottom of your InitClientPersistent() routine..


  client->periscope=0;      // default to OFF


This will set the default state to OFF.

Also, in find your player_die() function and add this new line
to the bottom of this function so that the periscope gets reset
when you die..


  self->client->periscope=0;


============================================================
Okay, now open your g_cmds.c file and add this new command
into the nested-if statements of the ClientCommand() function:


  else if (!Q_stricmp(cmd, "periscope"))
    Cmd_Periscope_f(ent,cmd);


============================================================
Lastly, add this new function into your g_cmds.c file at a point
above your ClientCommand() function:


//==========================================
//========== Periscope States ==============
//==========================================

#define PERISCOPE_OFF   0  // set if periscope is not active
#define PERISCOPE_ON    1  // set if periscope is active
#define PERISCOPE_LOWER 2  // set if lower the periscope
#define PERISCOPE_RAISE 4  // set if raise the periscope

//==========================================================
/*
To enable, in your autoexec.cfg file put:

// Aliases for Periscope
alias +lower "periscope lower"
alias -lower "periscope stop"
alias +raise "periscope raise"
alias -raise "periscope stop"
alias +periscope "periscope action"
alias -periscope "periscope stop"

// Key Bindings for Periscope.
bind F2 +periscope
bind F3 +raise
bind F4 +lower
*/
//==========================================================
void Cmd_Periscope_f(edict_t *ent, char *cmd) {
char *s=gi.argv(1);
int *periscope=NULL;

  // Not available to dead or respawning players!
  if (!G_ClientInGame(ent)) return;

  // create intermediate state value
  periscope = &ent->client->periscope;

  if (!BitCmp(*periscope,PERISCOPE_ON) && (!Q_stricmp(s, "action"))) {
    ent->viewheight += 10; // Start by Raising by 10 units
    return; }

  //---------------------------
  // Process command request..
  //---------------------------

  if (BitCmp(*periscope,PERISCOPE_ON)) {

    // raise periscope
    if (!Q_stricmp(s, "raise")) {
      BitOR(*periscope,PERISCOPE_RAISE);
      *periscope -= BitCmp(*periscope,PERISCOPE_LOWER);
      ent->viewheight += 10; // Raise by 10 units
      return; }

    // lower periscope
    if (!Q_stricmp(s, "lower")) {
     BitOR(*periscope,PERISCOPE_LOWER);
     *periscope -= BitCmp(*periscope,PERISCOPE_RAISE);
     ent->viewheight = MinOf(22, ent->viewheight-10); // Lower by 10 units
     return; }

    // return to normal viewheight
    if (!Q_stricmp(s, "action")) {
      *periscope = PERISCOPE_OFF;
      ent->viewheight = 22; // Reset to normal viewheight
      return; } }
}


NOTE: You can easily change the amount that the periscope view
gets raised up (and lowered) to whatever amount you are comfortable
with..

============================================================
You may also need these macros if you don't have it already..


#define MinOf(x,y) ((x)<(y)?(x):(y)) 
#define BitCmp(x,bit) ((int)(x)&(bit)) 
#define BitOR(x,bit)  ((x)|=(bit))


============================================================

That's it! You're done!

Now, get out there and SCOPE OUT THE BASTARDS THEN KILL'EM!!

Have Fun!!

Maj.Bitch