DarkRP.CanDropWeapon

From DarkRP
This page refers to DarkRP 2.4.3. This information may be incorrect as of later versions.
Check here for a up-to-date list of hooks.

Syntax[edit]

DescriptionCalled when a player tries to drop a weapon
Syntax
GAMEMODE:CanDropWeapon(Player ply, Entity weapon)
ReturnsCanDrop (boolean): whether the player is allowed to drop this weapon. Return nothing to use the default.

Arguments

  • ply (Player)
  • The player who wants to drop a weapon

  • weapon (Entity)
  • The weapon that the player wants to drop

    Examples[edit]

    DescriptionPeople can drop weapons they bought, but they cannot drop weapons they spawned with. e.g. If a gundealer buys a glock he can drop it, but a cop who spawned with it can't.
    Code
    hook.Add("CanDropWeapon", "example", function(ply, weapon)
            if not IsValid(weapon) then return end
    	local class = weapon:GetClass()
    	class = string.lower(class)
    
    	-- The player spawns with this weapon
    	if RPExtraTeams[ply:Team()] and table.HasValue(RPExtraTeams[ply:Team()].weapons, class) then
    		return false
    	end
    	-- Return nothing otherwise to take the default (by default things like pocket and keys can't be dropped)
    end)
    
    OutputPeople can't drop the weapons they spawned with