Saltar al contenido principal

NPC_Spawn

aviso

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

Description

Spawns an NPC into the game world, making it visible and active.

NameDescription
npcidThe ID of the NPC.

Returns

Returns true if the NPC was spawned successfully, false otherwise.

Examples

public OnPlayerCommandText(playerid, cmdtext[])
{
if (!strcmp(cmdtext, "/createnpc", true))
{
new name[24];
format(name, sizeof name, "Bot_%d", g_NPCCount++);

new npcid = NPC_Create(name);
if (NPC_IsValid(npcid))
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);

NPC_Spawn(npcid);
NPC_SetPos(npcid, x + 3.0, y, z);
NPC_SetWeapon(npcid, WEAPON_M4);
NPC_SetAmmo(npcid, 500);

PlayerNPC[playerid] = npcid;
SendClientMessage(playerid, 0x00FF00FF, "NPC %s (ID %d) spawned near you!", name, npcid);
}
else
{
SendClientMessage(playerid, 0xFF0000FF, "Failed to create NPC!");
}
return 1;
}
return 0;
}

Notes

aviso
  • The NPC must be created with NPC_Create before spawning.