PlayerDeath bug?

I’m trying to figure out what weapon a player used to kill someone in the PlayerDeath hook, but the ‘weapon’ param is the same as the ‘killer’ param, the player himself. The only time it’s different is if the killer uses something like an RPG or prop.

Also I don’t want to use killer:getactiveweapon or something because the player might be dead

what is going on here

You could try using the PlayerHurt hook, and if the damage would kill the player then get get the active weapon after checking it’s valid, here’s the wiki on playerhurt

hope this helps

Only weapons with a delayed attack will show up if the player were to die before the enemy got killed. So you can do 2 things.

  1. –This can have that rare innaccuracy
    Check if weapon is player
    if not then check if player is alive

  2. –Shouldn’t ever have innaccuracy
    Use playerbindpress and check when the player changes weapons. Send a command to the server to see which weapon he switched to and store it’s name as a variable on the player. When he kills someone just look at that variable for the weapon you want to show.

Maybe **[Gamemode.DoPlayerDeath](**
will help you.

How do I get the weapon used from that, the dmginfo doesn’t have it I think


Doesn’t work. Something like this should do the trick:

[lua]hook.Add( “EntityTakeDamage”, “foo”, function( ply, inf, attacker, dmg, info )
ply.DamageWeapon = attacker:GetActiveWeapon():GetClass()
end )

hook.Add( “PlayerDeath”, “foo2”, function( ply, inf, killer )
print( ply:Nick() … " was killed by " … killer:Nick() … " with a " … ply.DamageWeapon )
end )[/lua]

That would still pose the same problem he was talking about. The player could die before he killed a person. Logging it when the player changes weapons would prevent that.

Or your could log they’re weapon in the DoPlayerDeath(), and then do what Overv said but if the attacker is dead set ply.DamageWeapon to the one you logged in DoPlayerDeath.

How would that work unless the weapon is ranged?

If you mean how would the player die before his target is killed, these can have that happen:
Grenades, crossbow, rocket launcher, various SWEPs that have delayed damage, and SENTs that report the player as the attacker.

Those can be detected manually.

Why go through that trouble when you could just do what you said, but also log their gun right before they die in a DoPlayerDeath() hook. I don’t even know how you would detect them manually, because all it would show is the projectile of the weapon and not the actual weapon.


and how does that solve your problem of people dieing before the player is killed?

I’d suggest something along the lines of what Overv posted.

You could log the weapon with **[Gamemode.PlayerTraceAttack](**. The only issue is it gets called when a player is hit by a trace and is damaged by it, so stuff like ranged weapons could be subject to error.

That is unless CTakeDamageInfo.GetInflictor works. You could start logging from when IN_ATTACK gets pressed by the player with a KeyPress hook for an initial log, and then check if it hits/kills with PlayerTraceAttack or one of the PlayerDeath hooks.

Both CTakeDamage.GetInflictor and CTakeDamage.GetAttacker return the player.

It’s not to solve the problem of them being killed, it’s to solve the problem of what weapon they were using if they were to be dead.

Hey, as far as I know, the attacker can’t be dead at the moment PlayerDeath is called if the weapon used was a hitscan weapon. If the attacker was dead, the weapon wouldn’t exist anymore, and there would be no inflictor to be found. That’s obviously different with projectile based weapons because the inflictor would then be the projectile itself.

You guys are overcomplicating things, just use GetActiveWeapon only if the inflictor is the same as the attacker, which happens only on hitscan weapons, problem solved.

Yeah I thought about it a little bit and that makes the most sense. If the player’s dead then I’ll check what the projectile was from.