Order variables alphabetical - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Order variables alphabetical (
/showthread.php?tid=620450)
Order variables alphabetical -
MerryDeer - 30.10.2016
Hi,
I have variables like
new Nameslist[ MAX_PLAYERS ][ MAX_NAMES ][ MAX_PLAYER_NAME ];
This variable can contain any name, but when i show dialog, i want to order it before showing, from order alphabetical A-Z
Re: Order variables alphabetical -
SyS - 30.10.2016
Simple snippet
PHP код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)
/*Alphabet sorter by Sreyas*/
alpha(str[MAX_NAMES][MAX_PLAYER_NAME]) //MAX_NAME - total number of strings in that matrix
{
new i, j,t[24];
for(i=1; i<MAX_NAMES; i++)
{
for(j=1; j<MAX_NAMES; j++)
{
if(strcmp(str[j-1], str[j])>0)
{
strcpy(t, str[j-1]);
strcpy(str[j-1], str[j]);
strcpy(str[j], t);
}
}
}
/*printf("Names in alphabetical order ");
for(i=0; i<MAX_NAMES; i++)
{
printf("%s",str[i]);
}
*/
}