SortDeepArray Sorting Wanted Players by wanted level
#1

Hello all,

I have a problem with sorting wanted players.
I am using this code:
pawn Код:
//Top of script
enum e_wanted_level_sort_data {E_WANTED_PLAYERID, E_WANTED_LEVEL};
new WantedLevel2[MAX_PLAYERS][e_wanted_level_sort_data];

//Command
WantedLevel2[0][E_WANTED_LEVEL]=66;
    WantedLevel2[1][E_WANTED_LEVEL]=22;
    WantedLevel2[2][E_WANTED_LEVEL]=33;
    WantedLevel2[3][E_WANTED_LEVEL]=11;
    WantedLevel2[4][E_WANTED_LEVEL]=35;
    SortDeepArray(WantedLevel2, E_WANTED_LEVEL);
    for (new i = 0; i < 5; i++) {
        printf("e_wanted_level_sort_data[%d] = {%d,%d}", i, WantedLevel2[i][E_WANTED_PLAYERID],WantedLevel2[i][E_WANTED_LEVEL]);
    }
And it returns in print:
pawn Код:
[19:40:08] e_wanted_level_sort_data[0] = {0,0}
[19:40:08] e_wanted_level_sort_data[1] = {0,0}
[19:40:08] e_wanted_level_sort_data[2] = {0,0}
[19:40:08] e_wanted_level_sort_data[3] = {0,0}
[19:40:08] e_wanted_level_sort_data[4] = {0,0}
What it should do is sorting the top 5 wanted players on order(66,35,33,22,11) with the returning playerid.
What i am doing wrong?

PS: I am using Slice his include:
https://sampforum.blast.hk/showthread.php?tid=343172

Admigo
Reply
#2

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
You're only printing the first 5 cells in that loop but the array is 500 cells big (or whatever MAX_PLAYERS is)

Run it with this loop:

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
and I think you'll understand what's going on!


Spoiler:

Since you sorted by the default sort (ascending) the list will go from the lowest value to the highest. Since you only set the first 5 cells, the rest will be 0 and thus be at the top when you sort it.

Try sorting the list descending and then the highest value will be in cell 0.
sorry men! i helped him on skype! your reply was too slow broski ;d
Reply
#3

It sorts in an ascending manner.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)