SANDBOX/PlayerGiveSWEP

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Change GM usage to hook.Add in example)
 
Line 27: Line 27:
 
{{Example
 
{{Example
 
|Description=Stops non-admins from giving themselves weapons.
 
|Description=Stops non-admins from giving themselves weapons.
|Code=function GM:PlayerGiveSWEP( ply, class, swep )
+
|Code=hook.Add( "PlayerGiveSWEP", "BlockPlayerSWEPs", function( ply, class, swep )
if (not ply:IsAdmin()) then
+
if ( not ply:IsAdmin() ) then
  return false
+
return false
end
+
end
end
+
end )
 
}}
 
}}

Latest revision as of 20:03, 24 June 2019

 SANDBOX:PlayerGiveSWEP( )

Contents

Description

Called when a player attempts to give themselves a weapon from the Q menu. ( Left mouse clicks on an icon )

Arguments

Player ply

The player who attempted to give themselves a weapon.

Arguments

string weapon

Class name of the weapon the player tried to give themselves.

Arguments

table swep

The swep table of this weapon, see SWEP structure

Returns

boolean

Can the SWEP be given to the player

Examples

Example

Stops non-admins from giving themselves weapons.

hook.Add( "PlayerGiveSWEP", "BlockPlayerSWEPs", function( ply, class, swep )
	if ( not ply:IsAdmin() ) then
		return false
	end
end )


Personal tools
Navigation