self.SetClip1 expects an entity?

ISSUE RESOLVED, made variables global and corrected the way I used self:Clip1.

I’m making a SWEP that allows a player to throw his/her weapon and retrieve it.
The SWEP creates a variable, “AK47Clip”, modifies it every time the player loses the weapon, and then sets the clip to the value of that variable every time the SWEP is initialized. The SWEP is based on Worshipper’s Mad Cow Weapons, but I highly doubt that Worshipper included his own variable “AK47Clip.” (He didn’t.)

Here’s the SWEP’s initialize function.

[lua]/---------------------------------------------------------
Name: SWEP:Initialize()
Desc: Called when the weapon is first loaded.
---------------------------------------------------------
/
function SWEP:Initialize()

if AK47Pickup==1 then
	self.SetClip1(AK47Clip) //line 50 BTW.
end
self:SetWeaponHoldType(self.HoldType)
AK47Pickup=0
if (SERVER) then

	// Fucking NPCs
	self:SetNPCMinBurst(30)
	self:SetNPCMaxBurst(30)
	self:SetNPCFireRate(self.Primary.Delay)
end

end
[/lua]

And here’s the Secondary Attack function, where I set the variable “AK47Clip.”

[lua]
/---------------------------------------------------------
Name: SWEP:SecondaryAttack()
Desc: +attack2 has been pressed.
---------------------------------------------------------
/
function SWEP:SecondaryAttack()

if (self.Owner:KeyDown(IN_USE)) then

	self.Weapon:EmitSound("weapons/iceaxe/iceaxe_swing1.wav")
	self.Weapon:SetNextPrimaryFire(CurTime() + 1)
	self.Weapon:SetNextSecondaryFire(CurTime() + 1)
	self.Weapon:SendWeaponAnim(ACT_VM_DRAW)

	if (SERVER) then
		local knife = ents.Create("ent_mad_ak47")
		knife:SetAngles(self.Owner:EyeAngles())

// if (self:GetIronsights() == false) then
local pos = self.Owner:GetShootPos()
pos = pos + self.Owner:GetForward() * 5
pos = pos + self.Owner:GetRight() * 9
pos = pos + self.Owner:GetUp() * -5
knife:SetPos(pos)
// else
// knife:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector()))
// end

		knife:SetOwner(self.Owner)
		knife:SetPhysicsAttacker(self.Owner)
		knife:Spawn()
		knife:Activate()

		self.Owner:SetAnimation(PLAYER_ATTACK1)

		local phys = knife:GetPhysicsObject()
		phys:SetVelocity(self.Owner:GetAimVector() * 700)
		phys:AddAngleVelocity(Vector(0, 500, 0))
		local AK47Clip=self.Clip1
		local AK47Pickup=1
		self.Owner:StripWeapon("weapon_mad_ak472")
	end
else

if self.Owner:IsNPC() then return end
if not IsFirstTimePredicted() then return end


if (!self.IronSightsPos) or (self.Owner:KeyDown(IN_SPEED) or self.Weapon:GetDTBool(0)) then return end

// Not pressing Use + Right click? Ironsights
bIronsights = !self.Weapon:GetDTBool(1)
self:SetIronsights(bIronsights)

self.Weapon:SetNextPrimaryFire(CurTime() + 0.2)
self.Weapon:SetNextSecondaryFire(CurTime() + 0.2)
end

end
[/lua]

The issue isn’t with ent_mad_ak47, that just gives the player the weapon when used (and forces him/her to select it.).

The error I get occurs when the player attempts to pick up the weapon by using the spawned ent_mad_ak47, and is (serverside)
…cows weapons\lua\weapons\weapon_mad_ak472\shared.lua:50: bad argument #1 to ‘SetClip1’ (Entity expected, got function)

I’m pretty sure Weapon.SetClip1 is supposed to accept an integer. If I change line 50 to self.SetClip1(47) then I get the error (serverside)
…cows weapons\lua\weapons\weapon_mad_ak472\shared.lua:50: bad argument #1 to ‘SetClip1’ (Entity expected, got number)

I think it’s weird that Weapon.SetClip1 suddenly won’t even accept an integer, clearly I’m doing something horribly, horribly wrong.

Sorry for a bit of an inflated post, but if anyone can tell me how I’m abusing weapon.SetClip1, I’d appreciate it.
Thanks!

[lua]self.Weapon:SetClip1(10)[/lua]

Er…I get my mistake now. Thanks for the timely reply.

My issue now is that on pickup, the clip reverts to 30. It seems to be ignoring my variable, or worse, not setting the variable at all. Does there seem to be anything wrong with the way I set “AK47Clip”?

Thanks.

Set a delay on it.

Er…a delay on setting the variable or a delay on self:SetClip1? The latter doesn’t seem to accomplish anything. :saddowns:

Ohh i see what you’re doing you have to set the clip when someone picks it up im sure there is a function in the weapon that does that.

Never mind me, I just corrected some errors (self:Clip1()) and made my variables global. Done, works like a charm.

Thanks for the help. :v:

No problemo.