Getting Max Ammo Amount

As the title says, how do you get the max amount of ammo for the current weapon’s mag?

If it’s a default HL2 weapon, then you won’t be able to without predefining it as far as I know.

Otherwise, just do


ent:GetActiveWeapon().Primary.ClipSize

Replace “ent” with whatever you need it to be.

Ok thanks

Edit: This is working perfectly with custom weapons, is there a way to make it work with the HL weapons? If there isn’t a way how would I check to see if it wasn’t a custom weapon?

if ent:GetActiveWeapon().Primary then
should do the trick for checking if it actually has an accessible library.

If you would like to do C coded weapons like HL2 weapons, you’ll need to predefine their maxammo capacities.


    MaxAmmo={}
client = LocalPlayer()

    MaxAmmo["weapon_crowbar"]=0
    MaxAmmo["weapon_physcannon"]=0
    MaxAmmo["weapon_physgun"]=0
    MaxAmmo["weapon_pistol"]=18
    MaxAmmo["gmod_tool"]=0
    MaxAmmo["weapon_357"]=6
    MaxAmmo["weapon_smg1"]=45
    MaxAmmo["weapon_ar2"]=30
    MaxAmmo["weapon_crossbow"]=1
    MaxAmmo["weapon_frag"]=-1
    MaxAmmo["weapon_rpg"]=-1
    MaxAmmo["weapon_shotgun"]=6

    if client:GetActiveWeapon().Primarythen
        client:GetActiveWeapon().Primary.ClipSize
    else
        MaxAmmo[client:GetActiveWeapon():GetClass()]
    end

You can’t just stick that straight into your code, but that should give you a general enough idea to know what to do.

Thank you very much got my code working.