Manual weapon pickup+dropping and weapon limit?

So I have been trying to get a system that works like this for days now while also working on the gamemode itself, but it keeps glitching and breaking and overall is very unstable.

Basically what I want to do is make a system like in PUBG where you can have 2 primary weapons and 1 secondary and then to add on that I have a crowbar and health kit everyone spawns in with. (Currently I have no idea how to make the primary/secondary system, althought I know that all secondary weapons have slot 2 so thats something.)

Here are the issues I stumbled upon.

  • I need to drop all droppable weapons if I am fully equipped rather than dropping one to pick up another weapon.
  • Player can hold E and it will pickup everything the eyetrace passes.
  • Weapons sometime wont show up or be equippable but pressing G will drop them anyways.


function GM:PlayerButtonDown( ply, key )
if key == KEY_G and ply:GetActiveWeapon():IsValid() and (ply:GetActiveWeapon():GetClass() != "weapon_crowbar" and ply:GetActiveWeapon():GetClass() != "fas2_ifak") then
ply:DropWeapon(ply:GetActiveWeapon())
ply:EmitSound("items/ammocrate_close.wav")
end
end

function GM:PlayerCanPickupWeapon( ply, wep )
	if ( ply:KeyDown( IN_USE ) and ply:GetEyeTrace().Entity == wep and !ply:HasWeapon( wep:GetClass()) and #ply:GetWeapons() < 4) then
	ply:EmitSound("items/ammocrate_open.wav") return true	
	else return false end
end


Would be very grateful if someone could help me with this! :slight_smile: