Sorting bug
#1

Hello guys! I have a problem, when I type /territories to see all territories of the factions/gangs and if the factions/gangs like Ballas and Grove owns 0 territories it says:
Quote:

Ballas owns 0 territories
Ballas owns 0 territories

I mean 2 times that, instead of:
Quote:

Grove owns 0 territories
Ballas owns 0 territories

There is the code of sorting the territories:
PHP код:
cmd:Territories(playeridparams[])
{
    new 
FactionNamee[255], string2[256];
    
enum ENUM_GANG
    
{
        
E_TEAMNAME[32],
        
E_TERRITORIESWON
    
};
    new 
SIZE_ENUM_GANG[ENUM_GANG];
    new array[
MAX_FACTIONS][ENUM_GANG];
     for(new 
0MAX_FACTIONSi++)
    {
        
format(string2sizeof(string2), "/Factions/%d.dini.save"i);
        if(
dini_Exists(string2))
        {
            
FactionNamee dini_Get(string2,"FactionName");
        }
         
strcpy(array[i][E_TEAMNAME], FactionNameesizeof(SIZE_ENUM_GANG[E_TEAMNAME]));
        array[
i][E_TERRITORIESWON] = FactionInfo[i][tWons];
    }
    
SortDeepArray(array, E_TERRITORIESWON, .order SORT_DESC);
    new 
TerritoryString[2560];
     for(new 
0MAX_FACTIONSi++)
    {
        
format(string2sizeof(string2), "/Factions/%d.dini.save"i);
        if(!
dini_Exists(string2))
        {
            break;
        }
        
format(TerritoryStringsizeof(TerritoryString), "{%06x}%s%s owns %d territories.\n"COLOR_FACTIONS  >>> 8TerritoryString, array[i][E_TEAMNAME], array[i][E_TERRITORIESWON]);
    }
    
ShowPlayerDialog(playerid,29,DIALOG_STYLE_MSGBOX"{82FFFF}Territories:"TerritoryString"{FF0000}Close""");
    
SIZE_ENUM_GANG[E_TERRITORIESWON] = 0;
    return 
1;

EDITED: +1 REP if You help me
Reply
#2

PHP код:
new TerritoryString[2560];
format(TerritoryStringsizeof(TerritoryString), "{%06x}%s%s owns %d territories.\n"COLOR_FACTIONS  >>> 8TerritoryString, array[i][E_TEAMNAME], array[i][E_TERRITORIESWON]); 
You're formatting the string variable inside the loop, causing it to reset and eventually only contain the last value of whatever it is you're formatting inside the loop.

PHP код:
new 
    
territoryString[1024],
    
territoryStringTemp[128]
;
for(new 
0MAX_FACTIONSi++) { 
    
format(string2sizeof string2"/Factions/%d.dini.save"i); 
    if(!
dini_Exists(string2))
        break; 
    
    
format(territoryStringTempsizeof territoryStringTemp"{%06x}%s%s owns %d territories.\n"COLOR_FACTIONS  >>> 8TerritoryString, array[i][E_TEAMNAME], array[i][E_TERRITORIESWON]);
    
strcat(territoryStringterritoyStringTemp);

PHP код:
ShowPlayerDialog(playerid,29,DIALOG_STYLE_MSGBOX"{82FFFF}Territories:"territoryString"{FF0000}Close"""); 
Reply
#3

Quote:
Originally Posted by d1git
Посмотреть сообщение
PHP код:
new TerritoryString[2560];
format(TerritoryStringsizeof(TerritoryString), "{%06x}%s%s owns %d territories.\n"COLOR_FACTIONS  >>> 8TerritoryString, array[i][E_TEAMNAME], array[i][E_TERRITORIESWON]); 
You're formatting the string variable inside the loop, causing it to reset and eventually only contain the last value of whatever it is you're formatting inside the loop.

PHP код:
new 
    
territoryString[1024],
    
territoryStringTemp[128]
;
for(new 
0MAX_FACTIONSi++) { 
    
format(string2sizeof string2"/Factions/%d.dini.save"i); 
    if(!
dini_Exists(string2))
        break; 
    
    
format(territoryStringTempsizeof territoryStringTemp"{%06x}%s%s owns %d territories.\n"COLOR_FACTIONS  >>> 8TerritoryString, array[i][E_TEAMNAME], array[i][E_TERRITORIESWON]);
    
strcat(territoryStringterritoyStringTemp);

PHP код:
ShowPlayerDialog(playerid,29,DIALOG_STYLE_MSGBOX"{82FFFF}Territories:"territoryString"{FF0000}Close"""); 
Still the same problem!
Here is the output, when all gangs have no territories: https://imgur.com/a/fldFE
Here is the second one, when the gangs have 1,1 and 7 territories: https://imgur.com/a/JFAN4
Reply
#4

Start by debugging your code, check what "array" contains after the first loop, debug the entries that get put into the array in the first loop, do approximately the same for the second loop.

By the way, you're sorting the array by territories won, the second loop will mix up the ids;
Код:
Ballas = 0 [1 Win]
Grove = 1 [0 Wins]
White = 2 [3 Wins]
After the sorting, the array will look like this;
Код:
White = 2 [3 Wins]
Ballas = 0 [1 Win]
Grove = 1 [0 Wins]
The second loop loops in order, 0 to MAX_FACTIONS, you're getting the array entry data by order;
PHP код:
for(new 0MAX_FACTIONSi++) {
    array[
i][E_TEAMNAME], array[i][E_TERRITORIESWON]

Array Entry 1 contains "Ballas" but because you're looping in order, it actually contains "Grove" - this is something you should fix.
Reply
#5

Quote:
Originally Posted by d1git
Посмотреть сообщение
Start by debugging your code, check what "array" contains after the first loop, debug the entries that get put into the array in the first loop, do approximately the same for the second loop.

By the way, you're sorting the array by territories won, the second loop will mix up the ids;
Код:
Ballas = 0 [1 Win]
Grove = 1 [0 Wins]
White = 2 [3 Wins]
After the sorting, the array will look like this;
Код:
White = 2 [3 Wins]
Ballas = 0 [1 Win]
Grove = 1 [0 Wins]
The second loop loops in order, 0 to MAX_FACTIONS, you're getting the array entry data by order;
PHP код:
for(new 0MAX_FACTIONSi++) {
    array[
i][E_TEAMNAME], array[i][E_TERRITORIESWON]

Array Entry 1 contains "Ballas" but because you're looping in order, it actually contains "Grove" - this is something you should fix.
Sorry, but I didn't understand You, can you tell me what I have to do to remove this mix up and fix this?
Reply
#6

Any help ?
Reply
#7

Quote:
Originally Posted by Kraeror
Посмотреть сообщение
Any help ?
Is the command used to simply show how many territories a gang has?
Reply
#8

Quote:
Originally Posted by Andre02
Посмотреть сообщение
Is the command used to simply show how many territories a gang has?
Yes, but the territories are sorted in descending order!
Reply
#9

Anybody can help me with this problem?
Reply
#10

All fixed! I fixed it solo!
Thanks anyway!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)