Getplayerid
#1

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.
Reply
#2

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

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;

Reply
#4

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 !
Reply
#5

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.
Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)