NPC Connects but doesn't spawn
#1

Hello,
I am having some trouble with my NPCs not spawning...
They connect to the server alright, just don't seem to spawn.

I am trying to run them through a filterscript which, probably isn't the best way to do it but still should work from my understanding.

NPC Filterscript
pawn Код:
#include <a_samp>


public OnFilterScriptInit()
{
    ConnectNPC("Test_Test","grotti_npc");
    print(" NPC Filterscript Loaded.");
    return 1;
}

public OnPlayerConnect(playerid)
{
    if(IsPlayerNPC(playerid)) {
        new ip_addr_npc[64+1];
        new ip_addr_server[64+1];
        new playername[64];
        GetPlayerName(playerid,playername,64);
        GetServerVarAsString("bind",ip_addr_server,64);
        GetPlayerIp(playerid,ip_addr_npc,64);

        if(!strlen(ip_addr_server)) {
            ip_addr_server = "127.0.0.1";
        }

        if(!strcmp(playername,"Test_Test",true)) {
        SetSpawnInfo(playerid,0,240,539.2943,-1291.9962,17.2422,0.0,0,0,0,0,0,0);
        }

        if(strcmp(ip_addr_npc,ip_addr_server,true) != 0) {
            // this bot is remote connecting
            printf("NPC: Got a remote NPC connecting from %s and I'm kicking it.",ip_addr_npc);
            Kick(playerid);
            return 0;
        }
        printf("NPC: Connection from %s is allowed.",ip_addr_npc);
    }

    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    if(!IsPlayerNPC(playerid)) return 0; // We only deal with NPC players in this script

    new playername[64];
    GetPlayerName(playerid,playername,64);

    if(!strcmp(playername,"Test_Test",true)) {
        SetSpawnInfo(playerid,69,240,539.2943,-1291.9962,17.2422,0.0,-1,-1,-1,-1,-1,-1);
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(!IsPlayerNPC(playerid)) return 1; // We only deal with NPC players in this script

    new playername[64];
    GetPlayerName(playerid,playername,64);

    if(!strcmp(playername,"Test_Test",true)) {
        printf("%s Spawned!",playername);
        SetPlayerColor(playerid,0xFF0000FF);
    }
    return 1;
}
NPC Script
pawn Код:
#include <a_npc>
#define RECORDING "grotti_npc" //This is the filename of your recording without the extension.
#define RECORDING_TYPE 1 //1 for in vehicle and 2 for on foot.

main(){}
public OnRecordingPlaybackEnd() StartRecordingPlayback(RECORDING_TYPE, RECORDING);

#if RECORDING_TYPE == 2
  public OnNPCEnterVehicle(vehicleid, seatid) StartRecordingPlayback(RECORDING_TYPE, RECORDING);
  public OnNPCExitVehicle() StopRecordingPlayback();
#else
  public OnNPCSpawn() StartRecordingPlayback(RECORDING_TYPE, RECORDING);
#endif
Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3d, ©2005-2011 SA-MP Team


Server Plugins
--------------
 Loading plugin: whirlpool

 ==================

  Whirlpool loaded

 ==================

  Loaded.
 Loading plugin: mysql


  > MySQL plugin R5 successfully loaded.

  Loaded.
 Loading plugin: sscanf


 ===============================

      sscanf plugin loaded.

   © 2009 Alex "******" Cole

 ===============================

  Loaded.
 Loading plugin: streamer


*** Streamer Plugin v2.5 by Incognito loaded ***

  Loaded.
 Loaded 4 plugins.


Started server on port: 7777, with maxplayers: 32 lanmode is OFF.


Filterscripts
---------------
  Loading filterscript 'colourtest.amx'...
Colour Filterscript Loaded
  Loading filterscript 'npcs.amx'...
 NPC Filterscript Loaded.
  Loaded 2 filterscripts.


 =======================================
 |                                     |
 |        YSI version 1.03.0011        |
 |        By Alex "******" Cole        |
 |                                     |
 |  Checking the latest YSI version..  |
 |                                     |
 =======================================

Number of vehicle models: 0
Incoming connection: 127.0.0.1:54222
[npc:join] Test_Test has joined the server (0:127.0.0.1)
NPC: Connection from 127.0.0.1 is allowed.

 =======================================
 |                                     |
 |   Error: Could not connect to YSI   |
 |  update server (response was 006).  |
 |                                     |
 =======================================
When you connect to my server for the first time, it comes up with a few questions before asking to create a password, Not sure if this will affect the way the NPCs connect...?

Cheers for your help in advance.
Reply
#2

Some callbacks (OnPlayerConnect, OnPlayerRequestClass, OnPlayerSpawn, OnPlayerRequestSpawn etc.) in your gamemode (or another filterscript) might stop the NPC from spawning. For example a login dialog that asks a player to input password before he/she can continue. It asks the password from NPC too and it will just stay there forever and doesn't spawn.

This is just a guess. Just look at these callbacks, see what parts should the NPC ignore and add these lines where necessary.

pawn Код:
if(IsPlayerNPC(playerid)) return 1;
Reply
#3

Now we've up set him

Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3d, ©2005-2011 SA-MP Team


Server Plugins
--------------
 Loading plugin: whirlpool

 ==================

  Whirlpool loaded

 ==================

  Loaded.
 Loading plugin: mysql


  > MySQL plugin R5 successfully loaded.

  Loaded.
 Loading plugin: sscanf


 ===============================

      sscanf plugin loaded.

   © 2009 Alex "******" Cole

 ===============================

  Loaded.
 Loading plugin: streamer


*** Streamer Plugin v2.5 by Incognito loaded ***

  Loaded.
 Loaded 4 plugins.


Started server on port: 7777, with maxplayers: 32 lanmode is OFF.


Filterscripts
---------------
  Loading filterscript 'colourtest.amx'...
Colour Filterscript Loaded
  Loading filterscript 'npcs.amx'...
 NPC Filterscript Loaded.
  Loaded 2 filterscripts.


 =======================================
 |                                     |
 |        YSI version 1.03.0011        |
 |        By Alex "******" Cole        |
 |                                     |
 |  Checking the latest YSI version..  |
 |                                     |
 =======================================

Number of vehicle models: 0
Incoming connection: 127.0.0.1:51507
[npc:join] Test_Test has joined the server (0:127.0.0.1)
NPC: Connection from 127.0.0.1 is allowed.
[npc:part] Test_Test has left the server (0:0)

 =======================================
 |                                     |
 |   Error: Could not connect to YSI   |
 |  update server (response was 006).  |
 |                                     |
 =======================================
Would the server being Locked, change anything?

EDIT:
Nevermind, by returning that would close the dialog correct? therefore the server would be closing the bots connection to the server...?

and by returning i mean 'if(IsPlayerNPC(playerid)) return 1;'
Reply
#4

Just don't show any dialog to the NPC.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)