/getid sscanf warnings.
#1

First of all, thank you for reading this.

Alright, so I have the following code:
pawn Код:
CMD:getid(playerid, params[])
{
    new bool:found = false;
    if(sscanf(params, "S[MAX_PLAYER_NAME]", aname)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: /id [PartOfPlayerName]");
    SendClientMessage(playerid, COLOR_LIGHTGREEN, "Possible options:");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            GetPlayerName(i, pname, sizeof(pname));
            for(new j = 0; j <= MAX_PLAYER_NAME; j++)
            {
                if(strfind(pname, aname, true, j))
                {
                    kreplace(pname, '_', ' ');
                    found = true;
                }
            }
            if(found == true)
            {
                format(str, sizeof(str), "%s - [ID: %d]", pname, i);
                SendClientMessage(playerid, COLOR_USAGE, str);
            }
        }
    }
    return 1;
}
I know it looks horrible, but it's just because I started playing with it since it wasn't working.

At the beginning it showed the ID and name of the chosen player only if I'd input the second letter in his name ( and more ofc ) But when I used the first one. ( e.g Mark - M ) it didn't show the name and ID.

Now after I played with it a bit, every logged in player doesn't matter what I input.

Any idea what I am doing wrong?

( Please don't tell me go to there and copy or whatever )

Thank you in advance.
Reply
#2

This might be useful: http://forum.sa-mp.com/showpost.php?...65&postcount=6
Reply
#3

Quote:
Originally Posted by Dwane
Посмотреть сообщение
Looks a bit smiliar to what I made in the first place, thank you I'll check it out.
Reply
#4

pawn Код:
new aname[MAX_PLAYER_NAME];
if(sscanf(params, "u", aname)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: /id [PartOfPlayerName]");
This should work. And use foreach for player loops, it's faster.
Reply
#5

pawn Код:
CMD:id(playerid, params[])
{
    new pID;
    new str[24];

    if(sscanf(params,"u", pID)) return SendClientMessage(playerid, -1, "/id [playerid/playername]");
    else if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, -1, "That player is not online.");
   
    format(str,sizeof(str), "{FFFFFF}[{6B6B6B}INFO:{FFFFFF}] ID: (%d) %s", pID, GetName(pID));
    SendClientMessage(playerid, -1, str);
    return 1;
}
pawn Код:
stock GetName(playerid)
{
    new pName[24];
    GetPlayerName(playerid, pName, sizeof(pName));
    return pName;
}
Reply
#6

If I'm not mistaken, this is my shot at it:

pawn Код:
CMD:getid(playerid, params[])
{
    new nametosearchfor[25];
    if(sscanf(params, "s[25]", nametosearchfor)) return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /getid [name]");
    new Count = 0;
    SendClientMessage(playerid, 0x00FF00FF, "Current Matches (Online Players):");
    foreach(Player, i)
    {
        if(strfind(GetName(i), nametosearchfor, true) != -1)
        {
            format(fstr, sizeof(fstr), "MATCH: %s(%d)", GetName(i), i);
            SendClientMessage(playerid, 0xFFFF00FF, fstr);
            Count++;
        }
    }
    if(Count == 0) return SendClientMessage(playerid, 0xFF0000FF, "There were no matches found.");
    return 1;
}

stock GetName(playerid)
{
    new name[24];
    GetPlayerName(playerid, name, 24);
    return name;
}
If I can remember correctly, sscanf doesn't support mid-name searches.

Example: Player searches for 'Angelu'.
'Angelus4Life' would return positive.
names such as '[PDS]Angelus' and 'IamAngelu' would return negative. Using strfind will help solve this error though.
Reply
#7

Quote:
Originally Posted by Chrillzen
Посмотреть сообщение
pawn Код:
CMD:id(playerid, params[])
{
    new pID;
    new str[24];

    if(sscanf(params,"u", pID)) return SendClientMessage(playerid, -1, "/id [playerid/playername]");
    else if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, -1, "That player is not online.");
   
    format(str,sizeof(str), "{FFFFFF}[{6B6B6B}INFO:{FFFFFF}] ID: (%d) %s", pID, GetName(pID));
    SendClientMessage(playerid, -1, str);
    return 1;
}
pawn Код:
stock GetName(playerid)
{
    new pName[24];
    GetPlayerName(playerid, pName, sizeof(pName));
    return pName;
}
Let's say you do "/getid Dw" and there are two players online. Dwane and Dwwane, it will send the "Dwane".
This will return the first name with this char, however I think Denying wants to be printed both of them.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)