OnPlayerTakeDamage
From SA-MP Wiki
(Difference between revisions)
Revision as of 15:46, 12 September 2017 Freaksken (Talk | contribs) ← Previous diff |
Revision as of 18:16, 3 October 2017 Vince (Talk | contribs) Next diff → |
||
Line 17: | Line 17: | ||
* It is always called first in filterscripts so returning 1 there blocks other filterscripts from seeing it.}} | * It is always called first in filterscripts so returning 1 there blocks other filterscripts from seeing it.}} | ||
- | {{note2|[[GetPlayerHealth]] and [[GetPlayerArmour]] will return the old amounts of the player before this callback.}} | + | {{notes2| |
+ | * [[GetPlayerHealth]] and [[GetPlayerArmour]] will return the old amounts of the player before this callback. | ||
+ | * '''Always''' check if issuerid is valid before using it as an array index.}} | ||
{{Notes| | {{Notes| |
Revision as of 18:16, 3 October 2017
Description:
This callback is called when a player takes damage.
(playerid, issuerid, Float:amount, weaponid, bodypart)
playerid | The ID of the player that took damage. |
issuerid | The ID of the player that caused the damage. INVALID_PLAYER_ID if self-inflicted. |
amount | The amount of damage the player took (health and armour combined). |
weaponid | The ID of the weapon/reason for the damage. |
bodypart | The body part that was hit. (NOTE: This parameter was added in 0.3z. Leave it out if using an older version!) |
Return Values:
- 1 - Callback will not be called in other filterscripts.
- 0 - Allows this callback to be called in other filterscripts.
- It is always called first in filterscripts so returning 1 there blocks other filterscripts from seeing it.
Important |
|
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, bodypart: %d", attackerName, amount, victimName, weaponName, bodypart); 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.
- OnPlayerGiveDamage: This callback is called when a player gives damage.
- OnPlayerWeaponShot: Called when a player fires a weapon.