SA-MP Forums Archive
Why doesn't this function work? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Why doesn't this function work? (/showthread.php?tid=95810)



Why doesn't this function work? - Norn - 05.09.2009

pawn Код:
stock GetPlayerIDFromName(playername[])
{
    new name[255];
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      GetPlayerName(i,name,sizeof(name));
      if(strcmp(playername, name, false) == 0)
      {
        return i;
      }
    }
  }
  return INVALID_PLAYER_ID;
}
forward AddNPC(name[64], skin, Float:x, Float:y, Float:z, Float:angle);
public AddNPC(name[64], skin, Float:x, Float:y, Float:z, Float:angle)
{
  ConnectNPC(name,"npcidle"); //npcidle is just a blank script default with the 0.3 package.
  new npcid = GetPlayerIDFromName(name);
  SetSpawnInfo(npcid, 0, skin, x, y, z, angle, 0, 0, 0, 0, 0, 0);
  return 1;
}
AddNPC is the function that doesn't work, GetPlayerIDFromName works fine.

NPC connects to the server, but he's not ingame. Any ideas?


Re: Why doesn't this function work? - Zezombia - 05.09.2009

Norn, you have to spawn your NPC. SpawnPlayer(id).

I'm not certain, because my test script spawns any player automatically when they connect.


Re: Why doesn't this function work? - Norn - 05.09.2009

Quote:
Originally Posted by Zezombia
Norn, you have to spawn your NPC. SpawnPlayer(id).

I'm not certain, because my test script spawns any player automatically when they connect.
I never used SpawnPlayer(playerid) as i was told that the NPC spawns automatically on connection like you said.

Can you test it in your script and see if it works for you? Perhaps i have a script bug.


Re: Why doesn't this function work? - Zezombia - 05.09.2009

Alright brb.

Edit:

Alright I completely tested with and without auto-spawning. My bot Does connect and Is in-game. My guess is it has something to do with your "npcidle" (i used my own npcmode).


Re: Why doesn't this function work? - Norn - 05.09.2009

npcidle is just this

pawn Код:
//
// NPC Test Script
// Kye 2009
//

#include <a_npc>

//------------------------------------------

main()
{
  printf("npcidle: running");
}

//------------------------------------------
And my other npcs work fine doing it the old fashioned way, i wonder whats wrong.


Re: Why doesn't this function work? - Zezombia - 05.09.2009

I tryed your function with the npcidle. The bot still connects and is still in-game.

Edit: But he spawns in the defualt place, not in the place defined by your function.


Re: Why doesn't this function work? - Norn - 05.09.2009

Quote:
Originally Posted by Zezombia
I tryed your function with the npcidle. The bot still connects and is still in-game.

Edit: But he spawns in the defualt place, not in the place defined by your function.
Strange... i can't be bothered even thinking further, NPC's have been pissing me off lately lol.