ID Command
#1

There is a problem with the /id command ,whenever i do /id [ID] it says No Players Found it only works when i do /id [Player Name] Can someone help me with it ?
pawn Код:
CMD:id(playerid, params[])
{
    new string[128], name[24];
    if(sscanf(params, "s[24]", name)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [Name/PartOfName]");
    else
    {
        new count;
        foreach(Player, i)
        {
            new pname[24];
            GetPlayerName(i, pname, sizeof(pname));
            if(strfind(pname, name, true) != -1)
            {
                format(string, sizeof(string), "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", i, GetPlayerNameEx(i),  PlayerInfo[i][pLevel], GetPlayerPing(i));
                SendClientMessageEx(playerid, COLOR_WHITE, string);
                count ++;
            }
        }
        if(count == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "  No players found.");
    }
    return 1;
}
Reply
#2

pawn Код:
CMD:id(playerid, params[])
{
    new string[128], name[24];
    if(sscanf(params, "u[24]", name)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [Name/PartOfName]");
    else
    {
        new count;
        foreach(Player, i)
        {
            new pname[24];
            GetPlayerName(i, pname, sizeof(pname));
            if(strfind(pname, name, true) != -1)
            {
                format(string, sizeof(string), "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", i, GetPlayerNameEx(i),  PlayerInfo[i][pLevel], GetPlayerPing(i));
                SendClientMessageEx(playerid, COLOR_WHITE, string);
                count ++;
            }
        }
        if(count == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "  No players found.");
    }
    return 1;
}
Change "s[24]" to "u[24]". U is for names/id's.
Reply
#3

it should be u instead of s
so it will be:
pawn Код:
CMD:id(playerid, params[])
{
    new string[128], name[24];
    if(sscanf(params, "u[24]", name)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [Name/PartOfName]");
    else
    {
        new count;
        foreach(Player, i)
        {
            new pname[24];
            GetPlayerName(i, pname, sizeof(pname));
            if(strfind(pname, name, true) != -1)
            {
                format(string, sizeof(string), "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", i, GetPlayerNameEx(i),  PlayerInfo[i][pLevel], GetPlayerPing(i));
                SendClientMessageEx(playerid, COLOR_WHITE, string);
                count ++;
            }
        }
        if(count == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "  No players found.");
    }
    return 1;
}
Reply
#4

If you see right here,

[CODE]CMD:id(playerid, params[])
{
new string[128], name[24];
if(sscanf(params, "u[24]", name)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [Name/PartOfName]"); // < Right there it states, Name/PartOfName, which is their name, not there ID so to fix it to do ID's it would be like this if(sscanf(params, "u[24]", name)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [ID/PartOfName]"); \\
else
{
new count;
foreach(Player, i)
{
new pname[24];
GetPlayerName(i, pname, sizeof(pname));
if(strfind(pname, name, true) != -1)
{
format(string, sizeof(string), "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", i, GetPlayerNameEx(i), PlayerInfo[i][pLevel], GetPlayerPing(i));
SendClientMessageEx(playerid, COLOR_WHITE, string);
count ++;
}
}
if(count == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, " No players found.");
}
return 1;
}[CODE]
Reply
#5

we already answered him and solved it
Reply
#6

It is best if you don't use array cells for the 'u' delimiter unless you've want to make some sort of a listing or multiple ID's operator - u[24] will store all the results (up to 24) in the array cells, so for example if you do /id "Lo" and there are three players containing "Lo" in their name it will store them at name[0], name[1] & name [2] respectively.

While essentially that's what you're trying to do, the method you're using is completely unefficient compared to what could be done:

from the sscanf thread

Quote:

The "u", "q", and "r" specifiers search for a user by name or ID. The method of this search has changed in the latest versions of "sscanf".

Additionally "U", "Q", and "R" used to take a name or ID as their default value - this has since been changed to JUST a number, and sscanf will not try and determine if this number is online:

Users can now optionally return an ARRAY of users instead of just one. This array is just a list of matched IDs, followed by "INVALID_PLAYER_ID". Given the following players:

Код:
0) ******
1) [CLAN]******
2) Jake
3) Alex
4) Hass
This code:

