04.06.2012, 17:26
Damn that nice i will use it in future.
Comparator:CompareDistanceToFinish(left[E_RACE_DATA], right[E_RACE_DATA]) {
// Returning negative means "left goes above"
// Positive means "left goes below"
// floatcmp returns -1 if right > left, 0 if equal, and 1 if left > right
return floatcmp(left[DistanceToFinish], right[DistanceToFinish]);
}
new sorted_racers[MAX_PLAYERS];
SortArrayUsingComparator(gPlayerRaceData, CompareDistanceToFinish) => sorted_racers;
for (new i = 0; i < sizeof(sorted_racers); i++) {
new playerid = sorted_racers[i];
if (!IsPlayerConnected(playerid))
continue;
// do stuff with "playerid"
}
new sorted_racers[MAX_PLAYERS];
SortArrayUsingComparator(gPlayerRaceData, CompareDistanceToFinish, SORT_IS_PLAYERS) => sorted_racers;
for (new i = 0; i < sizeof(sorted_racers); i++) {
new playerid = sorted_racers[i];
// All valid player IDs are at the start of the array, so the first invalid one means the rest will be, too.
if (playerid == INVALID_PLAYER_ID)
break;
// do stuff with "playerid"
}
enum E_ADMIN_DATA
{
admin_Name[MAX_PLAYER_NAME],
admin_Level
}
new
gAdminData[MAX_ADMIN][E_ADMIN_DATA];
SortDeepArray(gAdminData, admin_Level, .order = SORT_DESC);
warning 229: index tag mismatch (symbol "gAdminData") warning 213: tag mismatch warning 213: tag mismatch
#include <a_samp>
#include <md-sort>
enum some_enum
{
string[32],
integer
}
new gAdminData[1][some_enum];
main()
{
SortDeepArray(gAdminData, integer, .order = SORT_DESC);
}
#include <a_samp>
#include <md-sort>
enum SOME_ENUM
{
string[32],
integer
}
new gAdminData[1][SOME_ENUM];
main()
{
SortDeepArray(gAdminData, integer, .order = SORT_DESC);
}
I am wondering about this feature, it would be nice if it was a speed improvement (to looping or assigning a new variable if you don't want to actually edit the order of the original data)
|
D:\samp\server\pawno\include\md-sort.inc(0) : error 075: input line too long (after substitutions) D:\samp\server\pawno\include\md-sort.inc(1) : error 075: input line too long (after substitutions) D:\samp\server\pawno\include\md-sort.inc(7) : error 010: invalid function or declaration D:\samp\server\pawno\include\md-sort.inc(12) : error 001: expected token: "-identifier-", but found "#emit" D:\samp\server\pawno\include\md-sort.inc(12) : error 075: input line too long (after substitutions) D:\samp\server\pawno\include\md-sort.inc(13) : error 010: invalid function or declaration D:\samp\server\pawno\include\md-sort.inc(15) : error 075: input line too long (after substitutions) D:\samp\server\pawno\include\md-sort.inc(17) : error 010: invalid function or declaration D:\samp\server\pawno\include\md-sort.inc(17) : error 010: invalid function or declaration D:\samp\server\pawno\include\md-sort.inc(22) : error 038: extra characters on line D:\samp\server\pawno\include\md-sort.inc(22) : error 075: input line too long (after substitutions) D:\samp\server\pawno\include\md-sort.inc(24) : warning 203: symbol is never used: "or" D:\samp\server\pawno\include\md-sort.inc(24) : error 013: no entry point (no public functions)