I am asking the community for some help if possible.
I am working on a script which counts the number of fires that you shoot and stores into a variable.
The problem is that when I press the attack button and shoot a few times, it counts a tons of shots, for exmaple if I shoot 3 times it counts 18260520 etc... so I guess the script is running without pauses?
The code i am using:
Code: Select all
init() {
   
    level waittill("connected", player);
    player waittill("spawned");
    player thread monitorWeaponUsage();
}
monitorWeaponUsage() {
    ammo_before_wait = 0;
    ammo_after_wait = 0;
    
    while(isAlive(self)) {
        if(self attackButtonPressed()) {
            fired = true;
			ammo_after_wait = getCurrentWeaponClipAmmo(self);
        } else {
            fired = false;
			ammo_before_wait = getCurrentWeaponClipAmmo(self);
        }
        
        if(fired) {
			difference = ammo_before_wait - ammo_after_wait; 
					self.firecount += difference;
                  //  self iPrintLnBold("You Fired.");
        } else {
            //Avoid infinite loop
            wait 0.05;
        }
    }
}
getCurrentWeaponClipAmmo(currPlayer) {
   
    if(currPlayer getWeaponSlotWeapon("primary") == currPlayer getCurrentWeapon()) {
        weapon = "primary";
    } else {
        weapon = "primaryb";
    }
   ammo = currPlayer getWeaponSlotClipAmmo(weapon);
    //Returns with the current value in the clip.
    return ammo;
}Regards,
Unrealxqt



