OnNPCDeath
attention
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.
| Name | Description |
|---|---|
| npcid | The ID of the NPC that died |
| killerid | The ID of the player/NPC that killed the NPC (or INVALID_PLAYER_ID if none) |
| reason | The 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
killeridparameter will beINVALID_PLAYER_IDif the NPC death was not player inflicted - The
reasonparameter contains the weapon ID that caused the death (255 for unknown/other causes)
Related Functions
The following functions might be useful, as they're related to this callback in one way or another.
- NPC_Kill: Kill an NPC
- NPC_Respawn: Respawn a dead NPC
- NPC_GetHealth: Get NPC's health
- NPC_SetHealth: Set NPC's health
Related Callbacks
- OnNPCSpawn: Called when an NPC spawns
- OnNPCRespawn: Called when an NPC respawns
- OnNPCTakeDamage: Called when an NPC takes damage
- OnPlayerDeath: Called when a player dies