OnNPCSpawn
Description
This callback is called when an NPC spawns.
| Name | Description |
|---|---|
| npcid | The 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_Spawnis 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)
Related Functions
- NPC_Spawn: Spawn an NPC in the game world
- NPC_Respawn: Respawn a dead NPC
- NPC_SetHealth: Set NPC's health
- NPC_SetWeapon: Set NPC's weapon
Related Callbacks
- OnNPCCreate: Called when an NPC is created
- OnNPCRespawn: Called when an NPC respawns
- OnNPCDeath: Called when an NPC dies
- OnPlayerSpawn: Called when a player spawns