[TTT] Excluding entities from a "in pairs" loop

So I have a weapon that disarms the player it shoots at but because this is TTT, there are some weapons that I do not want to be removed when the player is shot. My current way of doing it removes all weapons and then gives the default TTT weapons back but it causes an issue where people can pickup multiple primary weapons, which obviously shouldn’t happen.

Ply in this case would be the trace entity that is declared in the Primary Attack function.



function SWEP:WeaponHandler(ply)
	for k, v in pairs(ply:GetWeapons()) do
			print(v)
		
		ply:DropWeapon(v)
		ply:Give("weapon_zm_improvised")
		ply:Give("weapon_zm_carry")
		ply:Give("weapon_ttt_unarmed")
	end
end


So my question is can I make it so that the player only drops “v” if “v” is not equal to a certain group of entities. I could not get it to work for the life of me

This is what happens when I print “v” and those are the weapon entities.



Weapon [10][weapon_zm_improvised]
Weapon [81][weapon_zm_carry]
Weapon [82][weapon_ttt_unarmed]


Thanks

You can use the keyword ‘continue’ inside loops to skip iterations and lookup tables to filter weapons you don’t want to be dropped:



-- Weapon classes players should not drop
local DontDrop = {
	weapon_zm_improvised = true,
	weapon_zm_carry = true,
	weapon_ttt_unarmed = true,
}

for i, wep in pairs( ply:GetWeapons() ) do
	-- Skip if it's a weapon we don't want to drop
	if DontDrop[wep:GetClass()] then continue end

	ply:DropWeapon( wep )
end


I did not know of the “continue” keyword and it appears that your code works perfectly. I had already figured out that I needed to use GetClass() and was tinkering with that before I checked this post again. Thank you very much!

Edit: It appears that “continue” is not in regular Lua and is a product of another coding language that GLua has.

You might want to take a look at this post in regards to your use of DropWeapon

Alright but I am not familiar with the WEPS library or if it even exists. I will mess with this in my SWep code and see what happens