SWEP.Reload

From GMod Wiki

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

Examples

DescriptionThis is taken from the Pump-shotgun
Used onNewerShared.png
Code
function SWEP:Reload()
 
	//if ( CLIENT ) then return end
 
	self:SetIronsights( false )
 
	// Already reloading
	if ( self:GetNetworkedBool( "reloading", true ) ) then return end
 
	// Start reloading if we can
	if ( self:Clip1() < self.Primary.ClipSize && self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 ) then
 
		self:SetNetworkedBool( "reloading", true )
		self:SetVar( "reloadtimer", CurTime() + 0.3 )
		self:SendWeaponAnim( ACT_VM_RELOAD )
 
	end
 
end
OutputN/A


DescriptionA better example of a reload function
Used onNewerShared.png
Code
function SWEP:Reload()
 
	if self.ReloadingTime and CurTime() <= self.ReloadingTime then return end
 
	if ( self:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 ) then
 
		self:DefaultReload( ACT_VM_RELOAD )
                local AnimationTime = self.Owner:GetViewModel():SequenceDuration()
                self.ReloadingTime = CurTime() + AnimationTime
                self:SetNextPrimaryFire(CurTime() + AnimationTime)
                self:SetNextSecondaryFire(CurTime() + AnimationTime)
 
	end
 
end
OutputN/A


See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox