AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How do I use SortCustomD1 and D2 Properly (https://forums.alliedmods.net/showthread.php?t=220306)

yan1255 07-09-2013 09:56

How do I use SortCustomD1 and D2 Properly
 
How do I use SortCustomD1 and SortCustom2D properly?

ConnorMcLeod 07-09-2013 10:21

Re: How do I use SortCustomD1 and D2 Properly
 
What do you need to sort ?

yan1255 07-09-2013 11:04

Re: How do I use SortCustomD1 and D2 Properly
 
an integer called cash...
i want to sort ranks basically...

yan1255 08-02-2013 14:27

Re: How do I use SortCustomD1 and D2 Properly
 
bump

akcaliberg 08-02-2013 17:36

Re: How do I use SortCustomD1 and D2 Properly
 
there should be a tutorial about this issue. Hard to understand

Black Rose 08-02-2013 17:39

Re: How do I use SortCustomD1 and D2 Properly
 
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.

yan1255 08-03-2013 04:52

Re: How do I use SortCustomD1 and D2 Properly
 
Quote:

Originally Posted by Black Rose (Post 2004392)
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 :3, 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?

Black Rose 08-03-2013 05:40

Re: How do I use SortCustomD1 and D2 Properly
 
Quote:

Originally Posted by yan1255 (Post 2004621)
thank you :3
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.").

yan1255 08-03-2013 05:55

Re: How do I use SortCustomD1 and D2 Properly
 
Quote:

Originally Posted by Black Rose (Post 2004630)
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 :)

Black Rose 08-03-2013 06:07

Re: How do I use SortCustomD1 and D2 Properly
 
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.


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

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