OnPlayerGiveDamage

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 15:25, 20 November 2016
OstGot (Talk | contribs)

← Previous diff
Revision as of 13:33, 13 June 2017
OstGot (Talk | contribs)

Next diff →
Line 26: Line 26:
GetWeaponName(weaponid, weaponname, sizeof (weaponname)); GetWeaponName(weaponid, weaponname, sizeof (weaponname));
- format(string, sizeof(string), "%s has made %.0f damage to %s, weapon: %s", attacker, amount, victim, weaponname);+ format(string, sizeof(string), "%s has made %.0f damage to %s, weapon: %s, bodypart: %d", attacker, amount, victim, weaponname, bodypart);
SendClientMessageToAll(0xFFFFFFFF, string); SendClientMessageToAll(0xFFFFFFFF, string);
return 1; return 1;

Revision as of 13:33, 13 June 2017



Description:

This callback is called when a player gives damage to another player.


OnPlayerGiveDamage 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, damagedid, Float:amount, weaponid, bodypart)
playeridThe ID of the player that gave damage.
damagedidThe ID of the player that received damage.
amountThe amount of health/armour damagedid has lost (combined).
weaponidThe reason that caused 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 - 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


public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
    new string[128], victim[MAX_PLAYER_NAME], attacker[MAX_PLAYER_NAME];
    new weaponname[24];
    GetPlayerName(playerid, attacker, sizeof (attacker));
    GetPlayerName(damagedid, victim, sizeof (victim));
 
    GetWeaponName(weaponid, weaponname, sizeof (weaponname));
    format(string, sizeof(string), "%s has made %.0f damage to %s, weapon: %s, bodypart: %d", attacker, amount, victim, weaponname, bodypart);
    SendClientMessageToAll(0xFFFFFFFF, string);
    return 1;
}


Image:32px-Ambox_warning_orange.png

Notes

  • Keep in mind this function can be inaccurate in some cases.
  • If you want to prevent certain players from damaging eachother, use SetPlayerTeam.
  • The weaponid will return 37 (flame thrower) from any fire sources (e.g. molotov, 18)
  • The weaponid will return 51 from any weapon that creates an explosion (e.g. RPG, grenade)


Related Callbacks

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

Personal tools
In other languages