Garry's Mod Wiki


  Player:SetActiveWeapon( Weapon weapon )


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.


1 Weapon weapon
The weapon to equip.


local ply = Entity( 1 ) local prevWeapon = ply:GetActiveWeapon() ply:SetActiveWeapon( NULL ) -- Holster the weapon, useful for manning the turrets. local class if ( prevWeapon:IsValid() ) then class = prevWeapon:GetClass() end ply:SelectWeapon( class or "weapon_crowbar" ) -- switch to the last weapon or crowbar if prevWeapon is not valid