a little change to the addon: Weapon drop

i like a little change to this addon http://www.garrysmod.org/img/?t=dll&id=19519

normaly you just walk over the dropped gun to pick it up again.
I want that you only can pick it up by pressing E.

I don’t know anything about lua but I think it easy to do it.

I’ve done this before. Create an new .txt file, copy-paste the below code in it, then rename the txt file to something like useweaponpickup.lua



if SERVER and !ConVarExists("useweaponpickup") then
    CreateConVar("useweaponpickup", '1', FCVAR_ARCHIVE)
end
hook.Add("PlayerLoadout","WeaponPickupUse_Loadout",function(ply)
	ply.usewep_loadout=1
	timer.Simple( 0.5, function()
		ply.usewep_loadout=0
	end)
end)
hook.Add("PlayerGiveSWEP","WeaponPickupUse_GiveSWEP",function(ply, wname, wtable )
	ply.usewep_loadout=1
	timer.Simple( 0.5, function()
		ply.usewep_loadout=0
	end)
end)
hook.Add("PlayerCanPickupWeapon","WeaponPickupUse",function(ply, ent)
	if GetConVarNumber("useweaponpickup") != 0 then
		if ply.usewep_loadout==1 or ply:GetPos():Distance(ent:GetPos())<2 then return true end
		if ply:KeyDown(IN_USE) and ply:Alive() then
			local pos = ply:GetShootPos()
			local dir = ply:GetAimVector()
			local tracew = {}
			tracew.start = pos
			tracew.endpos = pos+(dir*80)
			tracew.filter = ply
			local trace = util.TraceLine(tracew)
			if trace.Hit and trace.Entity == ent then
				return true
			else
				return false
			end
		else
			return false
		end
	end
end)


The console command for it is: useweaponpickup
It starts enabled.

thanks i will try when im home.

Ok, I didn’t test this exact code though. I modified it slightly, so there might be some errors. Post them here if you get any.

i tested it it worked all fine but one thing not. i can’t spawn any weapons by left clicking on the icons
.

Oh yeah, I forgot about that bug. Right clicking on them will still spawn them, just on the ground where you are looking. I’ll look into fixing that bug though, I think I know what’s wrong.

Edit:

Ok, I think have fixed that problem. I have updated the code from one of my older posts. Just replace your old code with that newer code

It works now and its way better than i thought. Thanks a lot!