Lewati ke konten utama

NPC_SetInvulnerable

peringatan

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

Description​

Sets whether an NPC is invulnerable to damage.

NameDescription
npcidThe ID of the NPC
toggletrue to make invulnerable, false to make vulnerable

Returns​

Returns true if the invulnerability was set successfully, false otherwise.

Examples​

public OnPlayerCommandText(playerid, cmdtext[])
{
if (!strcmp(cmdtext, "/toggleinvulnerable", 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.");

new bool:invulnerable = NPC_IsInvulnerable(npcid);
NPC_SetInvulnerable(npcid, !invulnerable);
SendClientMessage(playerid, 0x00FF00FF, "NPC %d invulnerable: %s", npcid, !invulnerable ? "Enabled" : "Disabled");

return 1;
}
return 0;
}

Notes​

  • Invulnerable NPCs will not take any damage from weapons, explosions, or other damage sources
  • This setting persists until changed or the NPC is destroyed
  • Invulnerable NPCs can still be moved, teleported, or have their animations changed
  • OnNPCTakeDamage: Called when NPC takes damage (not called for invulnerable NPCs)
  • OnNPCDeath: Called when NPC dies (invulnerable NPCs cannot die)