SA-MP Forums Archive
how to spawn npc? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: how to spawn npc? (/showthread.php?tid=605988)



how to spawn npc? - GunZsmd - 27.04.2016

Hi guys.
I would like to know how we can force a npc to spawn. I have a RP gamemode i added a NPC for a command im making it appears on the console he connects but i cant see any new id's ingame and he doesnt spawn. Any sugestions?
cumpz
vasco


Re: how to spawn npc? - oMa37 - 28.04.2016

You can't see the ID's of NPC in the players list (aka tab) but make sure you are in the correct world where the NPC is spawned.


Re: how to spawn npc? - itsCody - 28.04.2016

NPCs start at like ID 0 since they usually connect/spawn before any players do.


Re: how to spawn npc? - CalvinC - 28.04.2016

Make sure you don't try to show the login/register dialogs to it, and even if it spawned it probably spawned at coodinates 0, 0, 0.
Add something like this:
Код:
public OnPlayerConnect(playerid)
{
    if(IsPlayerNPC(playerid))
    {
        SetPlayerPos(playerid, x, y, z); // Replace with the coordinates he should spawn at
        return 1;
    }

    // The rest of your code

}



Respuesta: Re: how to spawn npc? - GunZsmd - 28.04.2016

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
Make sure you don't try to show the login/register dialogs to it, and even if it spawned it probably spawned at coodinates 0, 0, 0.
Add something like this:
Код:
public OnPlayerConnect(playerid)
{
    if(IsPlayerNPC(playerid))
    {
        SetPlayerPos(playerid, x, y, z); // Replace with the coordinates he should spawn at
        return 1;
    }

    // The rest of your code

}
Hum i did that and it still doesnt spawn him cuz id 0 should be him like it says on the console but when i join im the id 0 and the bot just doesnt exist. Imma leave here the scripts:

OnGamemodeInit:
PHP код:
deliveryplane CreateVehicle(512,-13.0069,-122.7030,2.0356,85.8541,0,0,0);
    
ConnectNPC("deliveryguy""delivery"); 
OnPlayerConnect
PHP код:
if(IsPlayerNPC(playerid))
    {
        
SetPlayerPos(playerid, -13.0069,-122.7030,2.0356); // Replace with the coordinates he should spawn at
        
return 1;
    }
    
// the rest of the login script is here 
OnPlayerSpawn
PHP код:
if(IsPlayerNPC(playerid))
  {
    new 
npcname[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnpcnamesizeof(npcname));
    if(!
strcmp(npcname"deliveryguy"true))
    {
      
PutPlayerInVehicle(playeriddeliveryplane0);
    }
    return 
1;
  } 
Please can anyone help me?


Respuesta: how to spawn npc? - GunZsmd - 28.04.2016

anyone??


Respuesta: how to spawn npc? - GunZsmd - 28.04.2016

plz i really need this npc can anyone help me? ill +rep


Re: how to spawn npc? - thaKing - 28.04.2016

ongamemodeinit
PHP код:
ConnectNPC("deliveryguy""delivery"); 
onplayerrequestclass
PHP код:
if (IsPlayerNPC(playerid)) {
    new 
playername[64];
    
GetPlayerName(playerid,playername,64);
    if (!
strcmp(playername"deliveryguy"true)) {
        
SetSpawnInfo(playeridNO_CLASS1, -13.0069, -122.70302.03560.0, -1, -1, -1, -1, -1, -1);
    }
    return 
1;

onplayerspawn
PHP код:
if (IsPlayerNPC(playerid)) {
    new 
playername[64];
    
GetPlayerName(playerid,playername,64);
    if(!
strcmp(playername"deliveryguy"true)) {
        
PutPlayerInVehicle(playerid10);
        
SetPlayerColor(playerid0xFFFFFFFF);
    }

also you must have npc-record file in npcmodes/recordings and of course the npc file in npcmodes


Respuesta: how to spawn npc? - GunZsmd - 28.04.2016

Well it didnt spawn. But imma give up trying to use NPC's it was suppost to be like a command that a player did and then a NPC delivered them the materials he asked for. All was ready but NPC aint working so imma go for like airdroping a crate. But thanks i +rep u guys thx rly for trying