• SWEP Ammo regen HELP!
    0 replies, posted
Hi guys I have been having a little bit of trouble with a small project I have been working on. I want to have a gun which has a clip of 30 bullets, when the clip is empty the ammo starts to regenerate. So far I have been able to get it to regenerate but it seems that the clip keeps going on. Even though I specified the clip size. Here is my code. [code] SWEP.ViewModelFOV = 65 SWEP.ViewModel = Model ( "models/weapons/v_IRifle.mdl" ) SWEP.WorldModel = Model ( "models/weapons/w_IRifle.mdl" ) SWEP.WalkSpeed = 150 SWEP.HoldType = "ar2" SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.DrawAmmo = true SWEP.Primary.Ammo = "ar2" SWEP.Primary.Automatic = true SWEP.Primary.Delay = 0.13 SWEP.Primary.Recoil = 6 SWEP.Primary.ClipSize = 28 SWEP.Primary.DefaultClip = 28 function SWEP:Initialize() self:SetWeaponHoldType(self.HoldType) if ( SERVER ) then self:SetWeaponHoldType(self.HoldType) end timer.Create("regen_ammo"..self:EntIndex(),1,4,function() if self:IsValid() then if self:Clip1() < 30 then self:SetClip1(self:Clip1() + 1) end end end) end function SWEP:OnRemove() timer.Destroy("regen_ammo"..self:EntIndex()) end function SWEP:PrimaryAttack() local bullet = {} bullet.Num = 1 bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() bullet.Spread = Vector(0.02,0.02,0.02) bullet.Tracer = 1 bullet.Force = 30 bullet.Damage = 10 self:ShootEffects() self.Owner:FireBullets( bullet ) self.Weapon:EmitSound(Sound("Airboat.FireGunHeavy")) self:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self:SetNextSecondaryFire( CurTime() + self.Primary.Delay ) self:TakePrimaryAmmo(1) end function SWEP:SecondaryAttack() --Nothing end function SWEP:CustomAmmoDisplay() self.AmmoDisplay = self.AmmoDisplay or {} self.AmmoDisplay.Draw = true self.AmmoDisplay.PrimaryClip = self:Clip1() return self.AmmoDisplay end [/code] Any help is greatly appreciated. Thanks -Duby
Sorry, you need to Log In to post a reply to this thread.