SA-MP Forums Archive
GetPlayerID (Useful_Functions) - 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: GetPlayerID (Useful_Functions) (/showthread.php?tid=597800)



GetPlayerID (Useful_Functions) - Sheperc - 05.01.2016

Код:
CMD:mapp(playerid, params[])
{
	new Float:TY, Float:TX, Float:TZ, targetname[MAX_PLAYER_NAME], IDofName, string[128], realname[MAX_PLAYER_NAME];
	if(sscanf(params,"u",targetname)) return SendClientMessage(playerid,-1, "{FF0000}Usage: /mapp [player name]!");
	
 	IDofName = GetPlayerID(targetname, 1);
	{
	    new shit[128];
	    format(shit, sizeof(shit), "Returned ID: %d", IDofName);
		SendClientMessage(playerid, -1, shit);
	
	    if(!IsPlayerConnected(IDofName))
	    {
	        SendClientMessage(playerid, 0xFF0000FF, "Error: player is not connected.");
	    }
	    else
	    {
			GetPlayerPos(IDofName, TX, TY, TZ);
			GPSMarkeris[playerid] = SetPlayerMapIcon(playerid, 0, TX, TY, TZ, 0, 0xFF0000FF, 1);
			GetPlayerName(IDofName, realname, sizeof(realname));
			format(string, sizeof(string), "{3399FF}[GPS] {5167F0}%s {3399FF}last known location has been marked {FF0000}with a red marker", realname);
			SendClientMessage(playerid, COLOR_HIGHLIGHT, string);
		}
	}


	return 1;
}
Why does this command work when I type in the name or part of name of ID0 only? When I type in the name of ID1 then GetPlayerID returns the value -1. Anyone know a fix to this?


This stuff is to see what value is returned:
Код:
	    new shit[128];
	    format(shit, sizeof(shit), "Returned ID: %d", IDofName);
		SendClientMessage(playerid, -1, shit);



Re: GetPlayerID (Useful_Functions) - DRIFT_HUNTER - 05.01.2016

Use targetname, sscanf will handle that for you.


Re: GetPlayerID (Useful_Functions) - Gammix - 05.01.2016

pawn Код:
targetname[MAX_PLAYER_NAME]
targetname should be an integer type because sscanf returns the ID not name.


Re: GetPlayerID (Useful_Functions) - Sheperc - 05.01.2016

K thanks


Re: GetPlayerID (Useful_Functions) - DRIFT_HUNTER - 05.01.2016

Quote:
Originally Posted by Gammix
Посмотреть сообщение
pawn Код:
targetname[MAX_PLAYER_NAME]
targetname should be an integer type because sscanf returns the ID not name.
No targetname should be integer as sscanf will return ID of the player, not name.


Re: GetPlayerID (Useful_Functions) - Crayder - 05.01.2016

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
No targetname should be integer as sscanf will return ID of the player, not name.
No shit, that's exactly what he said... xD