Using ammo in stock instead of clip

Topic created ยท 3 Posts ยท 77 Views
  • Hi I'm relatively new to modding but I know my way around. I can read an understand what the code is doing.

    I'm trying to recreate the Ring of Fire specifically its tier 3 effect, where the player uses its ammo in stock instead of the clip.

    The basic concept is to put the following code into a loop (hopefully it's properly formatted)

    if(self isFiring() && self attackButtonPressed())
    	if( self GetWeaponAmmoStock( self getCurrentWeapon() ) > 0 )
    		self setWeaponAmmoClip(self getCurrentWeapon(), self GetWeaponAmmoClip( self getCurrentWeapon() )+1);
    		self setWeaponAmmoStock(self getCurrentWeapon(), self GetWeaponAmmoStock( self getCurrentWeapon() )-1);

    The problem it's not smooth and the bullets in the clip can still decrease. I thought about using this, but it doesn't help.

    // Use ammo from stock
    if( self GetWeaponAmmoStock( self getCurrentWeapon() ) != 0 )
       self setClientDvar("sf_use_ignoreammo", "1");
    } else {
       self setClientDvar("sf_use_ignoreammo", "0");

    I also can't use dvars such as player_sustainAmmo 1 because it's globally applied.

    Here's a function that calculates the time between shots:
    ( I thought about using it as a delay, but it came out it's a bad idea )

    self.timeBetweenShots = gettime() - self.lastShotTime;
    self iprintln(self.timeBetweenShots / 1000);
    if(self isFiring() && self attackButtonPressed())
       self.lastShotTime = gettime();

    I couldn't find any function related to when a player is shooting or more specifically a function that detects change in ammunition.

    So right now I'm kinda lost, as I really want to make it smooth (aka the ammo in the clip has to stay still) but I also want a code that works for every weapon (considering their rate of fire).

    Also, this one is too slow ๐Ÿ˜ž
    self waittill("weapon_fired");

    Any tips?

  • I wanted to add that the first part of the code, works if your weapon is automatic.

    Otherwise there's a delay that must be calculated.

  • Solved, here's the code! Remember to run this in a loop ๐Ÿ™‚

    // We need to make sure the player shot and is holding the shooting button
    if(self isFiring() && self attackButtonPressed()){
    	// Use stock instead of clip
    	if( self GetWeaponAmmoStock( self getCurrentWeapon() ) > 0)
    		ClipSize = WeaponClipSize( self getCurrentWeapon() );
    		CurrentClip = self GetWeaponAmmoClip( self getCurrentWeapon() );
    		CurrentClipDiff = ClipSize - CurrentClip;
    		CurrentStock = self GetWeaponAmmoStock( self getCurrentWeapon() );
    		self setWeaponAmmoClip(self getCurrentWeapon(), ClipSize);
    		self setWeaponAmmoStock(self getCurrentWeapon(), CurrentStock - CurrentClipDiff);

    I'm unsure how this would work for dual wield weapons, the following might work for World at War but unsure about other games

    Add this to any if statement:

    && !maps\_zombiemode_weapons::weapon_is_dual_wield( CurrentWeapon ) 
Log in to reply