پرش به مطلب اصلی

OnNPCDeath

هشدار

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 dies.

NameDescription
npcidThe ID of the NPC that died
killeridThe ID of the player/NPC that killed the NPC (or INVALID_PLAYER_ID if none)
reasonThe reason for death (weapon ID or death cause)

Examples

public OnNPCDeath(npcid, killerid, WEAPON:reason)
{
printf("[NPC] NPC %d died (killer: %d, weapon: %d)", npcid, killerid, _:reason);

// Notify players tracking this NPC
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if (!IsPlayerConnected(playerid))
continue;

if (PlayerNPC[playerid] == npcid)
{
if (killerid == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, 0xFF0000FF, "Your tracked NPC %d died (weapon: %d)", npcid, _:reason);
}
else
{
SendClientMessage(playerid, 0xFF0000FF, "Your tracked NPC %d was killed by player %d (weapon: %d)", npcid, killerid, _:reason);
}
}
}
return 1;
}

Notes

  • The killerid parameter will be INVALID_PLAYER_ID if the NPC death was not player inflicted
  • The reason parameter contains the weapon ID that caused the death (255 for unknown/other causes)

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