Garry's Mod Wiki

Player:GetAmmoCount

  number Player:GetAmmoCount( any ammotype )

Description

Gets the amount of ammo the player has.

Arguments

1 any ammotype
The ammunition type. Can be either number ammo ID or string ammo name.

Returns

1 number
The amount of ammo player has in reserve.

Example

A function that returns the ammo for the weapon the player is currently holding.

function GetAmmoForCurrentWeapon( ply ) if ( !IsValid( ply ) ) then return -1 end local wep = ply:GetActiveWeapon() if ( !IsValid( wep ) ) then return -1 end return ply:GetAmmoCount( wep:GetPrimaryAmmoType() ) end
Output: 31

Example

Example usage. "pistol" ammo type has ID of 3.

print( Entity( 1 ):GetAmmoCount( 3 ) ) print( Entity( 1 ):GetAmmoCount( "3" ) ) print( Entity( 1 ):GetAmmoCount( "pistol" ) )
Output:
255 0 255