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 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.<br><br>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: 34ms

Session 0
DB GetPage 3
Generate Html 8
SaveChanges 8
Render Body 0
Render Sidebar 12