HELP! Dialog List Problem! -
SuperChock - 19.01.2012
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.
Re: HELP! Dialog List Problem! -
Tannz0rz - 19.01.2012
It'd more than likely be helpful if you'd post some code so people can provide assistance.
Re: HELP! Dialog List Problem! -
SuperChock - 19.01.2012
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");
Re: HELP! Dialog List Problem! -
Tannz0rz - 19.01.2012
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.
Re: HELP! Dialog List Problem! -
SuperChock - 19.01.2012
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?
Re: HELP! Dialog List Problem! -
viper_viper - 19.01.2012
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)
Re: HELP! Dialog List Problem! -
Tannz0rz - 19.01.2012
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.
Re: HELP! Dialog List Problem! -
FireCat - 19.01.2012
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?
Re: HELP! Dialog List Problem! -
Tannz0rz - 19.01.2012
Quote:
Originally Posted by FireCat
"m = 0x7FFFFFFF"
What's that for?
|
Код:
printf("%d", 0x7FFFFFFF);
Give it a try and find out.
Re: HELP! Dialog List Problem! -
FireCat - 19.01.2012
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?