OnPlayerDeath

From SA-MP

Jump to: navigation, search


OnPlayerDeath

This callback is called when a player dies.


(playerid, killerid, reason)
playeridPID of the player who dies.
killeridID of the player who killed the player who died, or INVALID_PLAYER_ID if there was none.
reasonID of the reason for the player's death.


This function does not return a specific value, it's best to simply ignore it.


To use the standard death messages simply do:

public OnPlayerDeath(playerid, killerid, reason)
 {
     SendDeathMessage(killerid, playerid, reason);
     return 1;
 }

Contrary to popular belief you do not need the check to see if killerid is INVALID_PLAYER_ID before sending the message as if it is you just send INVALID_PLAYER_ID anyway, making the entire check pointless and redundant. However you will require this check before doing other things such as awarding money.

Usage Example

//common piece of code to fill the kill list
public OnPlayerDeath(playerid, killerid, reason)
{
    if (killerid != INVALID_PLAYER_ID) {
        //teamkill? very bad, punish the player
        if (gTeam[playerid] == gTeam[killerid]) {
            SetPlayerScore(killerid, GetPlayerScore(killerid) - 1);
        }
        else {
            SetPlayerScore(killerid, GetPlayerScore(killerid) + 1);
        }
    }
    SendDeathMessage(killerid, playerid, reason);
    return 1;
}

Related Functions

The following functions might be useful as well, as they're related to this function in one way or another.

Personal tools