(Question) Getting active weapon clip size?

So for awhile now I’ve been trying to get an entity to give a player a whole clip of their active weapon. I figured this would be really easy and simple but I’ve run in to a few problems. I’ve been told to use Clip1 but that would end up returning what ever is in the clip at the time and I need the max clip. There is also the challenge with custom weapons, so I figured I would create some kind of ConVar:GetInt that returns the ClipSize/DefaultClip of the active weapon. But I have no idea how.

This is what I have so far.



function ENT:Touch( activator, caller )
	if ( activator:IsNPC() ) then return end
	if ( activator:IsPlayer() ) then -- If a player, not an NPC or prop or anything, activates it
		self:Remove() -- Remove the entity.
		activator:ChatPrint('You recieved ammo for your held weapon.') -- Chat prints so you know you reciveved ammo.
		activator:EmitSound('items/smallmedkit1.wav') -- Sound plays so you know you recivevd ammo.
		local ammoconvar = -- ???
		local clipcount = activator:GetActiveWeapon():ammoconvar() -- Defines local variable to get active weapon max ammo magazine/clip.
		local ammotype = activator:GetActiveWeapon():GetPrimaryAmmoType() -- Defines local variable to get active weapon ammo type.
		print( ammotype ) -- Ammo type test.
		print( clipcount ) -- Max magazine/clip count test.
		activator:GiveAmmo( clipcount, ammotype, true ) -- Gives correct ammo and ammount in regards of active weapon to player.
	end
end


I’m still fairly new to lua but I really want to get the hang of it and learn other coding languages. Can someone help me out?

This is probably what you’re looking for: http://wiki.garrysmod.com/page/Weapon/GetMaxClip1

This will be added next update.

So it currently doesn’t work?

It’ll work in the dev branch but not the current live game.

No, however, in the Source codebase, it’s the equivalent of returning SWEP.Primary.ClipSize, which you can get currently by using

weapons.Get

WeaponObj.Primary.ClipSize?

Edit: Ninja’d

Ah, that’s what I was looking at for awhile is that SWEP.Primary.ClipSize line but I wasn’t sure how to return it.

If you have a reference to the weapon, you should do wep.Primary.ClipSize, which only works on SWEPs.

So when it says " weapons.Get( string classname ) " would what goes in parenthesis be the swep or the information return from the sweps table?

The SWEP class name. Only use that if you can’t access the weapon entity.