SA-MP Forums Archive
INVALID_PLAYER_ID - 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)
+--- Thread: INVALID_PLAYER_ID (/showthread.php?tid=674181)



INVALID_PLAYER_ID - Mahzen - 14.04.2020

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;
}



Re: INVALID_PLAYER_ID - Runn3R - 14.04.2020

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.


Re: INVALID_PLAYER_ID - Mahzen - 14.04.2020

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


Re: INVALID_PLAYER_ID - jasperschellekens - 14.04.2020

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.


Re: INVALID_PLAYER_ID - Mahzen - 14.04.2020

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


Re: INVALID_PLAYER_ID - jasperschellekens - 14.04.2020

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;




Re: INVALID_PLAYER_ID - Mahzen - 14.04.2020

I will try this. Thank you


Re: INVALID_PLAYER_ID - Calisthenics - 15.04.2020

Update sscanf to 2.8.3


Re: INVALID_PLAYER_ID - DmitriyShift - 15.04.2020

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;




Re: INVALID_PLAYER_ID - Mahzen - 19.04.2020

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