Garry's Mod Wiki

Revision Difference

WEAPON:SecondaryAttack#512195

<function name="SecondaryAttack" parent="WEAPON" type="hook">⤶ <ishook>yes</ishook>⤶ <description>⤶ Called when secondary attack button ( +attack2 ) is pressed.⤶ ⤶ For issues with this hook being called rapidly on the client side, see the global function <page>Global.IsFirstTimePredicted</page>.⤶ </description>⤶ <realm>Shared</realm>⤶ <predicted>Yes</predicted>⤶ </function>⤶ ⤶ <example>⤶ <description>This is how it is defined in weapon_base</description>⤶ <code>⤶ function SWEP:SecondaryAttack()⤶ ⤶ -- Make sure we can shoot first⤶ if ( !self:CanSecondaryAttack() ) then return end⤶ ⤶ -- Play shoot sound⤶ self.Weapon:EmitSound("Weapon_Shotgun.Single")⤶ ⤶ -- Shoot 9 bullets, 150 damage, 0.75 aimcone⤶ self:ShootBullet( 150, 9, 0.2 )⤶ ⤶ -- Remove 1 bullet from our clip⤶ self:TakeSecondaryAmmo( 1 )⤶ ⤶ -- Punch the player's view⤶ self.Owner:ViewPunch( Angle( -10, 0, 0 ) )⤶ ⤶ end⤶ </code>⤶ ⤶ </example>