sscanf partial name check
#1

Hey guys, I'm trying to make it so that in a command, sscanf(updated to the latest version), besides checking for multiple occurances, to display an additional informative message.
So i've got this:

pawn Код:
if(sscanf(params, "?<CELLMIN_ON_MATCHES=1>r", id)) return SendClientMessage(playerid, -1, "Wrong syntax!");
if (id == cellmin)
{
    return SendClientMessage(playerid, -1, "There are more than 1 player with that part of name in it!");
}
This is what I've done so far. What I want to do as well, is to make the command show in the chat the name of the players which sscanf met the part of text in. Something like:

Input:
pawn Код:
/<command> Pot
Chat output:
pawn Код:
There are more than 1 player with that part of text in their name! Please use an ID:
1. [TAG]Potato (ID 1)
2. Potato (ID 2)
3. ILovePot (ID 3)
How would it be possible to do that?
Thanks in advance.
Reply
#2

https://github.com/Y-Less/sscanf/wiki/Users#user-lists
Reply
#3

So in my case, what would the size of the array be? 2?


Later edit:

Let's say I have the following command:
pawn Код:
COMMAND:goto(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new plo, string[150];
        if (sscanf(params, "r", plo))
        {
            SendClientMessage(playerid, COLOR_GRAD2, "Usage: /goto <player>");
            return 1;
        }
        new Float:plocx,Float:plocy,Float:plocz;
        if (IsPlayerConnected(plo))
        {
            if(plo != INVALID_PLAYER_ID)
            {
                if (PlayerInfo[playerid][pAdmin] >= 1)
                                {
                    GetPlayerPos(plo, plocx, plocy, plocz);
                    SetPlayerInterior(playerid, GetPlayerInterior(plo));
                    SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(plo));
                                        SetPlayerPos(playerid, plocx, plocy, plocz);
                }
                else
                {
                    SendClientMessage(playerid, -1, "You're not an admin!");
                }
            }
        }
        else
        {
            SendClientMessage(playerid, -1, "That's player is NOT connected!");
        }
    }
    return 1;
}
In order to convert it for partial name matches, should I replace plo (like in here: "GetPlayerPos(plo, plocx, plocy, plocz);") with plo[0]?


Update:

I've done this:

pawn Код:
COMMAND:goto(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new plo[2], string[150];
        if (sscanf(params, "r[2]", plo))
        {
            SendClientMessage(playerid, COLOR_GRAD2, "Usage: /goto <player>");
            return 1;
        }
                if(!CheckMultipleNames(playerid, plo)) return 1;
        new Float:plocx,Float:plocy,Float:plocz;
        if (IsPlayerConnected(plo[0]))
        {
            if(plo[0] != INVALID_PLAYER_ID)
            {
                if (PlayerInfo[playerid][pAdmin] >= 1)
                                {
                    GetPlayerPos(plo[0], plocx, plocy, plocz);
                    SetPlayerInterior(playerid, GetPlayerInterior(plo[0]));
                    SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(plo[0]));
                                        SetPlayerPos(playerid, plocx, plocy, plocz);
                }
                else
                {
                    SendClientMessage(playerid, -1, "You're not an admin!");
                }
            }
        }
        else
        {
            SendClientMessage(playerid, -1, "That's player is NOT connected!");
        }
    }
    return 1;

// where:

CheckMultipleNames(playerid, array[])
{
    new strfound[180], yesno, foundplayer, name[MAX_PLAYER_NAME];
    for(new i = 0; array[i] != INVALID_PLAYER_ID; i++)
    {
        GetPlayerName(array[i], name, sizeof(name));

        if (array[i] == cellmin)
        {
            if(yesno == 0)
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "(!) Multiple players have been found matching that name. Use one of the IDs:");
                format(strfound, sizeof(strfound), "%d. %s [ID %d]", yesno+1, GetPlayerNameEx(foundplayer), foundplayer);
                SendClientMessage(playerid, COLOR_LIGHTRED, strfound);
            }
            yesno ++;
            format(strfound, sizeof(strfound), "%d. %s [ID %d]", yesno+1, name, array[i]);
            SendClientMessage(playerid, COLOR_LIGHTRED, strfound);
        }
        foundplayer = array[i];
    }
    if(yesno > 0) return 0;
    return 1;
}
The output is this:
pawn Код:
(!) Multiple players have been found matching that name. Use one of the IDs:
1. [TAG]Potato (ID 1) // first name, displayed correctly
2. [TAG]Potato (ID --) // ID '--', i don't know why, and it displays the same name as the first player (i don't know why) - the second player should be just 'Potato'
SERVER: Unknown command.
What's wrong?
Reply
#4

Bump! (24 hours passed)
Reply
#5

Fixed. Thanks ******.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)