Drop Weapon

I’ve setup the concommand so that when I type “dropweapon” in the console it will call the corresponding function on the server. The only problem is I can’t seem to actually get the drop weapon working in the way I had intended. The standard player:DropWeapon() doesn’t seem to work right… I’ve also tried to spawn a new weapon with ents.Create( ) and player:StripWeapon() This works almost perfectly, except, I don’t know how to transfer the ammo on the player and the clips to the new weapon, so that when it’s picked up by another player it has the same ammo as when dropped. Please I really need help with this…

I’ve tried those functions before. If I remember the code right, it went something like this… Maybe I’m doing something wrong? This is off the top of my head and partially pseudo code, so it may not be entirely accurate.

[lua]
activeWeapon = ply:GetActiveWeapon()
if(activeWeapon is valid…) then
clip1 = activeWeapon:Clip1()
clip2 = activeWeapon:Clip2()
weapclass = activeWeapon:GetClass()

ply:StripWeapon(activeWeapon)

newWeap = ents.Create(weapclass)
newWeap:SetPos(…)
newWeap:Spawn()
newWeap:Activate()
newWeap:SetClip1(clip1)
newWeap:SetClip2(clip2)
end
[/lua]

Yes that should work. Just be sure to cleanup your … placeholders into their correct format
If you are still having problems with that start console output debug to make sure the code is actually executing and check your variables to see what is happening.

I have a similar function, it does not call Activate(), just spawn and setclip and works fine for me.

I did have some SWEPS that wanted to spawn ammo whenever you picked them up, and I didn’t want to bother changin the sweps at the moment so I threw this hack together.
So if you are having problems with stacking ammo on dropped guns, I ran into this as well.



local ammoType = Currentweapon:GetPrimaryAmmoType()
local ammo = ply:GetAmmoCount(ammoType)
ply:SetAmmo(ammo-ammo, ammoType)


It will consume ammo for guns that don’t give you ammo on pickup. So the ideal solution would be for me to remove whichever script picking up the gun gives free ammo, but I am lazy and just tagged it with a – TODO: fix this blah blah details