Anyone knows what the problem is? When my ammo count hits 0, I am still able to fire.
Post your SWEP:PrimaryFire code.
[QUOTE=Robotboy655;42498543]Post your SWEP:PrimaryFire code.[/QUOTE]
[CODE]
function SWEP:PrimaryAttack()
if SERVER then
local maxammo = 10
if self.Owner:GetAmmoCount("AR2") == 0 then return end
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK );
self:TakePrimaryAmmo( 1 )
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Owner:SetVelocity(self.Owner:GetForward() * -200 )
self.Owner:ViewPunch(Angle( -5, -5, -5 ))
umsg.Start("SetNextPrimaryFire", self.Owner)
umsg.Float(CurTime() + self.Primary.Delay)
umsg.End()
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 20^14
trace.filter = self.Owner
local tr = util.TraceLine(trace)
local vAng = (tr.HitPos-self.Owner:GetShootPos()):GetNormal():Angle()
local dmginfo = DamageInfo();
dmginfo:SetDamage( self.Primary.Damage );
dmginfo:SetAttacker( self:GetOwner() );
dmginfo:SetInflictor( self );
if( dmginfo.SetDamageType ) then
dmginfo:SetDamagePosition( tr.HitPos );
dmginfo:SetDamageType( DMG_BURN );
end
tr.Entity:DispatchTraceAttack( dmginfo, tr.HitPos, tr.HitPos - vAng:Forward() * 20 );
tr.Entity:SetKeyValue("targetname", "disTarg")
local dis = ents.Create("env_entity_igniter")
dis:SetKeyValue("magnitude", "5")
dis:SetKeyValue("dissolvetype", "")
dis:SetKeyValue("target", "disTarg")
dis:Spawn()
dis:Fire("Dissolve", "disTarg", 0)
dis:Fire("kill", "", 0)
self:ShootEffect(effect or "Weapon_Gunship_Ultras_Rail",self.Owner:EyeAngles(),tr.HitPos) //shoop da whoop
local bullet = {}
bullet.Num = self.Primary.NumShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( self.Primary.Cone , self.Primary.Cone, 0)
bullet.Tracer = 1
bullet.TracerName = "Tracer"
bullet.Force = self.Primary.Force
bullet.Damage = 0
bullet.AmmoType = (self.Primary.Ammo)
self:ShootEffects()
self.Owner:FireBullets( bullet )
local randomsounds = {
"weapons/ioncannon/ioncannon_1.wav",
"weapons/ioncannon/ioncannon_2.wav",
"weapons/ioncannon/ioncannon_3.wav",
}
local random = math.random(1, #randomsounds)
self.Owner:EmitSound(randomsounds[random])
local effect = EffectData()
effect:SetStart(self.Owner:GetShootPos()+self.Owner:EyeAngles():Forward()*22+self.Owner:EyeAngles():Up()*-6+self.Owner:EyeAngles():Right()*5)
effect:SetOrigin(tr.HitPos)
--util.Effect("Rail_Spiral", effect)
util.Effect("HelicopterImpact", effect)
util.Effect("ManhackSparks", effect)
local effect2 = EffectData()
effect2:SetStart(tr.HitPos)
effect2:SetNormal(tr.HitNormal)
util.Effect("Rail_Puff", effect2)
local hit1, hit2 = tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal
util.Decal("FadingScorch", hit1, hit2)
end
end
[/CODE]
if self.Owner:GetAmmoCount("AR2") == 0 then return end
replace that with
if self:Clip1() == 0 then return end
Before it checked how much ammo the guy has in his pocket, now it checks how much ammo the gun has in its clip. That's what reloading does, it moves ammo from pocket to clip.
Really I'd go with if self.Weapon:Clip1() < 1 then return end.
[QUOTE=Donkie;42498941]if self.Owner:GetAmmoCount("AR2") == 0 then return end
replace that with
if self:Clip1() == 0 then return end
Before it checked how much ammo the guy has in his pocket, now it checks how much ammo the gun has in its clip. That's what reloading does, it moves ammo from pocket to clip.[/QUOTE]
Still shoots under 0 :/
Boy that code looks unnecessarily complex. Maybe it's because I'm on my phone
Do what Internet said, but use self not self.weapon
[QUOTE=Noah;42499161]Still shoots under 0 :/[/QUOTE]
Then fuck with it until it doesn't anymore.
Look at Garry's base SWEP and how it handles ammunition.
Sorry, you need to Log In to post a reply to this thread.