Raised This Month: $ Target: $400
 0% 

How do I use SortCustomD1 and D2 Properly


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
yan1255
Senior Member
Join Date: Jul 2011
Old 08-03-2013 , 04:52   Re: How do I use SortCustomD1 and D2 Properly
Reply With Quote #7

Quote:
Originally Posted by Black Rose View Post
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.
Thank you , That really helped me out.
Though is there any way to save it ? like rank from an entire server players (not only online one's)
I mean I know there is, but is there any way that is easy?
__________________

Last edited by yan1255; 08-03-2013 at 05:19.
yan1255 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