SWEP.SecondaryAttack

From GMod Wiki

Revision as of 00:49, 23 December 2009 by Nerdboy (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Event Hook
Hook NameSecondaryAttack
SyntaxSWEP:SecondaryAttack( )
DescriptionActivates when +attack2 is pressed.
ReturnsNil
Lua StateNewerShared.png
BBCode[b][url=wiki.garrysmod.com/?title=SWEP.SecondaryAttack]SWEP.SecondaryAttack [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionA zoom function taken from SteveUK's Scout Rifle.
Used onNewerShared.png
Code
/*---------------------------------------------------------
	SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
	//The variable "ScopeLevel" tells how far the scope has zoomed.
	//This SWEP has 2 zoom levels.
	if(ScopeLevel == 0) then
 
		if(SERVER) then
			self.Owner:SetFOV( 45, 0 )
			//SetFOV changes the field of view, or zoom. First argument is the
			//number of degrees in the player's view (lower numbers zoom farther,)
			//and the second is the duration it takes in seconds.
		end	
 
		ScopeLevel = 1
		//This is zoom level 1.
 
	else if(ScopeLevel == 1) then
 
		if(SERVER) then
			self.Owner:SetFOV( 25, 0 )
		end	
 
		ScopeLevel = 2
		//This is zoom level 2.
 
	else
		//If the user is zoomed in all the way, reset their view.
		if(SERVER) then
			self.Owner:SetFOV( 0, 0 )
			//Setting the FOV to zero resets the player's view, AFAIK
		end		
 
		ScopeLevel = 0
		//There is no zoom.
 
	end
	end
 
end
OutputN/A


See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox