Extending grenade lifespan while in motion


 

Posted by Maj.Bitch (24.95.222.*) at 1:45 PM, 5/2/2001:


While standing on some really high-up spot in city64.bsp (I like that map!) and firing my grenadelauncher, I noticed that the grenade exploded while it was in mid-air and still in motion. For example, if it took a really high bounce and it's timer ran out, then kaboom!

So I was thinking about seeing what it would take to make the grenade still have all its normal characteristics (like exploding on contact with players AND when its timer ran out naturally), but with the added feature of extending its timer by 2 frames if the grenade was still in motion. Now, when I launch a grenade off some high ledge, it bounces and bounces and then explodes when it finally comes to a complete stop. This way, you can toss a grenade down a long and twisted stairway, for example, and it won't explode unless it bounces into somebody along the way OR until it finally comes to rest at the bottom!

Do this:

Find your grenade_explode() function in p_weapon.c and at the very top, put this:

  if (!grenade->enemy)
    if (VectorLengthSqr(grenade->velocity)>0) { // grenade still moving?
      grenade->nextthink=level.time + 0.2; // extend timer if still in motion
      return; }
 

So, if the timer has expired and the grenade's think function wants to do a grenade_explode, what we do is to keep extending the timer by 2 frames.. Eventually, the grenade will ultimately come to a complete stop somewhere and then it'll blow! heheh

Have fun!

Maj.Bitch