Hi. I wrote a plugin to list all the maps from the maps folder, but I have a problem with sorting the list. I managed to sort them, using the Exolent's code from
here, but I think what I've made looks messy.
I was wondering what's the best way for sorting dynamic string arrays?
Here's the part of the code in question:
PHP Code:
public SortMaps(Array:g_MapsArray, iItem1, iItem2, const iData[])
{
static iData1[5], iData2[5]; // first 5 elements should be enough
ArrayGetString(g_MapsArray, iItem1, iData1, charsmax(iData1));
ArrayGetString(g_MapsArray, iItem2, iData2, charsmax(iData2));
new iCount1 = iData1[0]; // gets the first letter of the map name('d' for 'de_dust2')
new iCount2 = iData2[0]; // -//- ('d' for 'de_inferno')
if(iCount1 != iCount2) // in this example 'd' equals 'd'
{
return (iCount1 > iCount2) ? 1 : -1;
}
iCount1 = iData1[1];
iCount2 = iData2[1];
if(iCount1 != iCount2) // 'e' equals 'e'
{
return (iCount1 > iCount2) ? 1 : -1;
}
iCount1 = iData1[3];
iCount2 = iData2[3];
// 'd' != 'i' but this it's not good cause some maps could have a 3 letter prefix (awp_)
// then I'd need to repeat the above process
return (iCount1 > iCount2) ? 1 : ((iCount1 < iCount2) ? -1 : 0);
}
The entire code it's attached.