OnPlayerGiveDamage

From SA-MP Wiki

Jump to: navigation, search


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


OnPlayerGiveDamage 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, damagedid, Float:amount, weaponid)
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.


This callback does not handle returns.


public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid)
{
    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", attacker, amount, victim, weaponname);
    SendClientMessageToAll(0xFFFFFFFF, string);
    return 1;
}


Image:32px-Ambox_warning_orange.png Note: TakeDamage and GiveDamage won't match up perfectly until lag compensation is done on the shooting. And even then there will be some differences (due to lag).

One thing you can do with GiveDamage is detect when other players report that they have damaged a certain player, and that player hasn't taken any health loss. You can flag those players as suspicious.

You can also set all players to the same team (so they don't take damage from other players) and process all health loss from other players manually.

You might have a server where players get a wanted level if they attack Cop players (or some specific class). In that case you might trust GiveDamage over TakeDamage.

There should be a lot you can do with it. You just have to keep in mind the levels of trust between clients. In most cases it's better to trust the client who is being damaged to report their health/armour (TakeDamage). SA-MP normally does this. GiveDamage provides some extra information which may be useful when you require a different level of trust.


Related Callbacks

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

Personal tools
In other languages