Garry's Mod Wiki

Player:SelectWeapon

Player:SelectWeapon( string className )

Description

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.

Arguments

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.

Example

Force the player to switch to toolgun

Entity( 1 ):SelectWeapon( "gmod_tool" )

Example

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() )

Page Links


Special Pages


Wikis

?

Render Time: 89ms

DB GetPage 53
Generate Html 9
SaveChanges (1) 12
Render Body 0
Render Sidebar 12