Aller au contenu principal

NPC_Kill

attention

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

Description

Kills an NPC with a specific weapon/reason.

NameDescription
npcidThe ID of the NPC to kill
killeridThe ID of the player who killed the NPC (optional, use INVALID_PLAYER_ID for no killer)
reasonThe weapon ID or reason for death (default: 255 for suicide)

Returns

Returns true on success, false on failure.

Examples

public OnPlayerCommandText(playerid, cmdtext[])
{
if (!strcmp(cmdtext, "/npckill", true))
{
new npcid = PlayerNPC[playerid];
if (npcid == INVALID_NPC_ID)
return SendClientMessage(playerid, 0xFF0000FF, "You are not debugging a NPC.");

if (!NPC_IsValid(npcid))
return SendClientMessage(playerid, 0xFF0000FF, "Invalid NPC.");

NPC_Kill(npcid);

SendClientMessage(playerid, 0x00FF00FF, "NPC %d has been killed.", npcid);
return 1;
}
return 0;
}

Notes

  • Use INVALID_PLAYER_ID for killerid if there is no killer
  • The reason parameter uses weapon IDs (WEAPON enum)
  • This triggers the OnNPCDeath callback