Hello friends, I have a small LUA code that makes weapons require the Use key pressed to pick them up:
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 )
This works fine, except for a couple of drawbacks:
I can’t simply select a weapon to use from the list, I need to right-click spawn it.
I can’t spawn weapons from the Toybox at all. Sometimes holding the Use key and clicking the weapon will download the stuff for it, but still no weapon.
How can I fix this? I want to be able to spawn weapons as normal, but any weapons on the ground I want to have to press Use to pick them up.
This code was in a download from garrysmod.org, and I haven’t touched it. Not to say I don’t have any LUA coding experiance, I’ve done a few bits and bobs in my time so I know a little. Any and all help is greatly appreciated.