PlayerDeath Hook - Who killed the Player?

Hello everyone.

So basically, in my gamemode, I have custom sweps which are ranged. It always registers as “mdm_glock18” has killed the player, rather than saying the player has killed them. How can I check who the weapon belongs to?


function KillPlayer( victim, killer, weapon )

	if ( killer == weapon ) then
	
             -- What goes in here?

	end

end
hook.Add( "PlayerDeath", "OnPlayerDeath", KillPlayer )

You could use ENT:GetOwner() I guess. I still don’t quite know what the hell you are doing…

Uhh, are you looking for simply killer:Nick()?

Thanks, Starfox. That did work. In regards to what I’m doing, I am trying to make a gamemode for Garry’s Mod and I just sometimes don’t know what the code is for something.

Niandra, that isn’t what I meant, I didn’t want to get the suspect’s name, I wanted to identify the suspect as the object that the player was killed by wasn’t a player, but an object.

You’re calling it out of order: http://wiki.garrysmod.com/page/GM/PlayerDeath

It is victim, weapon_which_can_also_be_called_inflictor, attacker.

weapon_which_can_also_be_called_inflictor is the object, weapon or “explosive” that caused the death. Attacker is the player ( or world ) that used the weapon to kill the victim.

Here are some examples based on PlayerDeath ( gun-race, etc… ):
https://dl.dropboxusercontent.com/u/26074909/tutoring/_gamemode_logic/gun_race/sv_gun_race.lua.html

https://dl.dropboxusercontent.com/u/26074909/tutoring/_gamemode_logic/gun_race/sv_upgrade_weapons_for_kills.lua.html

Take a look at how it’s used in the base gamemode: https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/gamemode/player.lua#L146

There’s a little work that goes into finding out how the player died