Garry's Mod Wiki

Revision Difference

WEAPON:TakePrimaryAmmo#512180

<function name="TakePrimaryAmmo" parent="WEAPON" type="hook">⤶ <ishook>yes</ishook>⤶ <description>A convenience function to remove primary ammo from clip.</description>⤶ <realm>Shared</realm>⤶ <args>⤶ <arg name="amount" type="number">Amount of primary ammo to remove</arg>⤶ </args>⤶ </function>⤶ ⤶ <example>⤶ <description>As defined in weapon_base</description>⤶ <code>⤶ function SWEP:TakePrimaryAmmo( num )⤶ ⤶ -- Doesn't use clips⤶ if ( self.Weapon:Clip1() &amp;lt;= 0 ) then ⤶ ⤶ if ( self:Ammo1() &amp;lt;= 0 ) then return end⤶ ⤶ self.Owner:RemoveAmmo( num, self.Weapon:GetPrimaryAmmoType() )⤶ ⤶ return end⤶ ⤶ self.Weapon:SetClip1( self.Weapon:Clip1() - num ) ⤶ ⤶ end⤶ </code>⤶ ⤶ </example>