No I don't understand.
You are looping a sorting function which is illogical.
checkChance() means nothing to me.
You can't supply a sorting function with an array that is related to one player. The whole point is that it is sorting all players. I think what you want to do is to send JUST "arKills", which is basically "2". and then use that as an offset in your internal code.
What you are doing now:
PlayerData[id][arKills] will return an integer basically that points to another integer which is NOT an array.
You then tell the code it's an array, and since it's the last entry in the enumeration you will get an index out of bounds as soon as "elem1" or "elem2" in combination with the previously set player offset "i" + arArray >= the size of your enumeration array.
What you want is the code that I wrote but I assume with more calculations inside. There's nothing that SortCustom1D can't sort, that's the point of SortCustom. You send a list of whatever you want sorted. You decide in the public function what criteria you want to be met and it does exactly that. It will return to you the array you sent it, sorted with the criteria you decided.
If you want to combine the three you first have to decide which of the three is most important. For example "shoots" which I assume is "shots" may be 10000 but kills and items bought are probably more important.
So either you select an order:
if (
items of player 1 > items of player 2
||
kills of player 1 > kills of player 2
||
shots of player 1 > shots of player 2
)
return -1
Or you create some kind of calculation to balance them out to a kind of score (in this case 1 item is worth 2 kills, 1000 shots is worth 1 kill):
if (
items of player 1 * 2 + kills of player 1 + shots of player 1 / 1000
>
items of player 2 * 2 + kills of player 2 + shots of player 2 / 1000
)
return -1
Then you apply it:
Code:
GetTop()
{
new Players[32], iPlayersnum;
get_players(Players, iPlayersnum)
SortCustom1D(Players, iPlayersnum, "SortCustom")
return Players[0]
}
public SortCustom(elem1, elem2) {
if ( PlayerData[elem1][arItemsBought] * 2 + PlayerData[elem1][arKills] + PlayerData[elem1][arShoots] / 1000 > PlayerData[elem2][arItemsBought] * 2 + PlayerData[elem2][arKills] + PlayerData[elem2][arShoots] / 1000 )
return -1
else if ( PlayerData[elem1][arItemsBought] * 2 + PlayerData[elem1][arKills] + PlayerData[elem1][arShoots] / 1000 < PlayerData[elem2][arItemsBought] * 2 + PlayerData[elem2][arKills] + PlayerData[elem2][arShoots] / 1000 )
return 1
return 0
}
I might have misunderstood though. Maybe this is what you want:
Code:
GetTop(arItemsBought)
GetTop(PlayerDatas:arOffset)
{
new Players[32], iPlayersnum, data[1];
data[0] = any:arOffset;
get_players(Players, iPlayersnum)
SortCustom1D(Players, iPlayersnum, "SortCustom", data, 1);
return Players[0]
}
public SortCustom(elem1, elem2, array[], data[], datasize) {
new PlayerDatas:arOffset;
if ( ! datasize )
arOffset = PlayerDatas:data[0];
if ( PlayerData[elem1][arOffset] > PlayerData[elem2][arOffset] )
return -1
else if ( PlayerData[elem1][arOffset] < PlayerData[elem2][arOffset] )
return 1
return 0
}
Creating a custom sorting function is not as easy as looping players once. Google "Bubble Sort" to find some basic code if you want to create your own function. I would stick with SortCustom1D.
__________________