Garry's Mod Wiki

Garry's Mod Wiki

  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)

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated four times a day. Edits and history are not available.

Last Parsed: Loading...