NPC join then Leave D: why? -
Mzake - 01.09.2014
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!!!
Re: NPC join then Leave D: why? -
meitaredri - 01.09.2014
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.
Re: NPC join then Leave D: why? -
Beckett - 01.09.2014
Do you have a registeration system? if yes then let the NPC bypass it.
Re: NPC join then Leave D: why? -
M0HAMMAD - 01.09.2014
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
Re: NPC join then Leave D: why? -
Mzake - 02.09.2014
sorry for being offline... anyway still same and i unloaded Admin system (registeration) i have no anti-cheat and still leaving!!! D:
Re: NPC join then Leave D: why? -
Dotayuri - 02.09.2014
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?
Re: NPC join then Leave D: why? -
Mzake - 02.09.2014
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 :/
Re: NPC join then Leave D: why? -
Rifa4life - 02.09.2014
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;
}
Re: NPC join then Leave D: why? -
meitaredri - 02.09.2014
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 NPC. You can add...
pawn Code:
if(IsPlayerNPC(playerid)) return 1;
... as the first line of any callbacks that bots will use, e.g. OnPlayerRequestClass or OnPlayerRequestSpawn. For an efficient, simple way of excluding NPCs from loops, check 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.
Re: NPC join then Leave D: why? -
Clad - 02.09.2014
Код:
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.