Player/GetAmmoCount

From Garry's Mod
Jump to: navigation, search
 Player:GetAmmoCount( )

Contents

Description

Gets the amount of ammo the player has.

Arguments

any ammotype

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

Returns

number

The amount of ammo player has in reserve.

Examples

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

Examples

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
Personal tools
Navigation