Picking up weapons via Use

I am attempting to make it so that weapons can only be taken if you press +use whilst looking at them. My best attempt at this was to make an entity which mimics the weapon, with it model and positioning but when you interact wiht it, turns into the real thing and is picked up. Although I think this would be much better:

I attempted to use the above but failed. Any guidance? It would mean I don’t have to re-turn the weapon into an entity when dropped and also would be just cleaner.

Any help appreciated, thanks.

[lua]
function UseKeyOnly( ply )
if !ply:KeyDown( IN_USE ) then
return false
end
end
hook.Add(“PlayerCanPickupWeapon”, “UseKeyOnly”, UseKeyOnly)
[/lua]

[editline]11:22PM[/editline]

might work

[lua]
function UseKeyOnly( ply, weapon )

local trace = util.TraceLine(util.GetPlayerTrace( ply ))

if !ply:KeyDown( IN_USE ) and not trace.Entity == weapon then
return false
end
end
hook.Add(“PlayerCanPickupWeapon”, “UseKeyOnly”, UseKeyOnly)
[/lua]

Here is a snippet I posted some time ago. Use the search feature next time, there’s tons of these threads.