Adding Double-Jumping to your mod


 

Posted by Solarbeam (pool0123.cvx8-bradley.dialup.earthlink.net) on January 25, 2000 at 17:58:43:

Author: Solarbeam (or Lunarbeam)
Difficulty: Fairly Easy (Cut and paste)

Intended for the v3.20 src, but it probably doesn't matter.

Note: If you use this small mod in your mod, please mention me and my email address (solarbeam2@yahoo.com).

Ok, all. After a couple posts on Qdevels and a little thought, I built Double-Jumping. Dbl-jumping works like this: when the player jumps once, he does a normal jump, BUT, if the player presses his jump button in midair, his screen flashes and he is given an extra thrust. It also plays a sound upon completion. This can only be done once each jump.

First of all, add this to your "g_local.h" file at the bottom before the last bracket.


qboolean   dbljumped;   // SB: Is true if the player has jumped already
 

That was painless; now for the meat of the tutorial. Pop open your "p_client.c" and add this right after the line that reads: "pm_passent = ent;"

// All this below deals with Dbl-Jumping
if (ent->groundentity)
  ent->timestamp = level.time;

if (!ent->groundentity && !ent->dbljumped && ucmd->upmove > 10)
{
  if (level.time - ent->timestamp >= 0.35) // Time after jump to dbl-jump
  {
    // Play sound
    gi.sound(ent, CHAN_VOICE, gi.soundindex("world/x_light.wav"), 1, ATTN_NORM, 0);

    ent->client->blue_alpha = 0.5;
    Float_ModVelocity(ent, 0, 0, DBLJUMP_HEIGHT);

    // Init the vars
    ent->dbljumped = true;
    ent->timestamp = 0;
  }
}

if (ent->groundentity && ent->dbljumped == true)
  ent->dbljumped = false;

// END ALL DBL-JUMPING CODE

Finally you need to have this function included (I like it in a separate file):

void Float_ModVelocity (edict_t *ent, float x, float y, float z)
{
  vec3_t tempvec;
  
  VectorSet(tempvec, x, y, z);
  VectorAdd(ent->velocity, tempvec, ent->velocity);
}

That's it! If you have any problems or questions, just post 'em and I'll answer.

Next Tutorial: "Extension to Dbl-Jumping: Burst Jumping"