Display a player ID from his name from a command
#1

Hello, this is m'y fiesta post !

I Am stripping a GM and i want to make a command witch work like that :

- A player type /id <the name Of the player/part le name>
- The server returns "player not found if he is not
- If he is found, it returns "<Name of the player>'s ID is <ID>".

Is it possible ?

Thank you

Ps: I looked topics about GetPlayerID but it don't work for me ...
Reply
#2

Check if the ID is online if he is just simply
pawn Код:
format( string, sizeof( string ), "The ID that matches %s is %d.", GetName( id ), id );
SendClientMessage( playerid, WHITE, string );
EDIT: If you doesn't have "GetName" or something like that:
pawn Код:
stock GetName( playerid )
{
    new Name[ MAX_PLAYER_NAME ];
   
    if( IsPlayerConnected( playerid ) )
    {
        GetPlayerName( playerid, Name, sizeof( Name ) );
    }
    else
    {
        Name = "Disconnected/Nothing";
    }
   
    return Name;
}
Reply
#3

I tryed this, but i don't know how to use it as a command ! The compilation doesn't work ='(

Help please =)
Reply
#4

It now works !

I maked this command

Код:
dcmd_id(playerid, params[])
{
    new id, playername[24] ,string[256];
	if (sscanf(params, "s", GetName(id), playername))
	return SendClientMessage(playerid, 0xFF0000AA, "Utilisation: \"/id <nom du joueur>\"");
	else if (!IsPlayerConnected(id))
	return SendClientMessage(playerid, 0xFF0000AA, "Joueur non trouve");
	else
	{
	format(string, sizeof(string), "The ID that matches %s is %d.", GetName(id), id);
	SendClientMessage(playerid, 0xFFFF00AA, string);
	}
	return 1;
}
With this stock :

Код HTML:
stock GetName(playerid)
{
    new Name[MAX_PLAYER_NAME];

    if(IsPlayerConnected(playerid))
    {
        GetPlayerName(playerid, Name, sizeof(Name));
    }
    else
    {
        Name = "Disconnected/Nothing";
    }

    return Name;
}
And now, when I type /id a player name, it returns his ID !!


Thank you ! =)
Reply
#5

If you are using sscanf there is a "u" specifier which does exactly what you want already, you don\'t need to write your own based on "s". Plus, "u" takes either a name OR an ID.
Reply
#6

It don't work ... It only gives the first player ID ... How can I give the player that i give the name's ID ?
Reply
#7

Using zcmd;
pawn Код:
CMD:id( playerid, params[ ] )
{
    if(isnull(params)) return
    SendClientMessage(playerid, -1, "Usage: /id <the name Of the player/part le name> ");
    new found, string[128], playername[MAX_PLAYER_NAME];
    format(string,sizeof(string),"Searched for: \"%s\"",params);
    SendClientMessage(playerid, -1,string);
    for(new i=0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            GetPlayerName(i, playername, MAX_PLAYER_NAME);
            new namelen = strlen(playername);
            new bool:searched=false;
            for(new pos=0; pos <= namelen; pos++)
            {
                if(searched != true)
                {
                    if(strfind(playername,params,true) == pos)
                    {
                        found++;
                        format(string,sizeof(string),"%d. %s's ID is: (%d)",found,playername,i);
                        SendClientMessage(playerid, -1 ,string);
                        searched = true;
                    }
                }
            }
        }
    }
    if(found == 0)
    SendClientMessage(playerid, -1, "player not found");
    return 1;
}
Reply
#8

Quote:
Originally Posted by ludesert
View Post
It don\'t work ... It only gives the first player ID ... How can I give the player that i give the name\'s ID ?
Are you using the PAWN or plugin version of sscanf (I\'m guessing the PAWN version given that you didn\'t include an array size after "s"). Anyway, if you\'re not already, use the plugin version.


Russell_: zcmd has nothing to do with the question.
Reply
#9

I don't know ... ^^

But i tryed to use "u" in sscanaf, but it gives me ID 0 for all players ! And even for players who are not connected !
Reply
#10

Then you need to find out - I can\'t solve, or even attempt to solve your issue without that information. Or technically I can, but the first step is getting that information.
Reply
#11

How can i find that ?
Reply
#12

How can I find that ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)