Garry's Mod Wiki

SANDBOX:PlayerSpawnSWEP

  boolean SANDBOX:PlayerSpawnSWEP( Player ply, string weapon, table swep )

Description

Called when a player attempts to spawn a weapon from the Q menu as an entity on the ground. (Mouse wheel clicks on an icon)

Not to be confused with SANDBOX:PlayerGiveSWEP, which is called only when the weapon is given to the player directly, if they don't already have it.

Arguments

1 Player ply
The player who attempted to spawn a weapon.
2 string weapon
Class name of the weapon the player tried to spawn.
3 table swep
Information about the weapon the player is trying to spawn, see SWEP structure

Returns

1 boolean
Can the SWEP be spawned

Example

Stops non-admins from spawning weapons.

hook.Add( "PlayerSpawnSWEP", "SpawnBlockSWEP", function( ply, class, info ) if ( not ply:IsAdmin() ) then return false end end )