SA-MP Forums Archive
Command: /id [player name or part of name] - 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: Command: /id [player name or part of name] (/showthread.php?tid=403696)



Command: /id [player name or part of name] - JoelR - 31.12.2012

As the title says, the following command is supposed to show a list of players with the name containing what was typed.

EG: If I type in game: /id jam

It should appear as (If there are 3 people online with the letters jam in the name):

James Girvan - ID 1
Jamie Clark - ID 5
Chris Jameson - ID 24

But it doesn't.

pawn Код:
command(id, playerid, params[])
{
    new name[24], string[1024];
    if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, GREY, "Usage: /id [player name or part of name]");
    {
        format(string, sizeof(string), "%s\n%s - ID %d", string, RemoveUnderScore(GetPlayerIDFromName(name, 1)), GetPlayerIDFromName(name, 1));
        SendClientMessage(playerid, WHITE, string);
    }
    return 1;
}
If anyone can help, I'd be grateful.


Re: Command: /id [player name or part of name] - JaKe Elite - 31.12.2012

use u. instead of s.
u = playername/id.

pawn Код:
new id;
if(sscanf(params, "u", id)) return SendClientMessage(playerid, GREY, "Usage: /id [player name or part of name]");



Re: Command: /id [player name or part of name] - JoelR - 31.12.2012

That wouldn't find the players that are also containing the same name though?


Re: Command: /id [player name or part of name] - JaKe Elite - 31.12.2012

Actually.
I think it will find the players that are also containing the same name.

However.
Read the sscanf topic for more information.
https://sampforum.blast.hk/showthread.php?tid=120356


Re: Command: /id [player name or part of name] - Aldo. - 31.12.2012

Quote:
Originally Posted by Romel
Посмотреть сообщение
use u. instead of s.
u = playername/id.

pawn Код:
new id;
if(sscanf(params, "u", id)) return SendClientMessage(playerid, GREY, "Usage: /id [player name or part of name]");
No, what you posted is just wrong.

Here is an example on how it should be done OP
pawn Код:
CMD:id(playerid, params[]) {
    if(isnull(params)) {
        return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /id [player name]");
    }

    new
        szMessage[64],
        szPlayerName[MAX_PLAYER_NAME],
        iTargetID = strval(params);

    if(IsNumeric(params) && IsPlayerConnected(strval(params))) {
        format(szMessage, sizeof szMessage, "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", iTargetID, GetPlayerNameEx(iTargetID), PlayerInfo[iTargetID][pLevel], GetPlayerPing(iTargetID));
        return SendClientMessageEx(playerid, COLOR_WHITE, szMessage);
    }
    else if(strlen(params) < 3) {
        return SendClientMessageEx(playerid, COLOR_GREY, "Input at least 3 characters to search.");
    }
    else foreach(new i: Player) {
        GetPlayerName(i, szPlayerName, sizeof szPlayerName);
        if(strfind(szPlayerName, params, true) != -1) {
            format(szMessage, sizeof szMessage, "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", i, GetPlayerNameEx(i), PlayerInfo[i][pLevel], GetPlayerPing(i));
            SendClientMessageEx(playerid, COLOR_WHITE, szMessage);
        }
    }
    return 1;
}



Re: Command: /id [player name or part of name] - Konstantinos - 31.12.2012

pawn Код:
command(id, playerid, params[])
{
    new name[24];
    if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, GREY, "Usage: /id [player name or part of name]");
    format(string, sizeof(string), "%s\n%s - ID %d", string, RemoveUnderScore(GetPlayerID(name, 1)), GetPlayerID(name, 1));
    SendClientMessage(playerid, WHITE, string);
    return 1;
}
pawn Код:
stock GetPlayerID(const playername[], partofname=0) //By Jan "DracoBlue" Schќtze (edited by Gabriel "Larcius" Cordes) || Or ******, I don't remember.
{
    new i;
    new playername1[MAX_STRING];
    for (i=0;i<MAX_PLAYERS;i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i,playername1,sizeof(playername1));
            if (strcmp(playername1,playername,true)==0)
            {
                return i;
            }
        }
    }
    new correctsigns_userid=-1;
    new tmpuname[MAX_STRING];
    new hasmultiple=-1;
    if(partofname)
    {
        for (i=0;i<MAX_PLAYERS;i++)
        {
            if (IsPlayerConnected(i))
            {
                GetPlayerName(i,tmpuname,sizeof(tmpuname));
                if (strfind(tmpuname,partofname,true)==0)
                {
                    hasmultiple++;
                    correctsigns_userid=i;
                }
                if (hasmultiple>0)
                {
                    return -2;
                }
            }
        }
    }
    return correctsigns_userid;
}



Re: Command: /id [player name or part of name] - Threshold - 31.12.2012

Try this:
pawn Код:
CMD:id(playerid, params[])
{
    new name[MAX_PLAYER_NAME], string[1024];
    if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, GREY, "Usage: /id [player name/part of name]");  
    new count = 0;
    new playername[MAX_PLAYER_NAME];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            GetPlayerName(i, playername, MAX_PLAYER_NAME);
            if(strfind(playername, name, true) != -1)
            {
                if(count == 0)
                {
                    format(string,sizeof(string),"%s - ID %d",playername, i);
                    count++;
                    continue;
                }
                count++;
                format(string,sizeof(string),"%s\n%s - ID %d",string, playername, i);
            }
        }
    }
    if(count == 0) return SendClientMessage(playerid, WHITE, "No players were found.");
    SendClientMessage(playerid, WHITE, string);
    return 1;
}



Re: Command: /id [player name or part of name] - Vince - 31.12.2012

The new sscanf 2.8 has some new array sort of feature for player's names. Read up on that.