#include <amxmodx>
new const maps_list_file[] = "addons/amxmodx/configs/maps.ini"
new Trie:g_Trie;
new priority_maps[][] =
{
"de_dust2",
"de_nuke",
"de_cbble"
}
public SortMapNames(Array:array, item1, item2, const data[], data_size)
{
new szMap[2][32];
new high_priority[2];
new bool:found_priority[2];
ArrayGetArray(array, item1, szMap[0]);
ArrayGetArray(array, item2, szMap[1]);
found_priority[0] = TrieGetCell(g_Trie, szMap[0], high_priority[0]);
found_priority[1] = TrieGetCell(g_Trie, szMap[1], high_priority[1]);
if(found_priority[0] || found_priority[1])
{
if(found_priority[0] && found_priority[1])
return high_priority[0] > high_priority[1] ? 1 : -1;
else if (found_priority[0])
return -1;
else if (found_priority[1])
return 1;
}
return strcmp(szMap[0], szMap[1], true);
}
public plugin_precache()
{
register_plugin("Map List Generator", "1.3m", "Leo_[BH]")
new dir, mapName[32]
dir = open_dir("maps", mapName, charsmax(mapName))
new Array:g_ArrMaps = ArrayCreate(32);
g_Trie = TrieCreate();
for(new i = 0 ; i < sizeof(priority_maps); i++)
{
TrieSetCell(g_Trie, priority_maps[i], i);
}
if(dir)
{
new lenMapName
while(next_file(dir, mapName, charsmax(mapName)))
{
lenMapName = strlen(mapName);
if (lenMapName > 4 && equali(mapName[lenMapName - 4], ".bsp", 4))
{
mapName[lenMapName-4] = '^0'
ArrayPushArray(g_ArrMaps, mapName);
}
}
close_dir(dir)
}
ArraySort(g_ArrMaps, "SortMapNames");
new iSize = ArraySize(g_ArrMaps);
new szMap[32];
new mapsfileid = fopen(maps_list_file,"wt");
for(new i = 0 ; i < iSize; i++)
{
ArrayGetArray(g_ArrMaps, i, szMap);
fprintf(mapsfileid, "%s^n", szMap)
}
fclose(mapsfileid)
ArrayDestroy(g_ArrMaps);
TrieDestroy(g_Trie);
}