Перейти к основному содержимому

OnNPCSpawn

Description

This callback is called when an NPC spawns.

NameDescription
npcidThe ID of the NPC that spawned

Examples

public OnNPCSpawn(npcid)
{
printf("[NPC] NPC %d has spawned", npcid);

// Notify players tracking this NPC
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if (!IsPlayerConnected(playerid))
continue;

if (PlayerNPC[playerid] == npcid)
{
new Float:x, Float:y, Float:z;
NPC_GetPos(npcid, x, y, z);
SendClientMessage(playerid, 0x00FF00FF, "Your tracked NPC %d spawned at (%.2f, %.2f, %.2f)", npcid, x, y, z);
}
}
return 1;
}

Notes

  • This callback is called when NPC_Spawn is successfully executed
  • The NPC becomes visible and interactive in the game world
  • You can set initial NPC properties and behaviors in this callback
  • The NPC's stats are automatically set to default values (100 health, 0 armor, fists weapon)