முதன்மை உள்ளடக்கத்துக்குச் செல்லவும்

NPC_IsValid

எச்சரிக்கை

செயல்பாடு என்பது omp v1.5.8.3079 பதிப்பில் சேர்க்கப்பட்டது. இது முந்தைய பதிப்புகளில் இயங்காது!

Description​

Checks if an NPC ID is valid and the NPC exists.

NameDescription
npcidThe NPC ID to check.

Returns​

Returns true if the NPC is valid, false otherwise.

Examples​

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

new bool:isValid = NPC_IsValid(npcid);

SendClientMessage(playerid, 0x00FF00FF, "NPC %d is valid: %s", npcid, isValid ? "Yes" : "No");
return 1;
}
return 0;
}

Notes​

உதவிக்குறிப்பு
  • Always check if an NPC is valid before performing operations on it. This prevents runtime errors and crashes.
  • Use this in loops when iterating through potential NPC IDs.
குறிப்பு

An NPC becomes invalid when it is destroyed.