08.12.2018, 12:12
If there are files with different extensions in that directory, you will need to check the last 4 characters (matching .map).
If you can, store all .map files in a folder called "Maps" or something else and you do not need strfind. The code from previous post will work.
Current random algorithm gives few results over and over again. If you want any map to have a chance, you may use MerRandom plugin.
pawn Код:
new dir: dHandle, item[40], type, counter, random_file;
dHandle = dir_open("./scriptfiles");
while (dir_list(dHandle, item, type))
{
if(type == FM_FILE && strfind(item, ".map", true, strlen(item) - 4) != -1) counter++;
}
dir_close(dHandle);
random_file = random(counter);
counter = 0;
dHandle = dir_open("./scriptfiles");
while (dir_list(dHandle, item, type))
{
if(type == FM_FILE && strfind(item, ".map", true, strlen(item) - 4) != -1 && counter++ == random_file) break;
}
dir_close(dHandle);
printf("random file: \"%s\"", item);
Current random algorithm gives few results over and over again. If you want any map to have a chance, you may use MerRandom plugin.