Gun doesn't reload automatically/negative clip

In trying to recreate the C3000-B1ATCH35 from call of duty zombies, I encountered a glitch that causes the gun to continue firing even though there is no ammo in the clip. The part I found especially odd is that when it fires it deducts from reserve ammo once the clip runs out (and will continue to fire after reserve ammo is gone) How do I stop the gun from firing once the clip is empty? Here’s what I’ve got.


SWEP.Author = “McManager”
SWEP.Purpose = “Pew pew, kaboom.”
SWEP.Category = “Nazi Zombies”

SWEP.Spawnable = true
SWEP.UseHands = true

SWEP.ViewModel = “models/weapons/v_pist_usp.mdl”
SWEP.WorldModel = “models/weapons/w_pistol.mdl”

SWEP.ViewModelFOV = 75

SWEP.ViewModelFlip = true
SWEP.Primary.ClipSize = 6
SWEP.Primary.DefaultClip = 54
SWEP.Primary.Automatic = true
SWEP.Primary.Recoil = 3
SWEP.Primary.Ammo = “RPG_Round”
SWEP.CSMuzzleFlashes = true

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “none”

SWEP.PrintName = “C-3000 B1AT-CH35”
SWEP.Slot = 2
SWEP.SlotPos = 3

local ShootSound = Sound( “NPC_Hunter.FlechetteShoot” )

function SWEP:PrimaryAttack()

self:SetNextPrimaryFire( CurTime() + 1 )
self:TakePrimaryAmmo( 1 )
self:EmitSound( ShootSound )
self:ShootEffects( self )

if (!SERVER) then return end

local Forward = self.Owner:EyeAngles():Forward()

local ent = ents.Create( "grenade_ar2" )
if ( IsValid( ent ) ) then

		ent:SetPos( self.Owner:GetShootPos() + Forward * 25 )
		ent:SetAngles( self.Owner:EyeAngles() )
	ent:SetVelocity( Forward * 3000 )
	ent:SetOwner( self.Owner )



I’d recommend using [lua] tags around code. To prevent a weapon from firing when the magazine is empty, do a check for ammo left in the magazine in PrimaryAttack( )

Something like this:
[lua] if ( self:Clip1( ) <= 0 ) then
self.Weapon:EmitSound( “Weapon_Pistol.Empty” )

The reason it continues firing is because there is no return; statement telling it not to. The reason it keeps deducting is because the algorithm ( The sequence of instructions to solve a problem ) is telling it to: self:TakePrimaryAmmo( 1 );

Sorry about that, :stuck_out_tongue: and that worked, thanks!

Excellent, feel free to mark this thread solved up near the top-left reply button to avoid confusion for others! :slight_smile: