Garry's Mod Wiki

Weapon

This is a list of all methods only available for weapons. It is also possible to call Entity functions on weapons.

A list of available methods has been expanded in your navigation bar.

Inherits methods from Entity.

Methods

Returns whether the weapon allows to being switched from when a better ( Weapon:GetWeight ) weapon is being picked up.
Returns whether the weapon allows to being switched to when a better ( Weapon:GetWeight ) weapon is being picked up.
Weapon:CallOnClient( string functionName, string arguments = "" )
Calls a SWEP function on client. This uses the usermessage internally, because of that, the combined length of the arguments of this function may not exceed 254 bytes/characters or the function will cease to function!
number Weapon:Clip1()
Returns how much primary ammo is in the magazine. This is not shared between clients and will instead return the maximum primary clip size.
number Weapon:Clip2()
Returns how much secondary ammo is in the magazine. This is not shared between clients and will instead return the maximum secondary clip size.
Forces the weapon to reload while playing given animation. This will stop the Weapon:Think function from getting called while the weapon is reloading!
Returns the sequence enumeration number that the weapon is playing. This can return inconsistent results between the server and client. Issue Tracker: 2543
Returns the weapon deploy speed, as set by Weapon:SetDeploySpeed. If not previously set, the value will be polled from the sv_defaultdeployspeed ConVar.
Returns the hold type of the weapon.
Returns maximum primary clip size
Returns maximum secondary clip size
Gets the next time the weapon can primary fire. ( Can call WEAPON:PrimaryAttack )
Gets the next time the weapon can secondary fire. ( Can call WEAPON:SecondaryAttack )
Gets the primary ammo type of the given weapon.
Returns the non-internal name of the weapon, that should be for displaying. If that returns an untranslated message (#HL2_XX), use language. GetPhrase to see the "nice" name. If SWEP. PrintName is not set in the Weapon or the Weapon Base then "<MISSING SWEP PRINT NAME>" will be returned.
Gets the ammo type of the given weapons secondary fire.
number Weapon:GetSlot()
Returns the slot of the weapon. The slot numbers start from 0.
Returns slot position of the weapon
Returns the view model of the weapon.
Returns the world model of the weapon.
number Weapon:GetWeight()
Returns the "weight" of the weapon, which is used when deciding which Weapon is better by the engine.
boolean Weapon:HasAmmo()
Returns whether the weapon has ammo left or not. It will return false when there's no ammo left in the magazine and when there's no reserve ammo left. This will return true for weapons like crowbar, gravity gun, etc.
Returns whenever the weapon is carried by the local player.
Checks if the weapon is a SWEP or a built-in weapon.
Returns whether the weapon is visible. The term visibility is not exactly what gets checked here, first it checks if the owner is a player, then checks if the active view model has EF_NODRAW flag NOT set.
Returns the time since this weapon last fired a bullet with Entity:FireBullets in seconds. It is not networked.
Weapon:SendWeaponAnim( number act )
Forces weapon to play activity/animation.
Weapon:SetActivity( number act )
Sets the activity the weapon is playing. See also Weapon:GetActivity.
Weapon:SetClip1( number ammo )
Lets you change the number of bullets in the given weapons primary clip.
Weapon:SetClip2( number ammo )
Lets you change the number of bullets in the given weapons secondary clip.
Weapon:SetDeploySpeed( number speed )
Sets the weapon deploy speed. This value needs to match on client and server.
Weapon:SetHoldType( string name )
Sets the hold type of the weapon. This function also calls WEAPON:SetWeaponHoldType and properly networks it to all clients. This only works on scripted weapons. Using this function on weapons held by bots will not network holdtype changes to clients if the world model is set to an empty string (SWEP. WorldModel = "").
Weapon:SetLastShootTime( number time = CurTime() )
Sets the time since this weapon last fired in seconds. Used in conjunction with Weapon:LastShootTime
Weapon:SetNextPrimaryFire( number time )
Sets when the weapon can fire again. Time should be based on CurTime. The standard HL2 Pistol (weapon_pistol) bypasses this function due to an internal implementation. This will fire extra bullets if the time is set to less than CurTime. Issue Tracker: 3786
Sets when the weapon can alt-fire again. Time should be based on CurTime.