Aller au contenu principal

OnNPCDestroy

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 is destroyed and removed from the server.

NameDescription
npcidThe ID of the NPC that was destroyed

Examples​

public OnNPCDestroy(npcid)
{
printf("[NPC] NPC %d has been destroyed", npcid);

// Clear any player tracking this NPC and notify
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if (!IsPlayerConnected(playerid))
continue;

if (PlayerNPC[playerid] == npcid)
{
PlayerNPC[playerid] = INVALID_NPC_ID;
SendClientMessage(playerid, 0xFF0000FF, "Your tracked NPC %d has been destroyed", npcid);
}
else
{
SendClientMessage(playerid, 0xFFFF00FF, "NPC %d has been destroyed", npcid);
}
}
return 1;
}

Notes​

  • This callback is called immediately before the NPC is removed from the server
  • The NPC will be disconnected and its player slot freed after this callback

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