I forgot about pre-caching, plus this probably won't even work (not tested).
Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#define MAXNAMES 500
#define PANELCOUNT 40
new g_mapnames[MAXNAMES][32]
new g_mapcount
new g_mapselected[MAXNAMES]
new g_mapselection[PANELCOUNT]
public plugin_init()
{
register_plugin("Assign maps to panels", "1", "pizzahut")
read_cfg_file()
display_maps()
}
read_cfg_file()
{
new configfile[200]
get_configsdir(configfile, charsmax(configfile))
format(configfile, charsmax(configfile), "%s/maps.ini", configfile)
if (file_exists(configfile))
{
new mapname[32], chars_read
for (new line; (line < file_size(configfile, 1)) && (g_mapcount < MAXNAMES); line++)
{
read_file(configfile, line, mapname, charsmax(mapname), chars_read)
if (is_map_valid(mapname))
{
copy(g_mapnames[g_mapcount], charsmax(g_mapnames[]), mapname)
g_mapcount++
}
}
}
new map
for (new panel; (panel < PANELCOUNT) && (panel < g_mapcount); panel++)
{
map = random(g_mapcount)
while (g_mapselected[map])
map = random(g_mapcount)
g_mapselected[map] = 1
g_mapselection[panel] = map
}
}
display_maps()
{
new ent, panel, ent_info_target, model_path[128]
new Float:mins[3], Float:maxs[3], Float:origin[3]
while ((ent = find_ent_by_tname(ent, "glass_votemap")))
{
entity_get_vector(ent, EV_VEC_mins, mins)
entity_get_vector(ent, EV_VEC_maxs, maxs)
origin[0] = (mins[0] + maxs[0]) / 2.0
origin[1] = (mins[1] + maxs[1]) / 2.0
origin[2] = (mins[2] + maxs[2]) / 2.0
ent_info_target = create_entity("info_target")
entity_set_origin(ent_info_target, origin)
format(model_path, charsmax(model_path), "models/fm/maps/%s.mdl",g_mapnames[g_mapselection[panel]])
entity_set_model(ent_info_target, model_path)
panel++
}
}
From DarthMan:
Code:
public plugin_precache()
{
new conffile_mdl[200]
new configdir_mdl[200]
get_configsdir(configdir_mdl,199)
format(conffile_mdl,199,"%s/mapvote_precache.ini",configdir_mdl)
if(!file_exists(conffile_mdl))
{
log_amx("amxmodx/configs/mapvote_precache.ini is missing!")
return 0
}
new lines = file_size(conffile_mdl,1)
new file[1024], len
for(new i=0;i<=lines;i++)
{
read_file(conffile_mdl,i,file,1023,len)
if(equal(file,"")) continue;
if(!equal(file,";",1)) precache_model(file);
}
return PLUGIN_HANDLED
}