HELP! Dialog List Problem!
#1

Hello, I have a loop for create a list of online players. The list is created, example:

Код:
John (ID:1)
Mike (ID:5)
SuperChock (ID:9)
But the problem is that "listitem" (of OnPlayerDialogResponse) doesn't match the correct ID of each player. Example:

For John, the "listiten" returns 0, for Mike returns 1 and for me returns 2, but the correct ID are respectively 1, 5 and 9.

Can anyone help me?

Thanks and sorry from my bad English.
Reply
#2

It'd more than likely be helpful if you'd post some code so people can provide assistance.
Reply
#3

pawn Код:
new GroupSTr[2500],
       eX;
foreach(Player, PLAY)
{
    format(sTrinG, sizeof(sTrinG), "{FFFFFF}%s", pName(PLAY));
    if(eX)
    strcat(GroupSTr, "\n");
    strcat(GroupSTr, sTrinG);
    eX = 1;
}
ShowPlayerDialog(playerid, 853, 2, "Groups", GroupSTr, "Select", "Back");
Reply
#4

Quote:
Originally Posted by SuperChock
Посмотреть сообщение
pawn Код:
new GroupSTr[2500],
       eX;
foreach(Player, PLAY)
{
    format(sTrinG, sizeof(sTrinG), "{FFFFFF}%s", pName(PLAY));
    if(eX)
    strcat(GroupSTr, "\n");
    strcat(GroupSTr, sTrinG);
    eX = 1;
}
ShowPlayerDialog(playerid, 853, 2, "Groups", GroupSTr, "Select", "Back");
Even then it's relatively unreadable.

Try doing a simple
Код:
printf("%d", PLAY);"
test to see what exactly foreach is giving you.
Reply
#5

As I said, the loop with all the players connected is created normally. However, the order of players on the list doesn't match the respective IDs of the players. Do you understand?
Reply
#6

Dosent seem like much you can do, unless you have blank spaces if a player is not connected under a valid ID.

Example:
Viper(ID: 0)
None(ID: 1)
SuperChock(ID: 2)
Reply
#7

Now I do. As far as I'm concerned foreach isn't meant to return the users in any sorted order.

I've whipped up a quick sort function for you:
pawn Код:
sort(list[], const size=sizeof(list))
{
    new
        i, j, x,
        m,
        l[MAX_PLAYERS] = { -1, ... };

    while(j < size)
    {
        for(i = 0, m = 0x7FFFFFFF; i < size; ++i)
        {
            if(list[i] < m)
            {
                for(x = 0; x < size; ++x)
                {
                    if(l[x] == list[i])
                    {
                        goto next;
                    }
                }
               
                m = list[i];
            }
           
            next:
        }
       
        l[j++] = m;
    }
   
    for(i = 0; i < size; ++i)
    {
        if(l[i] != -1)
        {
            list[i] = l[i];
        }
    }
}
I may as well post this in the code snippets topic.

EDIT:
It doesn't account for doubles of any number in the list, but that shan't be a problem as there shouldn't be doubles of any player ids.
Reply
#8

Quote:
Originally Posted by Tannz0rz
Посмотреть сообщение
Now I do. As far as I'm concerned foreach isn't meant to return the users in any sorted order.

I've whipped up a quick sort function for you:
pawn Код:
sort(list[], const size=sizeof(list))
{
    new
        i, j, x,
        m,
        l[MAX_PLAYERS] = { -1, ... };

    while(j < size)
    {
        for(i = 0, m = 0x7FFFFFFF; i < size; ++i)
        {
            if(list[i] < m)
            {
                for(x = 0; x < size; ++x)
                {
                    if(l[x] == list[i])
                    {
                        goto next;
                    }
                }
               
                m = list[i];
            }
           
            next:
        }
       
        l[j++] = m;
    }
   
    for(i = 0; i < size; ++i)
    {
        if(l[i] != -1)
        {
            list[i] = l[i];
        }
    }
}
I may as well post this in the code snippets topic.
"m = 0x7FFFFFFF"
What's that for?
Reply
#9

Quote:
Originally Posted by FireCat
Посмотреть сообщение
"m = 0x7FFFFFFF"
What's that for?
Код:
printf("%d", 0x7FFFFFFF);
Give it a try and find out.
Reply
#10

Quote:
Originally Posted by Tannz0rz
Посмотреть сообщение
Код:
printf("%d", 0x7FFFFFFF);
Give it a try and find out.
So why on earth, are you checking if list[i] is < 2147483647?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)