Код:
new ids[3], i;
if (sscanf("Le", "?<MATCH_NAME_PARTIAL=1>u[3]", ids)) printf("Error in input");
for (i = 0; ids[i] != INVALID_PLAYER_ID; ++i)
{
    if (ids[i] == cellmin)
    {
        printf("Too many matches");
        break;
    }
    printf("id = %d", ids[i]);
}
if (i == 0) printf("No matching players found.");
Will output:

Код:
id = 0
id = 1
Too many matches
Searching "Les" instead will give:

Код:
id = 0
id = 1
And searching without "MATCH_NAME_PARTIAL" will give:

Код:
No matching players found.
Basically, if an array of size "N" is passed, this code will return the first N-1 results. If there are less than "N" players whose name matches the given name then that many players will be returned and the next slot will be "INVALID_PLAYER_ID" to indicate the end of the list. On the other hand if there are MORE than "N - 1" players whose name matches the given pattern, then the last slot will be "cellmin" to indicate this fact.

When combined with "U" and returning the default, the first slot is always exactly the default value (even if that's not a valid connected player) and the next slot is always "INVALID_PLAYER_ID".

Note also that user arrays can't be combined with normal arrays or enums, but normal single-return user specifiers still can be.

Reply
#7

Quote:
Originally Posted by XK
Посмотреть сообщение
it should be u instead of s
so it will be:
pawn Код:
CMD:id(playerid, params[])
{
    new string[128], name[24];
    if(sscanf(params, "u[24]", name)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /id [Name/PartOfName]");
    else
    {
        new count;
        foreach(Player, i)
        {
            new pname[24];
            GetPlayerName(i, pname, sizeof(pname));
            if(strfind(pname, name, true) != -1)
            {
                format(string, sizeof(string), "(ID: %d) - (Name: %s) - (Level: %d) - (Ping: %d)", i, GetPlayerNameEx(i),  PlayerInfo[i][pLevel], GetPlayerPing(i));
                SendClientMessageEx(playerid, COLOR_WHITE, string);
                count ++;
            }
        }
        if(count == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "  No players found.");
    }
    return 1;
}
Now it says "No Players Found" if i did /id [ID] or /id [Player Name]
Reply
#8

Bump ?
Reply
#9

try this.

pawn Код:
COMMAND:id(playerid, params[])
{
    new targetid[128],targetid2,string[128],giveplayer[MAX_PLAYER_NAME];
    if(sscanf(params, "s[128]", targetid)) SendClientMessage(playerid, COLOR_GREY, "USAGE: /id {FFFFFF}[playerid/PartOfName]");
    else
    {
        targetid2 = ReturnUser(targetid);
        if(IsPlayerConnected(targetid2))
        {
            format(giveplayer, sizeof(giveplayer), "%s", PlayerName(targetid2));
            GiveNameSpace(giveplayer);
            format(string, sizeof(string), "ID: (%d) %s Ping: %d",targetid2,GetPlayerPing(targetid2));
            SendClientMessage(playerid, COLOR_GREY, string);
        }
        else SendClientMessage(playerid, COLOR_GREY, "User was not found !");
    }
    return 1;
}

IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21)
    {
        if (text[pos] == 0) return INVALID_PLAYER_ID;
        pos++;
    }
    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos]))
    {
        userid = strval(text[pos]);
        if (userid >=0 && userid < MAX_PLAYERS)
        {
            if(!IsPlayerConnected(userid)) userid = INVALID_PLAYER_ID;
            else return userid;
        }
    }
    new len = strlen(text[pos]), count = 0, name[MAX_PLAYER_NAME];
    foreach (Player,i)
    {
        GetPlayerName(i, name, sizeof (name));
        if (strcmp(name, text[pos], true, len) == 0)
        {
            if (len == strlen(name)) return i;
            else
            {
                count++;
                userid = i;
            }
        }
    }
    if (count != 1)
    {
        if (playerid != INVALID_PLAYER_ID)
        {
            if (count) SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
            else SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
        }
        userid = INVALID_PLAYER_ID;
    }
    return userid;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)