INVALID_PLAYER_ID
#1

Sometimes I get the error that the player was not found even though the player was in the game. It does this in all commands.

Command is running when the player logs in and out

Please Help

Code:
CMD:gotoplayer(playerid, params[])
{
	new ID, string[128];

    if(sscanf(params, "u", ID))
		return errormessage(playerid,"/gotoplayer -ID-");

	if(ID == INVALID_PLAYER_ID)
	    return errormessage(playerid,"No players found");

        new Float:x, Float:y, Float:z;
	GetPlayerPos(ID, x, y, z);

	SetPlayerPos(playerid, x + 2, y, z);
	
	SendClientMessage(playerid, COLOR_ADMIN, "Teleported");
	return 1;
}
Reply
#2

You should check samp wiki as i can see that you are pretty new to this.


First off you didn't get the position of the other player and second of INVALID_PLAYER_ID is 65535 and there is no way that the ID can be that unless the player is not in-game.
Reply
#3

There is GetPlayerPos but I deleted it so that it is not a long issue. It also gives this error in all commands.
Reply
#4

You can also do it like this:

PHP Code:
CMD:gotoplayer(playeridparams[])
{
    new 
IDstring[128];
    if(
sscanf(params"u"ID))
        return 
errormessage(playerid,"/gotoplayer -ID-");
    if(!
IsPlayerConnected(ID))
        return 
errormessage(playerid,"No players found");
    new 
FloatPos[3];
    
GetPlayerPos(IDPos[0], Pos[1], Pos[2]);
    
SetPlayerPos(playeridPos[0] + 2Pos[1], Pos[2]);
    
    
SendClientMessage(playeridCOLOR_ADMIN"Teleported");
    return 
1;

Like Runn3r said, check the wiki.
Reply
#5

If (! IsPlayerConnected (ID)) I also tried this command but it didn't work
Reply
#6

Then you should check if they are spawned I think.


PHP Code:
public OnPlayerSpawn(playerid)
{
    if(
GetPVarInt(playerid"is_connected")==0SetPVarInt(playerid"is_connected"1); // set the pvar to 1 for the check later
    
return 1;
}

IsPlayerConnectedEx(playerid)
{
    if (
IsPlayerConnected(playerid)&&GetPVarInt(playerid"is_connected")==1&&playerid!=INVALID_PLAYER_ID) return 1;
    return 
0;
}

CMD:gotoplayer(playeridparams[])
{
    new 
IDstring[128];

    if(
sscanf(params"u"ID))
        return 
errormessage(playerid,"/gotoplayer -ID-");

    if(!
IsPlayerConnectedEx(ID))
        return 
errormessage(playerid,"No players found");

    new 
FloatPos[3];
    
GetPlayerPos(IDPos[0], Pos[1], Pos[2]);
    
SetPlayerPos(playeridPos[0] + 2Pos[1], Pos[2]);
    
    
SendClientMessage(playeridCOLOR_ADMIN"Teleported");
    return 
1;

Reply
#7

I will try this. Thank you
Reply
#8

Update sscanf to 2.8.3
Reply
#9

Quote:
Originally Posted by Mahzen
View Post
Sometimes I get the error that the player was not found even though the player was in the game. It does this in all commands.

Command is running when the player logs in and out

Please Help

Code:
CMD:gotoplayer(playerid, params[])
{
	new ID, string[128];

    if(sscanf(params, "u", ID))
		return errormessage(playerid,"/gotoplayer -ID-");

	if(ID == INVALID_PLAYER_ID)
	    return errormessage(playerid,"No players found");

        new Float:x, Float:y, Float:z;
	GetPlayerPos(ID, x, y, z);

	SetPlayerPos(playerid, x + 2, y, z);
	
	SendClientMessage(playerid, COLOR_ADMIN, "Teleported");
	return 1;
}


PHP Code:
CMD:gotoplayer(playeridparams[])
{
    new 
ID strval(params);
    if(
ID == INVALID_PLAYER_ID)) return errormessage(playerid,"/gotoplayer -ID-");
    if(!
IsPlayerConnected(ID)) return errormessage(playerid,"No players found");
    new 
FloatPos[3];
    
GetPlayerPos(IDPos[0], Pos[1], Pos[2]);
    
SetPlayerPos(playeridPos[0] + 2Pos[1], Pos[2]);
    
SendClientMessage(playeridCOLOR_ADMIN"Teleported");
    return 
true;

Reply
#10

Quote:
Originally Posted by Calisthenics
View Post
Update sscanf to 2.8.3
I updated but still get the same error
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)