NPC_IsSpawned
注意
这个函数是在omp v1.5.8.3079中添加的,在以前的版本中不起作用!
描述
检查 NPC 是否已在游戏世界中生成。
| 参数 | 说明 |
|---|---|
| npcid | NPC 的 ID |
返回值
若 NPC 已生成则返回 true,否则返回 false。
示例
public OnPlayerCommandText(playerid, cmdtext[])
{
if (!strcmp(cmdtext, "/checkspawned", true))
{
new npcid = PlayerNPC[playerid];
if (npcid == INVALID_NPC_ID)
return SendClientMessage(playerid, 0xFF0000FF, "你没有在调试NPC。");
if (!NPC_IsValid(npcid))
return SendClientMessage(playerid, 0xFF0000FF, "无效的NPC。");
new bool:isSpawned = NPC_IsSpawned(npcid);
SendClientMessage(playerid, 0x00FF00FF, "NPC %d 已生成: %s", npcid, isSpawned ? "是" : "否");
return 1;
}
return 0;
}
注意事项
- 这与 NPC_IsValid 不同,后者检查 NPC 是否存在
相关函数
- NPC_Spawn: 生成 NPC
- NPC_Respawn: 重新生成 NPC
- NPC_IsValid: 检查 NPC 是否有效
- NPC_IsDead: 检查 NPC 是否死亡
相关回调
- OnNPCSpawn: 当 NPC 生成时被调用
- OnNPCRespawn: 当 NPC 重新生成时被调用