SWEP.Ammo2

From GMod Wiki

Jump to: navigation, search
Event Hook
Hook NameAmmo2
SyntaxSWEP:Ammo2( )
DescriptionReturns the amount of secondary ammo in reserve.
ReturnsInteger
Lua StateNewerShared.png
BBCode[b][url=wiki.garrysmod.com/?title=SWEP.Ammo2]SWEP.Ammo2 [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:Ammo2()
	return self.Owner:GetAmmoCount( self:GetSecondaryAmmoType() )
end

Examples

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

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox