SWEP.PrimaryAttack

From GMod Wiki

Jump to: navigation, search
Event Hook
Hook NamePrimaryAttack
SyntaxSWEP:PrimaryAttack( )
DescriptionActivates when +attack1 is pressed.
ReturnsNil
Lua StateNewerShared.png
BBCode[b][url=wiki.garrysmod.com/?title=SWEP.PrimaryAttack]SWEP.PrimaryAttack [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]

Examples

DescriptionShoots a bullet if we can.
Used onNewerShared.png
Code
function SWEP:PrimaryAttack()
 
	// Make sure we can shoot first
	if ( !self:CanPrimaryAttack() ) then return end
 
	// Play shoot sound
	self:EmitSound("Weapon_AR2.Single")
 
	// Shoot 1 bullet, 150 damage, 0.75 aimcone
	self:ShootBullet( 150, 1, 0.01 )
 
	// Remove 1 bullet from our clip
	self:TakePrimaryAmmo( 1 )
 
	// Punch the player's view
	self.Owner:ViewPunch( Angle( -1, 0, 0 ) )
 
end
OutputN/A


Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox