Drop Weapon on Death

Hello,
I have this code that drops every weapon equipped on death. I’m wondering what I could use to make it so the player only drops the weapon they are holding.


-- Weapon Drop v2 by Maxter(v2) and iThermal(v1)

dropweps = 1

dontdrop = {}
dontdrop[1] = "weapon_fist"
dontdrop[2] = "weapon_knife"
dontdrop[3] = "weapon_crowbar"


function droptheweapon(ply)

	if dropweps == 1 then
	
	droppos = ply:GetPos() + Vector(0, 0, 30)
	
		for k, v in pairs (ply:GetWeapons()) do
		
			loopwep = v:GetClass()
		
			if not table.HasValue(dontdrop, loopwep) then
		
				local dropthiswep = ents.Create(loopwep)
				dropthiswep:SetPos(droppos)
				dropthiswep:Spawn()
		
			end
		
		end
	
	end

end

function toggledropweps(caller)

	if caller:IsAdmin() then
	
		if dropweps == 1 then
		
			dropweps = 0
			
			caller:ChatPrint("You turned off weapon dropping!")
			
		elseif dropweps == 0 then
		
			dropweps = 1
			
			caller:ChatPrint("You turned on weapon dropping!")
			
		end
	
	end

end

concommand.Add("toggleweapondrop", toggledropweps)
hook.Add("DoPlayerDeath", "pldrophook", droptheweapon)

Thanks.

you trying to innstall this on DAKRRP?, beacouse DARKRP already have this script innstaled and you could turn it ON in Config.lua :), there they only drop gun you are holding

Thanks but no. This is a custom gamemode.

Even tho his english is not very good, he has a point DarkRP does have the function just have a look through it.

I will do it later if you have not already tried that

[lua]
if SERVER then
local SWEP = FindMetaTable(“Weapon”)
if !SWEP then return end

function SWEP:DampenDrop()
	--Originally from TTT
	local phys = self:GetPhysicsObject()
	if IsValid(phys) then
		phys:SetVelocityInstantaneous(Vector(0,0,-75) + phys:GetVelocity() * 0.001)
		phys:AddAngleVelocity(phys:GetAngleVelocity() * -0.99)
	end
end

local WeaponBlackList = {
	weapon_crowbar = true,
	weapon_fist = true,
	weapon_physgun = true,
	weapon_knife = true
}

local CVarName = "DropWeaponToggle"
if !ConVarExists(CVarName) then
	CreateConVar(CVarName, "1", FCVAR_NOTIFY)
end

hook.Add("DoPlayerDeath", "DropActiveWeapon", function(ply, attacker, dmginfo)
	local wep = ply:GetActiveWeapon()
	local CVar = GetConVar(CVarName)
	local CVarEnabled = CVar:GetBool()
	local CanDrop = WeaponBlackList[wep:GetClass()]
	if IsValid(wep) and CVarEnabled and !CanDrop then
		ply:DropWeapon(wep)
		wep:DampenDrop()
	end
end)

end
[/lua]

Thank you very much.