OnPlayerTakeDamage

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 10:49, 17 January 2014
Smithy (Talk | contribs)
(Included new bodypart param in example)
← Previous diff
Revision as of 15:19, 1 February 2014
Connor Mead (Talk | contribs)

Next diff →
Line 59: Line 59:
[[Category:Scripting Callbacks]] [[Category:Scripting Callbacks]]
 +
 +[[en:OnPlayerTakeDamage]]

Revision as of 15:19, 1 February 2014



Description:

This callback is called when a player takes damage.


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


Parameters:
(playerid, issuerid, Float:amount, weaponid, bodypart)
playeridThe ID of the player that took damage.
issueridThe ID of the player that caused the damage. INVALID_PLAYER_ID if self-inflicted.
amountThe amount of dagmage the player took (health and armour combined).
weaponidThe ID of the weapon/reason for the damage.
bodypartThe body part that was hit. (NOTE: This parameter was added in 0.3z. Leave it out if using an older version!)


Return Values:

  • 1 - Allows this callback to be called in other scripts.
  • 0 - Callback will not be called in other scripts.
  • It is always called first in gamemodes so returning 0 there blocks filterscripts from seeing it


Example - Debugging

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
    if(issuerid != INVALID_PLAYER_ID) // If not self-inflicted
    {
        new
            infoString[128],
            weaponName[24],
            victimName[MAX_PLAYER_NAME],
            attackerName[MAX_PLAYER_NAME];
 
        GetPlayerName(playerid, victimName, sizeof (victimName));
        GetPlayerName(issuerid, attackerName, sizeof (attackerName));
 
        GetWeaponName(weaponid, weaponName, sizeof (weaponName));
 
        format(infoString, sizeof(infoString), "%s has made %.0f damage to %s, weapon: %s", attackerName, amount, victimName, weaponName);
        SendClientMessageToAll(-1, infoString);
    }
    return 1;
}

Example - One-shot-kill sniper headshots

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
    if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
    {
        // One shot to the head to kill with sniper rifle
        SetPlayerHealth(playerid, 0.0);
    }
    return 1;
}

Related Callbacks

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

In other languages