Raised This Month: $ Target: $400
 0% 

How do I use SortCustomD1 and D2 Properly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yan1255
Senior Member
Join Date: Jul 2011
Old 07-09-2013 , 09:56   How do I use SortCustomD1 and D2 Properly
Reply With Quote #1

How do I use SortCustomD1 and SortCustom2D properly?
__________________
yan1255 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-09-2013 , 10:21   Re: How do I use SortCustomD1 and D2 Properly
Reply With Quote #2

What do you need to sort ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 07-09-2013 , 11:04   Re: How do I use SortCustomD1 and D2 Properly
Reply With Quote #3

an integer called cash...
i want to sort ranks basically...
__________________
yan1255 is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 08-02-2013 , 14:27   Re: How do I use SortCustomD1 and D2 Properly
Reply With Quote #4

bump
__________________
yan1255 is offline
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 08-02-2013 , 17:36   Re: How do I use SortCustomD1 and D2 Properly
Reply With Quote #5

there should be a tutorial about this issue. Hard to understand
akcaliberg is offline
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
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
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-03-2013 , 05:40   Re: How do I use SortCustomD1 and D2 Properly
Reply With Quote #8

Quote:
Originally Posted by yan1255 View Post
thank you
that really helped me out.
now can you help me with editing arrays?

how do i exactly edit arrays in this way
ArraySetString ?
it's for the JailBreak Gang Plugin i want to make it possible to change gangs names... and because it's based on arrays i don't quite understand it yet...
so i will much appreciate the help
If you can give me an example of the array and what values it could consist of, yes. Otherwise It's hard to give examples that you have to implement yourself.

But in general arrays are not more complicated than normal strings, they are basically the same. So if you have an array of strings like so: ArrayOfStrings[32][128]. And you want to edit the string of the 12th index, you can use copy(ArrayOfStrings[12], 127, "New string value of 12th index.").
__________________
Black Rose is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 08-03-2013 , 05:55   Re: How do I use SortCustomD1 and D2 Properly
Reply With Quote #9

Quote:
Originally Posted by Black Rose View Post
If you can give me an example of the array and what values it could consist of, yes. Otherwise It's hard to give examples that you have to implement yourself.

But in general arrays are not more complicated than normal strings, they are basically the same. So if you have an array of strings like so: ArrayOfStrings[32][128]. And you want to edit the string of the 12th index, you can use copy(ArrayOfStrings[12], 127, "New string value of 12th index.").
no need for that for now...
i edited my post i would love it if you can help me with it
__________________
yan1255 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-03-2013 , 06:07   Re: How do I use SortCustomD1 and D2 Properly
Reply With Quote #10

Save it where? File, vault, SQL? Explain further what "rank" means.
Most things are possible, but only if explained so people can understand exactly what you want.
__________________
Black Rose is offline
Reply



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