Forum

Impulse trouble

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Impulse trouble

Postby sniperz227 » Fri Apr 06, 2012 5:50 pm

hey sniperz227 here, i was working on my mod for psp and i was having trouble with some stuff. First i made reload code and it executes perfectly fine but when i tie it to an impulse and set a key for it on the psp and hit that key it reloads but doesn't play the animation where as when i run out of bullets in my clip by shooting and it reloads it does. It's also been doing the same for most my impulse like ironsights. Another thing i would like to ask is im not very good with while loops in qc so i cant do this but what i want is while the player is holding the ltrigger down to call iron sight animation and keep it on the 33 frame so that it stays zoomed in cause right now it just plays the frames and goes back to the original frame after it doesnt stay. i'd also like to note if you look at the iron sight code it doesn't change the FOV for some reason. Thanks

here's my code i have:

reload
Code: Select all
/*
=============================
== Reload Code For Weapons ==
=============================
*/

void () reload =
{
local .float shots_fired;

if (self.weapon == IT_M1911)
{
self.shots_fired = 7 - self.clip_m1911;
if (self.clip_m1911 < 7 && self.ammo_m1911 > 0)
{
self.ammo_m1911 = self.ammo_m1911 - self.shots_fired;
self.clip_m1911 = 7;
}
else
{
self.clip_m1911 = self.clip_m1911 + self.ammo_m1911;
self.ammo_m1911 = 0;
}
}
self.currentammo = self.clip_m1911 && self.ammo_m1911;
self.attack_finished = time + 1.5;
if(self.weaponframe == 1)
{
self.weaponframe = 8;
self.think = M1911Reload;
self.nextthink = time+ 0.06;
}
}


iron sight:
Code: Select all
void() IronSights =
{
   if (self.weapon == IT_M1911)
   {   
      if (self.weaponframe == 1)
      {
         M1911IronIn();
         stuffcmd(self,"fov 55");
      }
   }
}


iron sight animation:

Code: Select all
void () M1911IronIn =
{
   if(self.weapon == IT_M1911)
   {
      self.weaponframe = 26;
      self.weaponframe = self.weaponframe +1; // increase by 1 frame
      if (self.weaponframe >= 33)   
         return;
      self.nextthink = time + 0.2;   
   }

}


impulses:

Code: Select all
void() ImpulseCommands =
{
   if (self.impulse >= 1 && self.impulse <= 8)
      W_ChangeWeapon ();

   if (self.impulse == 9)
      CheatCommand ();
   if (self.impulse == 14)
      M1911IronSights();
   if (self.impulse == 17)
      reload();   
   if (self.impulse == 10)
      CycleWeaponCommand ();
   if (self.impulse == 11)
      ServerflagsCommand ();
   if (self.impulse == 12)
      CycleWeaponReverseCommand ();

   if (self.impulse == 255)
      QuadCheat ();
      
   self.impulse = 0;
};
sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: Impulse trouble

Postby Ghost_Fang » Fri Apr 06, 2012 10:51 pm

For your Iron Sights you're going to want to make 2 aliases in autoexec.cfg:
alias +irondown "impulse 14" //You don't need a specific impulse for each gun, you can sort these with a new function
alias -ironup "impulse 15" //You'll see why this one in a sec
bind <MYIRONSIGHTBUTTON> +irondown

what we did here is bound whatever button you're going to use for Ironsights, pressing down will do impulse 14, releasing will do impulse 15.
somewhere before all your iron sight stuff make a new protoype:

.float ironsighting

so now change your self.impulse == 14 and impulse == 15 to

Code: Select all
if(self.impulse == 14)
    self.ironsighting = TRUE;
if(self.impulse == 15)
    self.ironsighting = FALSE;


now in playerprethink add all the arguments for all the different weapons' ironsights

Code: Select all
if(self.ironsighting == TRUE && self.attack_finished < time) //I think that would negate any conflicts with firing animations...
   {
   if(self.weapon == IT_M1911)
      self.weaponframe == XX;
   if(self.weapon == IT_MP%)
      self.weaponframe == XX;
 
  //etc etc etc
  stuffcmd(self, "fov 55"); //we'll go ahead and put this in here
  }
else if (self.ironsighting == FALSE && self.attack_finished < time)  //We aren't looking down the sights so default back to your idle frame
 {
   if(self.weapon == IT_M1911)
      self.weaponframe == XX;
   if(self.weapon == IT_MP%)
      self.weaponframe == XX;
   stuffcmd(self, "fov 90");
}
/* Or if they are all frame 1 just put

else if (self.ironsighting == FALSE && self.attack_finished < time)
   self.weaponframe == 1; */


I'm a bit rusty and have never personally did ironsights, but i think that should help or at least get you started. Be sure to add arguments for you're firing animations to account for the iron sight ones using the ironsighting float we made. As well as making sure you make ironsighting false upon weapon switching and reloads.
Ghost_Fang
 
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest