GM:PlayerCanPickupWeapon

From Garry's Mod
Jump to: navigation, search
 GM:PlayerCanPickupWeapon( )

Contents

Description

Returns whether or not a player is allowed to pick up a weapon.

Arguments

Player ply

The player attempting to pick up the weapon

Arguments

Weapon wep

The weapon entity in question

Returns

boolean

Allowed pick up or not

Examples

Example

Disallows picking up a weapon if player already has this weapon. ( Prevents ammo pickups from lying guns )

hook.Add( "PlayerCanPickupWeapon", "noDoublePickup", function( ply, wep )
    if ( ply:HasWeapon( wep:GetClass() ) ) then return false end
end )


Examples

Example

Players can only pick up the HL2 Pistol.

function GM:PlayerCanPickupWeapon(ply, wep)
    return (wep:GetClass() == "weapon_pistol")
end


Examples

Example

How you could give a player an alternate weapon to the one they picked up (such as an RPG Launcher rather than a pistol)

hook.Add( "PlayerCanPickupWeapon", "NoPistolGiveFists", function( ply, wep )
	if wep:GetClass() == "weapon_pistol" then -- if the weapon they are trying to pick up is a pistol
		ply:Give( "weapon_rpg" ) -- give them an RPG
		wep:Remove() -- remove the one they were trying to pick up
		return false -- don't give them a pistol
	end
end )


Personal tools
Navigation