Checking if an event happens within a certain amount of time

Discuss programming in the QuakeC language.
Post Reply
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Checking if an event happens within a certain amount of time

Post by DusterdooSmock »

Hey guys, it's been a while since I've programmed anything for Quake, and I've decided to implement a new firing mode for semi-automatic weapons.
For those of you who play paintball, you should be familiar with the Ramp PSP firing mode, and for those of you who aren't, I'll explain it.
Basically, your weapon is semi-automatic, that is, until you pull the trigger three or more times in one second. Once three shots have been fired in under a second, the fourth shot and all others after it will be "ramped". From that point on, as long as you continue to pull the trigger, the gun will fire at fifteen rounds per second. But, if you let off the trigger for one second the gun will reset, and you will have to fire three shots in under a second in order for the gun to begin ramping again.

I've already implemented semi-automatic firing thanks to the tutorial posted here by CheapAlert, but I've run into a bit of a roadblock when it comes to detecting if three shots have been fired in a period of time less than or equal to one second. It seems like it should be relatively easy, but I haven't programmed anything in quite a while, and I would appreciate it if someone could help me out with this.
gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

Re: Checking if an event happens within a certain amount of

Post by gnounc »

Code: Select all


void holdFire() = 
{

     if(fireButtonDown)
     {
          if(numFires > 1)//doublecliick, double fire rate
          {
               doubleFIre();
               fireButtonDown = 1;
               return;
          }

          if(numFires > 2)//triple cliick, triple fire rate
          {
               tripleFIre();
               fireButtonDown = 1;
               return; 
         }
     }

}
void releaseFire() = 
{
     fireButtonDown = 0;
     numFIres = numFires + 1;
     releaseTime = time;
}


///playerPreThink

if(time > releaseTime + 0.3)
{
    numFires = 0;//if too much time has passed between clicks its not a double click, reset click count 
}



feel free to use .button0 of course.

gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

Re: Checking if an event happens within a certain amount of

Post by gnounc »

Short answer

time is the variable name that holds game time.

set a new variable to record the marker for your first time, let time be the end time
and check for a duration by adding it to the variable you created and checking against time,
this is how attack_Finished works in weapons.qc

if (ourTime + 7seconds > time)
{
window of opportunity has closed() = 1;
}
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Re: Checking if an event happens within a certain amount of

Post by DusterdooSmock »

Actually, I'm gonna change some numbers and a couple small things around a bit.. This is going to be a secondary fire mode on a pistol, and the pistol will have a slightly extended 18 round magazine. I think I'm going to make it so that if you fire 6 shots in 2 seconds or less, then it begins to ramp up the rate of fire. I'm not sure what I want the ramped-up rate of fire to be yet, but once I get this working I'll figure that out.

Thanks for the reply Gnounc, but I'm still pretty lost here. It really has been a while since I've programmed anything. The firing code is pretty much the same as it is in vanilla Quake, plus the addition of CheapAlert's semi-automatic weapons tutorial.
Seven
Posts: 301
Joined: Sat Oct 06, 2007 8:49 pm
Location: Germany

Re: Checking if an event happens within a certain amount of

Post by Seven »

Hello DusterdooSmock,

I think you will find what you need in the source of moatdd´s mod.
He also uses ramp up fire, just like you described it (as far as my poor english dont fool me).

Please find it in this thread (last post on page 1):
http://forums.inside3d.com/viewtopic.php?f=2&t=4830

You will find many many additional custom weapon ideas in it.
He also has a youtube clip that shows them.

Good luck,
Seven
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Re: Checking if an event happens within a certain amount of

Post by DusterdooSmock »

His mod is similar to what I'm looking to achieve, but not exactly. Basically, I'm trying to check if the weapon is fired 6 or more times in a period of 2 seconds or less. Then, if the gun has been fired 6 or more times, the 7th shot and all others will be "ramped", basically meaning, the gun kinda burst fires for each shot, to give the effect of having a super fast rate of fire.

I'm know I'm going to need a .float to store the amount of shots fired, and another .float to check the 2 second time limit after the first shot in a sequence has been fired. If the 6 shots were not fired in that time, then it will need to be reset, and so will the shot count. And then another .float to reset the shot count if the trigger is let off for more than one second. It might need more, but that's about all I've got figured out so far...
Post Reply