1. Recursive task loop from getmaps() and StartVote()
2. Changed getmaps() to be direct call to have maps ready for vote
3. Chooses 4 maps while maps are available to be chosen
4. Only add items to the menu that exist
5. Stop loop if maps list is completely filled
6. First loop reads to end of file, second loop would give no results to add to maps list
7. Remove new line character at end of line
8. Only add map if it exists
9. Close file after using it
PHP Code:
public StartVote()
{
if (didgetmap == 0)
{
// #1, #2
getmaps()
}
new rnd
// #3
while (donemaps != 4 && mapscounter > 0)
{
rnd = random(mapscounter)
copy(mapschosen[donemaps++], 19, mapsavailable[rnd])
mapsavailable[rnd] = mapsavailable[--mapscounter]
}
gVoteMenu = menu_create("\rChange map?", "votemap");
// #4
new num[11]
for(new i = 0; i < donemaps; i++)
{
num_to_str(i, num, 10)
menu_additem(gVoteMenu, mapschosen[i], num, 0)
}
menu_additem(gVoteMenu, "\nExtend current map", "4", 0)
new players[32], pnum, tempid;
get_players(players, pnum, "ch");
for( new i; i<pnum; i++ )
{
tempid = players[i];
client_print(tempid, print_chat, "%s Please vote for the map you'd like to play in.", PREFIX)
menu_display(tempid, gVoteMenu);
}
set_task(10.0, "EndVote");
return PLUGIN_HANDLED;
}
public getmaps()
{
get_configsdir(maps_ini_file, 63);
format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file);
new mapsfile = fopen(maps_ini_file, "r")
new linefortest[50]
// #5, #6
while (mapscounter < sizeof(mapsavailable) && !feof(mapsfile))
{
fgets(mapsfile, linefortest, 49)
trim(linefortest) // #7
// #8
if (is_map_valid(linefortest))
{
copy(mapsavailable[mapscounter++], 24, linefortest)
}
}
// #9
fclose(mapsfile)
didgetmap++
// #1
}
__________________