Forum

Reload code help

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Reload code help

Postby sniperz227 » Tue Apr 12, 2011 2:17 am

Hey i added this reload code in and been trying to make it so when the gun starts reoading the player cannot shoot 3 seconds after the gun is reloaded. It doesn't work could someone help me here's the code

Code: Select all
void() Reload =
{
local float x;//Establishes a float to calculate the shots fired.
local .float ammo_weapon;//Establishes a .float for the clip ammo.
local .float exam_weapon;//Establishes a .float for the inventory ammo.

if(self.weapon == IT_AUG)
{
x = (30 - self.ammo_aug);//Sets the float to the size of the clip, minus whatever is left in the gun.
self.ammo_weapon = self.ammo_aug;//The clip ammo is the clip ammo for the AUG.
self.exam_weapon = self.exam_aug;//The inventory ammo is the inventory ammo for the AUG.
self.attack_finished = time + 3;// 3 seconds till you can shoot again
}
   
else if(self.weapon == IT_M249)
{
x = (100 - self.ammo_m249);   //Sets the float to the size of the clip, minus whatever is left in the gun.
self.ammo_weapon = self.ammo_m249;   //The clip ammo is the clip ammo for the M249.
self.exam_weapon = self.exam_m249;   //The inventory ammo is the inventory ammo for the M249.
}
   
//The part below actually adds the ammo back into the clip.
if(self.exam_weapon >= x)//If the inventory ammo is greater or equal to the shots fired.
{
self.ammo_weapon = (self.ammo_weapon + x);//Refills the weapon's clip.
self.exam_weapon = (self.exam_weapon - x);//Takes the shots fired away from the inventory.
}
else //If the inventory ammo is less than one full clip.
{
self.ammo_weapon = self.exam_weapon;//Sets the clip ammo to whatever the player has left.
self.exam_weapon = 0;//Sets his inventory ammo to zero.
}
W_SetCurrentAmmo();
return;
};
sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Postby Jukki » Tue Apr 12, 2011 8:28 am

Well i am not master of debuging. But all your ammo moving is done by local .floats. Wich means all the fliats are only contained inside the function and not used else were. And NEVER USE .float .vecctor as float. The fuck up your game.
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Postby r00k » Tue Apr 12, 2011 8:49 am

r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby toneddu2000 » Tue Apr 12, 2011 1:50 pm

that code doesn't support reload animations. Does anybody know how to add them?
It would be helpful for me too :)
toneddu2000
 
Posts: 1352
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Postby Ghost_Fang » Tue Apr 12, 2011 7:09 pm

It would have at least stopped him from attacking for 3 seconds with "self.attack_finished = time + 3" I talked to him on xbox live, he wasn't calling "Reload();" anywhere. I simply told him to have an ammo check in W_attack, if there is no ammo in the clip, don't shoot and reload.
Ghost_Fang
 
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Postby behind_you » Tue Apr 19, 2011 8:29 am

toneddu2000 wrote:that code doesn't support reload animations. Does anybody know how to add them?
It would be helpful for me too :)


1. make an impulse do a certain animation
2. in that certain animation, make the last frame call your reload function

ie this is your animation code:

void() army_paind1 =[ $death1, army_paind2 ] {};
void() army_paind2 =[ $death2, army_paind3 ] {};
void() army_paind3 =[ $death3, army_paind4 ] {};
void() army_paind4 =[ $death4, army_paind5 ] {};
void() army_paind5 =[ $death5, army_paind6 ] {};
void() army_paind6 =[ $death6, army_paind7 ] {};
void() army_paind7 =[ $death5, army_paind8 ] {};
void() army_paind8 =[ $death4, army_paind9 ] {};
void() army_paind9 =[ $death3, army_paind10] {};
void() army_paind10=[ $death2, army_paind11] {};
void() army_paind11=[ $death1, army_paind12] {};
void() army_paind12=[ $painc1, army_paind13] {};
void() army_paind13=[ $painc2, army_paind14] {};
void() army_paind14=[ $painc3, army_paind15] {};
void() army_paind15=[ $painc4, army_paind16] {};
void() army_paind16=[ $painc5, army_paind17] {};
void() army_paind17=[ $painc4, army_paind18] {};
void() army_paind18=[ $painc3, army_paind19] {};
void() army_paind19=[ $painc2, army_paind20] {};
void() army_paind20=[ $painc1, army_run1] {PUTNAMEOFRELOADFUNCTIONHERE()};

make sure you define the function if you get an unknown error.

hope that helps
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby toneddu2000 » Tue Apr 19, 2011 11:49 am

1. make an impulse do a certain animation
2. in that certain animation, make the last frame call your reload function

ie this is your animation code:

void() army_paind1 =[ $death1, army_paind2 ] {};
void() army_paind2 =[ $death2, army_paind3 ] {};
void() army_paind3 =[ $death3, army_paind4 ] {};
void() army_paind4 =[ $death4, army_paind5 ] {};
void() army_paind5 =[ $death5, army_paind6 ] {};
void() army_paind6 =[ $death6, army_paind7 ] {};
void() army_paind7 =[ $death5, army_paind8 ] {};
void() army_paind8 =[ $death4, army_paind9 ] {};
void() army_paind9 =[ $death3, army_paind10] {};
void() army_paind10=[ $death2, army_paind11] {};
void() army_paind11=[ $death1, army_paind12] {};
void() army_paind12=[ $painc1, army_paind13] {};
void() army_paind13=[ $painc2, army_paind14] {};
void() army_paind14=[ $painc3, army_paind15] {};
void() army_paind15=[ $painc4, army_paind16] {};
void() army_paind16=[ $painc5, army_paind17] {};
void() army_paind17=[ $painc4, army_paind18] {};
void() army_paind18=[ $painc3, army_paind19] {};
void() army_paind19=[ $painc2, army_paind20] {};
void() army_paind20=[ $painc1, army_run1] {PUTNAMEOFRELOADFUNCTIONHERE()};

make sure you define the function if you get an unknown error.


Thanks, I'll try it!
toneddu2000
 
Posts: 1352
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest