Disallow picking up same weapon with PlayerCanPickupWeapon?

I’m trying to create a gamemode, but there’s a problem whenever people pickup gravity guns, stunsticks or crowbars. If they already have the gun they are trying to pickup from ground, they can still pick it up and there are limited amount of guns on the map, so anyone could steal all the guns and leave rest without.

I’ve tried this piece of code:

function GM:PlayerCanPickupWeapon(ply,wep)
    if ply:HasWeapon("weapon_physcannon")== true then
        if wep:GetClass() == "weapon_physcannon" then return false
        else return true
    return true

Unfortunatly this still allows players to pickup more gravity guns if they already have one. Any help here? What am I doing wrong?

EDIT: Realized my derp, I had that in shared.lua instead of init.lua. But now I’d like to make them also respawn… hmm let’s see.
EDIT2: I’d kind of like to make it apply to any weapon, the respawn code would be nice to handle it.

[LUA]function GM:PlayerCanPickupWeapon(ply,wep)
return !ply:HasWeapon(wep:GetClass())
This stops any players from picking up any weapons that they already have.

As for the respawn:
[LUA]local tmRespawn = 10
local function fcOnRemove(wep)
local class = wep:GetClass()
local origin = wep.m_origin
local ent = ents.Create(class)
ent.m_origin = origin
for _, ent in ipairs(ents.GetAll()) do
if(ent:IsWeapon() && ent:CreatedByMap()) then
ent.m_origin = {ent:GetPos(),ent:GetAngles()}
This will respawn any map-placed weapon that was picked up (or removed for a different reason) after 10 seconds (tmRespawn) at its origin.

Thanks! That works. Although, I still have a problem, on some maps there are only like 6 gravity guns and people lose them on death (they can respawn as they like) and I don’t want to drop any weapons on death or set them to spawn with these weapons with Loadout. The problem is, the map will run out of gravity guns very soon, especially with 24 players.

So, is it possible to respawn another weapon to same place when players pick it up? Near instantly.

[editline]27th January 2012[/editline]

Sorry, but your respawn code doesn’t seem to do anything. No lua errors. :frowning:

EDIT: It actually only works after the player carrying the weapon has died. I want to make an infinite stack in the same place.
EDIT2: In other words, picking up the weapon doesn’t do anything, but removing the weapon in any way such as dying will respawn it.

I think what you’re looking for is something along the lines of:
[lua]function GM:PlayerCanPickupWeapon(ply,wep)
if not (ply:HasWeapon( wep:GetClass() ) then ply:Give( wep:GetClass() ) end
return false
Where it doesn’t actually pick up the weapon