Garry's Mod Wiki

Player:SetActiveWeapon

  Player:SetActiveWeapon( Weapon weapon )

Description

Sets the player's active weapon. You should use CUserCmd:SelectWeapon or Player:SelectWeapon, instead in most cases.

This function will not trigger the weapon switch events or associated equip animations. It will bypass GM:PlayerSwitchWeapon and the currently active weapon's WEAPON:Holster return value.

Arguments

1 Weapon weapon
The weapon to equip.

Example

Holster the weapon of a player and restore it after 20 seconds.

local ply = Entity( 1 ) local prevWeapon = ply:GetActiveWeapon() local prevWeaponClass = prevWeapon:GetClass() ply:SetActiveWeapon( NULL ) -- Holster the weapon timer.Simple(20, function() if ( !prevWeapon:IsValid() ) then prevWeapon = ply:Give( prevWeaponClass ) end ply:SelectWeapon( prevWeapon ) end)