Pular para o conteúdo principal

OnNPCTakeDamage

atenção

This function was added in omp v1.5.8.3079 and will not work in earlier versions!

Description

This callback is called when an NPC takes damage from a player or another NPC.

NameDescription
npcidThe ID of the NPC that took damage
damageridThe ID of the player/NPC that caused the damage
damageThe amount of damage that was taken
weaponidThe weapon ID used to cause the damage
bodypartThe body part that was hit

Returns

Return false to prevent the damage from being applied, or true to allow it.

Examples

public OnNPCTakeDamage(npcid, damagerid, Float:damage, WEAPON:weaponid, bodypart)
{
// Only notify players tracking this NPC
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if (!IsPlayerConnected(playerid))
continue;

if (PlayerNPC[playerid] == npcid)
{
if (damagerid == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, 0xFF8800FF, "NPC %d took %.1f damage (weapon: %d, bodypart: %d)",
npcid, damage, _:weaponid, bodypart);
}
else
{
SendClientMessage(playerid, 0xFF8800FF, "NPC %d took %.1f damage from player %d (weapon: %d, bodypart: %d)",
npcid, damage, damagerid, _:weaponid, bodypart);
}
}
}
return 1;
}

Notes

  • This callback is called before the damage is actually applied to the NPC
  • Returning false will prevent the damage from being applied
  • The damagerid parameter will be INVALID_PLAYER_ID if damage is not caused by player
  • Body parts use the same constants as OnPlayerTakeDamage

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