Raised This Month: $ Target: $400
 0% 

How do I use SortCustomD1 and D2 Properly


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-02-2013 , 17:39   Re: How do I use SortCustomD1 and D2 Properly
Reply With Quote #6

How is the array built?
Custom means it has to be customized depending on how you want to sort it. The text over the function on the inc really explains it all.

Here's an example of 1D-array I did recently. It sorts players by score, if score is equal it compares who has the least amount of deaths instead.

Code:
#include <amxmodx> #include <cstrike> #define g_MaxPlayers 32 public plugin_init() {     register_plugin("Test Plugin 8", "", "");         register_clcmd("say /sb", "score") } public score(id) {         new iPlayers[32], iPlayersnum, text[64], name[32];         get_players(iPlayers, iPlayersnum, "c");     SortCustom1D(iPlayers, iPlayersnum, "SortFunc");         for ( new i = 0 ; i < iPlayersnum ; i++ ) {         get_user_name(iPlayers[i], name, 31);         formatex(text, 63, "%s %i %i", name, get_user_frags(iPlayers[i]), get_user_deaths(iPlayers[i]));         server_print("%d: %s", i, iPlayers[i]);     } } public SortFunc(elem1, elem2) {     if ( get_user_frags(elem1) > get_user_frags(elem2) )         return -1;     else if ( get_user_frags(elem1) < get_user_frags(elem2) )         return 1;     else if ( get_user_deaths(elem1) < get_user_deaths(elem2) )         return -1;     else if ( get_user_deaths(elem1) > get_user_deaths(elem2) )         return 1;     return 0; }
Return values:
-1: elem1 before elem2
1: elem2 before elem1
0: they are equal.
__________________

Last edited by Black Rose; 08-02-2013 at 17:43.
Black Rose is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode