Get current weapon clip size

I’ve searched and still haven’t found anything that actually works.
this should work but I get this error instead:
[Error] attempt to index field ‘Primary’ (a nil value)
Could someone help me out here? I need to get the clip size so I can display it in my hud, like so: AmmoInClip/ClipSize

EDIT: Solved; It’s impossible to do what I want, have to hard-code the vanilla weapon clip sizes.


The power of google.

[Error] attempt to index field ‘Primary’ (a nil value)
Am I doing this wrong? :confused:

this returns: ResetBones = true


Make sure you’re using an actual weapon, as the physgun will not work. Try the fists/medkit or a custom SWEP.

To bypass this try this.

local amo = LocalPlayer():GetActiveWeapon():GetTable().Primary
if amo != nil then
amo = amo.ClipSize
amo = -1

I did some testing with my friend and it turns out that things like toolguns work fine with .Primary.ClipSize, but actual weapons (SMG, etc) DON’T work. How great is that?

The base weapons (the css ones) don’t work, but custom packs like MadCows, FAS2, Customizable Weaponry, should work fine. Don’t quote me on that. :v:

Right but I’d like my hud to work with the regular weapons, which is why I made this thread. Is there seriously no way to get the clipsize of normal weapons?

EDIT: I’ll add that I have a potential workaround in mind, but it’s a last resort.

Not that I know of. What you can do is make a look up table like this for the standard weapons.

//Look up table
local wepmaxclips={}
wepmaxclips["weapon_shotgun"] = 6

//The max ammo in a variable to use for your hud.
local maxclip = wepmaxclips[LocalPlayer():GetActiveWeapon():GetClass()]

If you go with this idea, to save you printing each of the class names, here they are on the wiki below additional notes.

I would recommend using both methods and using this method as back up and if both fail, default the clip to -1 so you don’t get errors.

That’s pretty much what my workaround was going to be. Possibly doing something with checking the ammo count right after you reload to get the max clip size. Thanks for the help.