Garry's Mod Wiki


  Player:SelectWeapon( string className )


Sets the active weapon of the player by its class name.

This will switch the weapon out of prediction, causing delay on the client and WEAPON:Deploy and WEAPON:Holster to be called out of prediction. Try using CUserCmd:SelectWeapon or input.SelectWeapon, instead.
This will trigger the weapon switch event and associated animations. To switch weapons silently, use Player:SetActiveWeapon.


1 string className
The class name of the weapon to switch to.

If the player doesn't have the specified weapon, nothing will happen. You can use Player:Give to give the weapon first.


Force the player to switch to toolgun

Entity( 1 ):SelectWeapon( "gmod_tool" )


Selects a random weapon from the player's inventory and switches to it.

local weapons = Entity( 1 ):GetWeapons() local weapon = weapons[ math.random( #weapons ) ] Entity( 1 ):SelectWeapon( weapon:GetClass() )