OnPlayerTakeDamage

From SA-MP Wiki

Jump to: navigation, search


This callback is called when a player takes damage.


OnPlayerTakeDamage was added in SA-MP 0.3x This callback was added in SA-MP 0.3d and will not work in earlier versions!


Parameters:
(playerid, issuerid, Float:amount, weaponid)
playeridThe ID of the player that took damage.
issueridThe ID of the player that caused the damage. INVALID_PLAYER_ID if none.
amountThe amount of health/armour playerid has lost.
weaponidThe ID of the reason that caused the damage.


This callback does not handle returns.


public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(issuerid != INVALID_PLAYER_ID)
    {
        new string[128], victim[MAX_PLAYER_NAME], attacker[MAX_PLAYER_NAME];
        new weaponname[24];
        GetPlayerName(playerid, victim, sizeof (victim));
        GetPlayerName(issuerid, attacker, sizeof (attacker));
 
        GetWeaponName(weaponid, weaponname, sizeof (weaponname));
        format(string, sizeof(string), "%s has made %.0f damage to %s, weapon: %s", attacker, amount, victim, weaponname);
        SendClientMessageToAll(0xFFFFFFFF, string);
    }
    return 1;
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(issuerid != INVALID_PLAYER_ID && weaponid == 34)
    {
        // One shot to kill with sniper rifle
        SetPlayerHealth(playerid, 0.0);
    }
    return 1;
}

Related Callbacks

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

Personal tools