So I'm trying to code in a PlayerDeath hook, but it's not working.
Concept is simple, if someone dies, he drops his current weapon. Here is the code I've got.
[code]
function DropWeapon(ply)
ply:DropWeapon(ply:GetActiveWeapon())
end
hook.Add("PlayerDeath", "DropWeapon", DropWeapon)[/code]
I've copied the code from the GMOD wiki, and I'm running it server side.
I've also tried using the code below, with no success either. Any help would be appreciated. :)
[code]
function DropWeapon(victim, inflictor, killer)
victim:DropWeapon(victim:GetActiveWeapon())
end
hook.Add("PlayerDeath", "DropWeapon", DropWeapon)[/code]
The first thing I would do would be using some debug prints to see what's actually going on. Does the player have an active weapon or is he already dead?
Try that :
[lua]function DropWeapon(ply)
print(ply:GetActiveWeapon())
ply:DropWeapon(ply:GetActiveWeapon())
print("The weapon should've dropped now")
end
hook.Add("PlayerDeath", "DropWeapon", DropWeapon)[/lua]
If there's no weapon you'll have to use another hook, if it's not ran we'll need to find out why.
In the SWEP's code declaration, you may also set SWEP:ShouldDropOnDie() and return true, that should work too ;)
[QUOTE=Gbps;18187015]In the SWEP's code declaration, you may also set SWEP:ShouldDropOnDie() and return true, that should work too ;)[/QUOTE]
Except sometimes you want default weapons to be dropped too. :ninja:
This would be usefull with ragmod.
It seems that the player is already dead, before he can drop his weapon. Guess I'll need to find another hook.
[QUOTE=DDooby;18189943]It seems that the player is already dead, before he can drop his weapon. Guess I'll need to find another hook.[/QUOTE]
[lua]function ScaleDamage( ply, hitgroup, dmginfo )
if ply:Health() - dmginfo:GetDamage() <= 0 then
ply:DropWeapon(ply:GetActiveWeapon())
end
end
hook.Add("ScalePlayerDamage","ScaleDamage",ScaleDamage)[/lua]
Try that, it will probably work. I recommend you also setup a whitelist or blacklist so players don't drop their toolgun/physgun.
Well, I wanted the default weapons to drop too. Just for the sake of 'realism'. It's a DarkRP server and I thought it would be nice to see players drop their weapon to the ground when they died.
Code doesn't work, I'll forget the whole thing. I might try again later.
Next try. Autowanted when killing a cop or mayor. :)
Sorry, you need to Log In to post a reply to this thread.