NPC join then Leave D: why?
#1

Subject say everything
Server log :
Код:
[13:41:49] [npc:join] Attack_NPC has joined the server (0:127.0.0.1)
[13:42:01] Incoming connection: 127.0.0.1:54463
[13:42:05] [npc:part] Attack_NPC has left the server (0:0)
[13:42:11] Incoming connection: 127.0.0.1:54464
Why the NPC join then he just leave...
NPC script:
pawn Код:
#include <a_samp>
#include <attacking_npc>

#define FILTERSCRIPT

public OnFilterScriptInit()
{
    ConnectNPC("Attack_NPC", "1");
    return 0;
}

//We make sure that the NPC spawns before we make it an attacking NPC
public OnPlayerSpawn(playerid)
{
    if(IsPlayerNPC(playerid))
    {
      if(playerid == GetPlayerID("Attack_NPC")) SetTimer("AttackNPC", 5000, 0);
    }
    return 0;
}

forward AttackNPC();
public AttackNPC()
{
    CreateAttackingNPC("Attack_NPC", 1398.5673,1528.5996,10.8125);
    return 0;
}
HELP ME PLEASE!!!
Reply
#2

Hi , I know what is the problem , Public "OnPlayerRequestClass"
add this:
Код:
if(IsPlayerNPC(playerid)) return 1;
btw if you have anti cheat that kick high ping , add this line as well.

+ Rep if I helped.
Reply
#3

Do you have a registeration system? if yes then let the NPC bypass it.
Reply
#4

Check Your Anti Cheat And Put This On it :
pawn Код:
if(!IsPlayerNPC(playerid))
{
//Code
return 1;
}
Or If You Want know Why The NPC Leave ? 1.kick or ...
Use This :
pawn Код:
new aDisconnectNames[][16] = {
    {"Time Out"},
    {"Exit - /Q"},
    {"Kick"}
};
pawn Код:
// In the OnPlayerDisconnect :
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid,pname,sizeof(pname));
printf("%s(%d) Has Been Left The Server [%d]"pname,playerid,aDisconnectNames[reason]);
if Is kick check your anti cheat. i was have this problems some day .
OR
Put "if(IsPlayerNPC(playerid)) return 1;" In The OnPlayerRequestClass, OnPlayerConnect, OnPlayerRequestSpawn And In The
OnPlayerSpawn Where You Have Added The NPC Put this
pawn Код:
if(IsPlayerNPC(playerid))
{
 //NPC Code ...
return 1;
}
I Hope I Can Help You And Sorry for my bad english
Don't Forget +Rep
Reply
#5

sorry for being offline... anyway still same and i unloaded Admin system (registeration) i have no anti-cheat and still leaving!!! D:
Reply
#6

Quote:
Originally Posted by Mzake
Посмотреть сообщение
sorry for being offline... anyway still same and i unloaded Admin system (registeration) i have no anti-cheat and still leaving!!! D:
Just to make sure, in your sever file. You do have max NPC set to anything higher then 0 right?
Reply
#7

Quote:
Originally Posted by Dotayuri
Посмотреть сообщение
Just to make sure, in your sever file. You do have max NPC set to anything higher then 0 right?
YES its 50 :/
Reply
#8

Quote:
Originally Posted by meitaredri
Посмотреть сообщение
Hi , I know what is the problem , Public "OnPlayerRequestClass"
add this:
Код:
if(IsPlayerNPC(playerid)) return 1;
First of all, that's not correct because you're not doing anything with the NPC, second of all, OnPlayerRequestClass is obviously not the only callback that's called upon when a player, or in this instance - an NPC joins the server.


What you have to do, is force the NPC to spawn because they can't press the spawn button / login / whatever, themselves. You have to make them do it. So modify your code under the relevant callback so it looks something like this:

pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    if(IsPlayerNPC(playerid))
    {
        SpawnPlayer(playerid);
    }
        return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    if(IsPlayerNPC(playerid))
    {
        SpawnPlayer(playerid);

    }
        return 1;
}
If that doesn't do it, then place the same code as above under OnPlayerConnect. Later on if you want to do anything with the bots, say for example, set their position or vw, you just code that under...

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(IsPlayerNPC(playerid))
    {
        //code
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by Rifa4life
Посмотреть сообщение
First of all, that's not correct because you're not doing anything with the NPC, second of all, OnPlayerRequestClass is obviously not the only callback that's called upon when a player, or in this instance - an NPC joins the server.


What you have to do, is force the NPC to spawn because they can't press the spawn button / login / whatever, themselves. You have to make them do it. So modify your code under the relevant callback so it looks something like this:

pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    if(IsPlayerNPC(playerid))
    {
        SpawnPlayer(playerid);
    }
        return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    if(IsPlayerNPC(playerid))
    {
        SpawnPlayer(playerid);

    }
        return 1;
}
If that doesn't do it, then place the same code as above under OnPlayerConnect. Later on if you want to do anything with the bots, say for example, set their position or vw, you just code that under...

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(IsPlayerNPC(playerid))
    {
        //code
    }
    return 1;
}
hahahha what....
dude if you don't know how to script don't help

PHP код:
Common problems
My NPC leaves my server after it joins
Your script is forcing the NPC to login
, or you have an anti-cheat ping kicker that is interfering with your NPCYou can add...
pawn Code:
if(
IsPlayerNPC(playerid)) return 1;
... as 
the first line of any callbacks that bots will use, e.gOnPlayerRequestClass or OnPlayerRequestSpawn. For an efficientsimple way of excluding NPCs from loopscheck out foreach by ******
Read it.
https://sampforum.blast.hk/showthread.php?tid=95034

OnPlayerRequestClass or OnPlayerRequestSpawn

and don't say somting you don't know please.
Reply
#10

Код:
public OnPlayerConnect(playerid)
{
	if(IsPlayerNPC(playerid))
 	{
	    SpawnPlayer(playerid);
		return 1;
	}
Код:
public OnPlayerRequestClass(playerid, classid)
{
   if(IsPlayerNPC(playerid))
	{
	    SpawnPlayer(playerid);
		return 1;
	}
You don't need to put anything about the NPC in OnPlayerSpawn, Only if you want to check his name/put him in vehicle.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)