Created By: Brian Meyers
eMail brian419@flash.net
Difficulty Scale Relatively Easy


 Purpose: To create a compass and speedometer that gives you your location and velocity. 

   What to do: Open cmds.c. Scroll down until you find the ClientCommand function and find a long string of  
  else if commands. Somewhere in there, insert these lines: 

   else if (Q_stricmp (cmd, "compass") == 0) 
    Cmd_Compass_f (ent); 
   else if (Q_stricmp (cmd, "speedometer") == 0) 
    Cmd_Speedometer_f (ent); 

   You have just created two new console commands. One is called "compass" and activates the function 
  Cmd_Compass_f. The other is called "speedometer" and activates the function Cmd_Speedometer_f. Of 
  course, neither of these functions exist. Time to rectify that. 
   Scroll up to above ClientCommand and enter this code: 

  void Cmd_Compass_f (edict_t *ent) 
  { 
   gi.cprintf (ent, PRINT_HIGH, "%d %d %d \n",ent->client->ps.pmove.origin[1], ent->client->ps.pmove.origin[2], 
  ent->client->ps.pmove.origin[3]);  //should be one line 
  } 

   What does that rather long command mean? Well, gi.cprintf (ent, PRINT_HIGH, means to put a message 
  at the top of the client (you) who used the command's screen. "%d %d %d \n", means that this message 
  should consist of 3 integers and then go to a new line. (Always put \n at the end of such commands.) Now, 
  what does ent->client->ps.pmove.origin[1] mean? Well, ent is you, which owns a structure called client, 
  which owns a structure called ps, which has a field called pmove. Pmove is a message sent to the quake2 
  engine telling what's been happening to the player. The thing is, you can also read this message. One of 
  pmove's fields is origin, which represents where you are. Origin is a vec3_t, which is a collection of three 
  floating-point numbers, (which our code will round off to integers for the sake of simplicity) [1], [2], and 
  [3]. In the case of origin, they are your x, y, and z coordinates. So, this command will display your current 
  coordinates at the top of the screen. 
   Now, insert this: 

  void Cmd_Speedometer_f (edict_t *ent) 
  { 
   gi.cprintf (ent, PRINT_HIGH, "%d %d %d \n",ent->client->ps.pmove.velocity[1], ent->client->ps.pmove.velocity[2], 
  ent->client->ps.pmove.velocity[3]); 
  } 

   This, you'll notice, is exactly the same as the compass code, except that origin has been changed to 
  velocity. Velocity is another vec3_t, representing (you guessed it) your velocity. Pmove has many other 
  useful vec3_t fields, like weaponangle and viewangle. 

   How to run this mod: First, compile it. Then put the gamex86.dll into a subdirectory of quake2. Then run 
  quake2 with quake2 +set game "subdirectoryname". Then start a new game. Go to the console  (~) and 
  type cmd compass (you have to type cmd before any command. It just doesn't seem like you have to for 
  normal game commands because they are aliased.) and press enter. You will see three coordinates, 
  representing your location in the map. Move around, and these number change accordingly. 
   Now try cmd speedometer. If you are standing still, you should get three 0s, because you have no velocity. 
  Jump and try the command in midair, and you will see that you are moving along the z axis. Run around and 
  you'll find that you are moving along the x and y axes, depending on which way you're moving. 
   



Tutorial html coding modified by legion.


If it is created, then it is copyrighted. Quake 2 Tutorial #8 is (c)1997-98 by Brian Meyers
and the
Inside3D staff. The site is hosted by the one and only TeleFragged. Please direct any
flames, comments, or praises to the author. Any and all information found in this tutorial may
be used in any Quake modification provided that the author and the Inside3D staff are credited.