• Player Death Types
    6 replies, posted
In this addon I'm creating, I need a way to find out the damagetype that killed a player, such as explosion, crushed, etc. I wanted to store that type in the PlayerDeath hook, but so far I've had no luck. I've tried using inflictor:GetName() to see if the weapon that caused the death equaled a name (such as ttt_weapon_c4, or what have you), but so far, all the names are nil. I'd rather use the damagetype option, but I dunno how I could get that in the PlayerDeath hook, or anywhere for that matter. Any ideas?
Would inflictor:GetClass() work?
[QUOTE=vegasx;42730397]Would inflictor:GetClass() work?[/QUOTE] That worked for some things. When using a weapon, it just returns 'player' instead of the weapon name.
You mean this? [lua] hook.Add("PlayerDeath", "DeathType", function(ply, dmginfo, killer) print(dmginfo:GetDamageType()) end) [/lua]
[QUOTE=Gaming_Unlim;42749080]You mean this? [lua] hook.Add("PlayerDeath", "DeathType", function(ply, dmginfo, killer) print(dmginfo:GetDamageType()) end) [/lua][/QUOTE] Sort of, but I'm also looking for the name of the weapon, such as 'weapon_ttt_glock', etc. etc. Edit: Also I don't think that second argument can use the CTakeDamageInfo methods. It's an entity, not a Damage class.
[lua] hook.Add("PlayerDeath", "Weapon name from killer", function( ply, dmg, killer ) if killer:IsPlayer() then print(killer:GetActiveWeapon()) end end) [/lua] Unless the killer switches weapons faster than lua runs, this should work.
[QUOTE=arcaneex;42751024][lua] hook.Add("PlayerDeath", "Weapon name from killer", function( ply, dmg, killer ) if killer:IsPlayer() then print(killer:GetActiveWeapon()) end end) [/lua] Unless the killer switches weapons faster than lua runs, this should work.[/QUOTE] Looks good, I'll give it a try and see how it does. EDIT: Worked like a charm, thank you!
Sorry, you need to Log In to post a reply to this thread.