SWEP.Ammo1

From GMod Wiki

Jump to: navigation, search
Event Hook
Hook NameAmmo1
SyntaxSWEP:Ammo1( )
DescriptionReturns the amount of primary ammo in reserve.
ReturnsInteger ammo
Lua StateNewerShared.png
BBCode[b][url=wiki.garrysmod.com/?title=SWEP.Ammo1]SWEP.Ammo1 [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Definition of the function

Because it is a convenience function, it is defined by Lua.

function SWEP:Ammo1()
	return self.Owner:GetAmmoCount( self:GetPrimaryAmmoType() )
end

Examples

Descriptionmodified comments from shared.lua of the base weapon
Used onNewerShared.png
Code
function SWEP:TakePrimaryAmmo( num )
 
	if ( self:Clip1() <= 0 ) then // Doesn't use clips
 
		if ( self:Ammo1() <= 0 ) then return end //check if reserve ammo is available
 
		self.Owner:RemoveAmmo( num, self:GetPrimaryAmmoType() ) //take ammo
 
	return end
 
	self:SetClip1( self:Clip1() - num ) //subtract from clip
 
end
OutputN/A

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox