Limit primary weapon.

I’m trying to limit a player’s primary and secondary weapon to one. For e.g. I don’t want an Ak47 and a M4a1 at the same time, only the Ak47 or M4a1. I’m creating a gamemode when the victim drops their weapon I want the attacker to be able to swap their weapon rather then keeping their current weapon as well as picking up the victim’s weapon.

Are you asking how to do it, or are you just telling us what you are doing?

The game mode needs to know what ‘type’ each weapon is, so you can make a ‘weapon_class’ = ‘type’ lookup table, or put something like SWEP.Type = ‘type’ inside the weapons. Then, when a player picks up a weapon, loop through all of the players weapons and remove the ones that are the same as the type being picked up.

Not the best way to do it but well This lets you pick up an weapon from the floor and Strip the current equipied one

[LUA]hook.Add( “PlayerSpawn”, “PickupTimeout”, function( ply )
ply.PickupTimeout = CurTime() + 0.5
end )

hook.Add( “PlayerCanPickupWeapon”, “NoPickup”, function( ply, wep )
if ( ( ply.PickupTimeout or 0 ) < CurTime() ) then return false end
end )

hook.Add( “KeyPress”, “PressUse”, function( ply, key )
if ( key == IN_USE ) then
local tr = ply:GetEyeTrace()
local weapon = ply:GetActiveWeapon()
if ( ValidEntity( tr.Entity ) and tr.Entity:IsWeapon() and tr.Entity:GetPos():Distance( ply:GetShootPos() ) < 96 ) then
ply.PickupTimeout = CurTime() + 0.5
ply:StripWeapon(weapon:GetClass())
ply:Give( tr.Entity:GetClass()) – tr.entity:getclass

		tr.Entity:Remove()
	end
end

end )[/LUA]