SA-MP Forums Archive
Getplayerid - 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 (/showthread.php?tid=647374)



Getplayerid - Osamakurdi - 04.01.2018

I have This stock:
Код:
//==============================================================================
stock GetPlayerIdFromName(playername[])
{
  for(new i = 0; i <= MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      new playername2[MAX_PLAYER_NAME];
      GetPlayerName(i, playername2, sizeof(playername2));
      if(strcmp(playername2, playername, true, strlen(playername)) == 0)
      {
        return i;
      }
    }
  }
  return INVALID_PLAYER_ID;
}
and i have this cmd:
Код:
CMD:myid(playerid, params[])
{
	new str3[80], GPID, name[MAX_PLAYER_NAME];
	GPID=GetPlayerIdFromName(name);
	format(str3, sizeof(str3), "Your Id Is:%i", GPID);
	SCM(playerid, -1, str3);

}
There is no errors but when I type /myid from 2 accounts
both accounts give me id 0.. help please.


Re: Getplayerid - pollo97 - 04.01.2018

Well, you need to get the param.
You must put before GetPlayeridFromName this: sscanf(params("s[24]",name));


Re: Getplayerid - RogueDrifter - 04.01.2018

that's wrong, you don't understand the function osama, you need to do something like this:
new RDZ = GetPlayerIdFromName(''RogueDrifter'');
this will return the id of the player called RogueDrifter and save it in the variable called RDZ.
So your code should look like this:
PHP код:
CMD:myid(playeridparams[])
{
    new 
str3[80], GPIDname[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,name,sizeof(name));
    
GPID=GetPlayerIdFromName(name);
    
format(str3sizeof(str3), "Your Id Is:%i"GPID);
    
SCM(playerid, -1str3);
    return 
1;




Re: Getplayerid - Osamakurdi - 04.01.2018

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
that's wrong, you don't understand the function osama, you need to do something like this:
new RDZ = GetPlayerIdFromName(''RogueDrifter'');
this will return the id of the player called RogueDrifter and save it in the variable called RDZ.
So your code should look like this:
PHP код:
CMD:myid(playeridparams[])
{
    new 
str3[80], GPIDname[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,name,sizeof(name));
    
GPID=GetPlayerIdFromName(name);
    
format(str3sizeof(str3), "Your Id Is:%i"GPID);
    
SCM(playerid, -1str3);
    return 
1;

Thanks !


Re: Getplayerid - SyS - 04.01.2018

zcmd passes playerid of the user executed the command as a parameter there is no need to use those functions unless you are looking for id of any other player.


Re: Getplayerid - Infra - 04.01.2018

pawn Код:
stock GetPlayerID(pName[])
{
    new playerid = INVALID_PLAYER_ID;
    sscanf(pName,"u",playerid);
    return playerid;
}
FTFY



If you are using it for a /myid command why are you not doing this:

pawn Код:
CMD:myid(playerid, params[])
{
        new string[32];
    format(string, sizeof(string), "Your ID is: %d", playerid);
    SendClientMessage(playerid, -1, string);
        return true;
}
The function itself (for usage in commands) is quite useless as you can simply do it like this (obviously requires sscanf):

pawn Код:
CMD:id(playerid, params[])
{
        new target;
        if (sscanf(params, "u", target)) return SendClientMessage(playerid, -1, "USAGE: /id [player]");
        if (!IsPlayerConnected(target)) return SendClientMessage(playerid, -1, "ERROR: The player is not online.");
        new string[64], pName[MAX_PLAYER_NAME];
        GetPlayerName(target, pName, sizeof(pName));
        format(string, sizeof(string), "%s's ID is %d", pName, target);
        SendClientMessage(playerid, -1, string);
        return true;
}