So, i made some sorting algorithm based on sorting alphabetically but symbols first in line, numbers second and letters last. I have some arrays with some numbers which stand for item ids registered in my plugin, i set the arrays based on some conditions and then introduce the array into the function which sorts the array. At the start of the function i checked what is in that array and i see that everything (for a specific number of items representing the items in the field) and see that everything is empty, why?
In the first lines of the function 'SortItemArray' you can see that i checked the array for its item ids and in 'InitSort' that i sorted the arrays (2 arrays with 3 dimensions) in 3 for-loops (no the best idea, it could be easier in 2 but still not the problem).
PHP Code:
SortItemArray( const Sort: mtd, const SortDir: dir, const Category, array[ ] )
{
server_print("[Buymenu] items in array to sort for category %s", g_CategName[Category]);
for(new h = 0; h < g_iCategItems[Category]; h++)
server_print("[Buymenu] %i", array[h]);
if(g_iCategItems[Category] <= 1)
{
server_print("[Buymenu] Not enough items to sort.");
return;
}
new i, j, d;
if ( mtd == Sort_Name )
{
new szName[ 30 ], szName2[ 30 ];
for ( i = 0; i < g_iCategItems[Category]; i++ )
{
ArrayGetString( g_ItemData[ IRD_Name ], array[ i ], szName2, charsmax( szName2 ) );
for ( d = 0; d < sizeof g_szMenuCodes; d++ )
{
if ( contain( szName, g_szMenuCodes[ d ] ) )
replace_all( szName, charsmax( szName ), g_szMenuCodes[ d ], "");
}
for ( j = i+1; j < g_iCategItems[Category]; j++ )
{
ArrayGetString( g_ItemData[ IRD_Name ], array[ j ], szName2, charsmax( szName2 ) );
for ( d = 0; d < sizeof g_szMenuCodes; d++ )
{
if ( contain( szName2, g_szMenuCodes[ d ] ) )
replace_all( szName2, charsmax( szName2 ), g_szMenuCodes[ d ], "");
}
if ( CompareStrings( szName2, szName, dir ) > 0 )
{
inverse_values( array[ i ], array[ j ] );
}
}
}
}
else if ( mtd == Sort_Cost )
{
server_print("[Buymenu] Sorting by Cost:");
new iCost[ 2 ];
new szSysName[2][20];
for ( i = 0; i < g_iCategItems[Category]; i++)
{
for ( j = i+1; j < g_iCategItems[Category]; j++ )
{
iCost[ 0 ] = ArrayGetCell( g_ItemData[ IRD_Cost ], array[ i ] );
iCost[ 1 ] = ArrayGetCell( g_ItemData[ IRD_Cost ], array[ j ] );
ArrayGetString( g_ItemData[ IRD_SystemName ], array[i], szSysName[0], charsmax(szSysName[]) );
ArrayGetString( g_ItemData[ IRD_SystemName ], array[i], szSysName[1], charsmax(szSysName[]) );
server_print("[Buymenu] %s vs %s", szSysName[0], szSysName[1]);
if ( ( iCost[ 0 ] > iCost[ 1 ] && dir == SRDir_Ascendent ) ||
( iCost[ 0 ] < iCost[ 1 ] && dir == SRDir_Descendent ) )
{
inverse_values( array[ i ], array[ j ] );
}
server_print("[Buymenu] Next: ^n^n");
}
}
}
}
InitSort( )
{
new szSysName[20];
for ( new i = 0; i < CATEGORIES; i++ )
{
for ( new SortDir:x = SortDir:0; x < SortDir; x++ )
{
for ( new z = 0; z < g_iItems; z++ )
{
if ( ArrayGetCell( g_ItemData[ IRD_Category ], z ) != i )
continue;
ArrayGetString( g_ItemData[ IRD_SystemName ], z, szSysName, charsmax(szSysName) );
server_print("[Buymenu] %s is part of %s (Id: %i)", szSysName, g_CategName[i], z);
g_iSortedItemsCost[ i ][ x ][ z ] = z;
g_iSortedItemsName[ i ][ x ][ z ] = z;
}
SortItemArray( Sort_Cost, x, i, g_iSortedItemsCost[ i ][ x ] );
SortItemArray( Sort_Name, x, i, g_iSortedItemsName[ i ][ x ] );
}
}
for ( new i = 0; i < CATEGORIES; i++ )
{
for ( new z = 0; z < g_iCategItems[i]; z++ )
{
ArrayGetString( g_ItemData[ IRD_SystemName ], g_iSortedItemsCost[i][SRDir_Ascendent][z], szSysName, charsmax(szSysName) );
server_print("[Buymenu] Category %s by Cost: %i. %s", g_CategName[i], z, szSysName);
}
}
}
Solved
I was setting the same cell in the third dimension.