Attempt to call method 'TakePrimaryAmmo' (a nil value)


function SWEP:PrimaryAttack()
	if not self.Power then self.Power = 0 end
	if SERVER and self.LastUpdated + 0.2 < CurTime() then
		self.LastUpdated = CurTime()
		self:SetNWInt('power',self.Power)
	end
	if self.Power <= 0 then  if not self.OverPower then 
		if SERVER then
			self.Laser = false
			net.Start('omglaser') net.WriteEntity(self) net.WriteBit(self.Laser) net.Broadcast() 
			self:FuckingOverStun(self.Target)end  self.OverPower = true
		end 
		return 
	end
	self.Power = self.Power -1

		
	if self:Clip1() <= 0 then
		if self.Target then
			
			self.Owner:EmitSound( "Weapon_Pistol.Empty")
			self.Owner:EmitSound( "Weapon_SMG1.Empty")

			self.LastPrimaryAttack = CurTime()
			if not self.Taser then
				self.Taser = true
				self:FuckingStun(self.Target,0.9)
			end
		else
			self:EmitSound("weapons/clipempty_rifle.wav")
			self:SetNextPrimaryFire(CurTime() + 2)
		end
		return
	end
 
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) 
	self.Weapon:EmitSound(self.Primary.Sound)
	
	if SERVER then
		local Target = self.Owner:GetEyeTrace().Entity
		if SWEPConfig.gameRP and IsValid(Target) and IsValid(self.ent) and Target:IsPlayer() and ((SWEPConfig.WantedOnly and not Target:isWanted()) or table.HasValue(SWEPConfig.RestrictJobs,Target:Team())) then 
				self.Weapon:SetNextPrimaryFire(CurTime() + 0.5)
				self.Owner:ViewPunch(Angle(math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0))
				self.LastPrimaryAttack = CurTime()
				return
		end
		if IsValid(self.ent) and IsValid(Target) and  Target:IsPlayer() and self.Owner:GetPos():Distance(Target:GetPos()) <= SWEPConfig.MaxDist then 
			self.Target = Target
			self.dist = self.Owner:GetPos():Distance(self.Target:GetPos())
			if not IsValid(self.Target.HelpEnt) then self:CreateMarionete(self.Target) end
			
			local pos = self.Target.HelpEnt:WorldToLocal(self.Owner:GetEyeTrace().HitPos)
			local const1,rop1 = constraint.Rope( self.ent, self.Target.HelpEnt, 0, 0,Vector(0.1,0.1,0),pos,self.dist,80,0,1, "cable/blue_elec",false )
			local const2,rop2 = constraint.Rope( self.ent,  self.Target.HelpEnt, 0, 0,Vector(-0.1,-0.1,0),pos,self.dist,80,0,1, "cable/redlaser",false )
		
		elseif self.Target == nil then
			self:CreateFakeRope()
		end
		self.Weapon:SetNextPrimaryFire(CurTime() + 0.5)
	end
	

	self:TakePrimaryAmmo(1)
	if self.Owner:IsNPC() then return end
	self.Owner:ViewPunch(Angle(math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0))
	self.LastPrimaryAttack = CurTime()
end


I have a error with TakePrimaryAmmo, help pls!

Your SWEP needs to be using “weapon_base” or a weapon base that uses “weapon_base” as the base IIRC.

Your base inheritance needs to eventually resolve to weapon_base, or you can just re-declare the function in your weapon:


function SWEP:TakePrimaryAmmo( num )

	-- Doesn't use clips
	if ( self.Weapon:Clip1() <= 0 ) then

		if ( self:Ammo1() <= 0 ) then return end

		self.Owner:RemoveAmmo( num, self.Weapon:GetPrimaryAmmoType() )

	return end

	self.Weapon:SetClip1( self.Weapon:Clip1() - num )

end

I love u :slight_smile: thanks