Make players drop weapons on death

I was wondering if anyone could give me the code for making players drop their currently equipped weapon on death.

[lua]hook.Add( “PlayerDeath”, “DropWeaponsOnDeath”, function( ply, inflictor, killer )
for k, v in ipairs( ply:GetWeapons() ) do
local newweap = ents.Create( v:GetClass() )
newweap:SetPos( ply:GetPos() + ply:GetUp() * 45 ) --around holding height
local phys = newweap:GetPhysicsObject()
if IsValid( phys ) then
phys:SetVelocity( ply:GetVelocity() ) --Make it fly forward with the player
end )[/lua]

I don’t know how to script what so ever but i think it would be a bad idea.
1:Someone killed them because they wanted there sniper or shotgun, then that person will go around trying to get there weapon back.
2:If its an admin the just randomly stop no-clipping but the admins health is low so when the admin hit the ground the admin dies and drops the admin gun by accident. Or even worse drop a ass mod gun that kicks people when it gets shot(that is if you have the gun anyway).

local function onPlayerDeath(ply)
if ply:GetActiveWeapon() ~= NullEntity() then
local wep = ents.Create(ply:GetActiveWeapon():GetClass())
wep:SetPos(ply:GetPos() + Vector(0,0,20))

Pseudocode, may or may not work.

Who said it was for RP or sandbox?


TRIPLE NINJA? :ninja: :ninja: :ninja:

Im just saying

Wont that drop all weapons not just the currantly equiped one?

I’m not going to give admins admin guns or any over-powerful admin weapons, because they are useless, i will however be making an Admin-only server, for the admins to screw around on, because it will be fun.

And I will only be using the drop weapon on death for the Garry Warfare gamemode im creating.

It’s just a script I had to show the concept. Hopefully he will be able to figure out how to change it to how he wants with GBPs’ code.

Arrr ok

Do a check on the weapon class, admin problem fixed.

** “Im just saying” **


most of the time the admins are being disorderly, and it is the regulars that suffer

And as the coder it is your job to prevent those things or any other flaws/problems that may arise.

function dropgun( ply )
concommand.Add( “drop”,gundrop )

then just create a new function
function deathgundrop( ply )
ply:ConCommand( “drop” )
then just hook it to PlayerDeath

You don’t know anything…

nofear, i’ve had bad experience with your coding, i’m going to pass.