Fixing this weapon pickup


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()
        if ( ValidEntity( tr.Entity ) and tr.Entity:IsWeapon() and tr.Entity:GetPos():Distance( ply:GetShootPos() ) < 96 ) then
            ply.PickupTimeout = CurTime() + 0.5
            
            ply:Give( tr.Entity:GetClass() )
            tr.Entity:Remove()
        end
    end
end )

I have no idea how lua coding works and I need to get this lua thing working. It’s a “Press use to pickup weapon” lua code.
Anybody mind fixing this for me? Would be very appreciated.

I fixed it for you. The problem was that the function ValidEntity() was removed in Gmod 13.


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()
        if ( tr.Entity:IsValid() and tr.Entity:IsWeapon() and tr.Entity:GetPos():Distance( ply:GetShootPos() ) < 96 ) then
            ply.PickupTimeout = CurTime() + 0.5
            
           // ply:Give( tr.Entity:GetClass() )
           // tr.Entity:Remove()
        end
    end
end )