GM:PlayerDeath

From Garry's Mod
Jump to: navigation, search
 GM:PlayerDeath( )

Contents

Description

Called when a player is killed by Player:Kill or any other normal means, except for when the player is killed with Player:KillSilent.

See GM:PostPlayerDeath for a hook in which the player is 100% dead.
See GM:PlayerSilentDeath for a hook that handles player deaths caused by Player:KillSilent.
See GM:DoPlayerDeath for a hook where player is still considered alive and is about to die.

See Player:LastHitGroup if you need to get the last hit hitgroup of the player.

Arguments

Player victim

The player who died

Arguments

Entity inflictor

Item used to kill the person

Arguments

Entity attacker

Player or entity that killed the victim

Examples

Example

If the player suicides (he is the killer and the victim (ply)), then it will print a message to console. If someone else kills him, it will print a different message to console.

function GM:PlayerDeath( victim, inflictor, attacker )
    if ( victim == attacker ) then
        PrintMessage( HUD_PRINTTALK, victim:Name() .. " committed suicide." )
    else
        PrintMessage( HUD_PRINTTALK, victim:Name() .. " was killed by " .. attacker:Name() .. ".")
    end
end

Output:

If suicide:

Player1 has committed suicide.

Else:

Player1 was killed by Player2.
Personal tools
Navigation