Hi! Now I wish to make a random selection of maps already used YAP PUG MOD and when the vote on maps if nobody chooses a map in 20 sec launches the configuration and does not change the map, i want to spend those 20 sec if was not chosen a map back to a random map here i leave my complete code
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <yap_menu>
#include <yap_const>
#include <yap_stocks>
#include <yap_natives>
#include <yap_forwards>
#include <yap_modspecific>
new const plugin_author[] = "PsychO"
new const plugin_name[] = "YAP-MENU"
new const plugin_version[] = "0.0.1"
public pug_votemap_menu;
public pug_voteteam_menu;
public pug_voteplayers_menu
public pug_voterestart_menu
public pug_votekick_menu
public pug_cvar_vote_time;
public pug_cvar_vote_perc;
public pug_cvar_votemap
public pug_cvar_votemap_e
public pug_cvar_votekick_perc;
new votemap_noswitch
public pug_voting = 0;
public plugin_init()
{
register_plugin(plugin_name,plugin_version,plugin_author);
register_dictionary("yap.txt")
register_dictionary("yap_vote.txt")
pug_cvar_vote_time = register_cvar("pug_vote_delay","20")
pug_cvar_vote_perc = register_cvar("pug_vote_percentage","0.4")
pug_cvar_votemap = register_cvar("pug_votemap","1")
pug_cvar_votemap_e = register_cvar("pug_votemap_enabled","1")
pug_cvar_votekick_perc = register_cvar("pug_votekick_percent","0.4")
register_pug_admincmd("votemap","cmd_votemap",PUG_CMD_LVL,"Solo para ADMIN")
//register_pug_admincmd("voteteams","cmd_voteteams",PUG_CMD_LVL,"Solo para ADMIN")
register_pug_admincmd("votekick","cmd_votekick",_,"< nombre > - Comienza un votekick")
register_pug_admincmd("voteplayers","cmd_voteplayers",PUG_CMD_LVL,"Solo para ADMIN")
//parse_header("BOE-E",pug_header,5)
pug_votemap_menu = menu_create("Pug VoteMap:","votemap_handle");
pug_voteteam_menu = menu_create("Team Enforcement:","voteteam_handle");
pug_voterestart_menu = menu_create("VoteRestart:","voterestart_handle");
pug_votekick_menu = menu_create("VoteKick:","votekick_handle");
menu_setprop(pug_votemap_menu,MPROP_EXIT,MEXIT_NEVER)
menu_additem(pug_voteteam_menu,"None","1")
menu_additem(pug_voteteam_menu,"Random","4")
//menu_additem(pug_voteteam_menu,"Skill Sorted","3")
//menu_additem(pug_voteteam_menu,"Captain Sorted","4")
menu_setprop(pug_voteteam_menu,MPROP_EXIT,MEXIT_NEVER)
menu_additem(pug_voterestart_menu,"Si","1")
menu_additem(pug_voterestart_menu,"No","2")
menu_setprop(pug_voterestart_menu,MPROP_EXIT,MEXIT_NEVER)
menu_additem(pug_votekick_menu,"Si","1")
menu_additem(pug_votekick_menu,"No","2")
menu_setprop(pug_votekick_menu,MPROP_EXIT,MEXIT_NEVER)
}
public plugin_cfg() try_load_votemap_menu()
CREATE_GEN_FORW_ID(firsthalf_forward)
public pug_firsthalf(GEN_FORW_ID(forward_id))
{
firsthalf_forward = forward_id
if( get_pcvar_num(pug_cvar_votemap_e) && get_pcvar_num(pug_cvar_votemap) ) votemap_start();
else voteteam_start();
return PLUGIN_HANDLED;
}
public pug_finished()
{
if(!votemap_noswitch) set_pcvar_num(pug_cvar_votemap_e,1)
}
#define MAX_MAPS 20
new pug_votemap_votes[MAX_MAPS]
new pug_votemap_name[MAX_MAPS][32]
new pug_votemap_count;
public try_load_votemap_menu()
{
// Rukia: Get our maps.ini
static filename[64]
get_configsdir( filename, 63 )
format( filename, 63, "%s/maps.ini", filename )
// Rukia: Otherwise, just use mapcycle
if(file_exists(filename))
{
load_votemap_menu(filename)
if(pug_votemap_count != 0) return;
}
copy(filename,63,"mapcycle.txt")
load_votemap_menu(filename)
}
public load_votemap_menu(filename[])
{
new file = fopen(filename,"rb")
static text[256], szDesc[48], num[10]
while( (pug_votemap_count < MAX_MAPS) && !feof(file) && fgets(file,text,255) )
{
// Rukia: Take out common comment conventions
if(text[0]==';') continue
if( (text[0]=='/') && (text[1]=='/') ) continue
// Rukia: Remove the newline character
text[strlen(text)] = '^0'
// Rukia: Get the map name and description out of what we read
strbreak(text,pug_votemap_name[pug_votemap_count],31,szDesc,47)
// Rukia: If the map is invalid, skip it
if( !is_map_valid( pug_votemap_name[pug_votemap_count] ) ) continue;
// Rukia: If there is no description (such as if we use mapcycle) then just use the first part of the map name
if(szDesc[0] == '^0') strtok(pug_votemap_name[pug_votemap_count],szDesc,47,"",0,'.',1)
// Rukia: The map number will be our index
formatex(num,9,"%i",pug_votemap_count)
// Rukia: Add the item into the menu and move on
menu_additem(pug_votemap_menu, pug_votemap_name[pug_votemap_count],num )
pug_votemap_count++;
}
fclose(file)
}
public cmd_votemap(id,level,cid)
{
if (!cmd_access(id, level, cid, 1) ) return pug_msg_tmp_empty(id,"PUG_CMD_NOTALLOWED")
votemap_start()
return PLUGIN_HANDLED;
}
public votemap_start()
{
if(pug_voting) { set_task(get_pcvar_float(pug_cvar_vote_time),"votemap_start",100 + pug_votemap_menu); return; }
pug_voting = 1;
arrayset(pug_voted,0,33)
arrayset(pug_votemap_votes,0,pug_votemap_count)
pug_display_menu_all(pug_votemap_menu)
client_print(0,print_chat,"",pug_header, LANG_PLAYER, "PUG_VOTE_START", "PUG map");
console_print(0,"%s %L",pug_header, LANG_PLAYER, "PUG_VOTE_START", "PUG map");
set_task(get_pcvar_float(pug_cvar_vote_time),"votemap_end",100 + pug_votemap_menu)
}
public votemap_end()
{
pug_cancel_menu()
pug_voting = 0;
remove_task ( 100 + pug_votemap_menu )
if(votemap_count()) voteteam_start();
}
public votemap_handle(id, menu, item)
{
if( item < 0 ) return PLUGIN_CONTINUE;
static access, callback
static cmd[3], name[32], cmdname[32]
menu_item_getinfo(menu, item, access, cmd,2,cmdname,31, callback);
pug_votemap_votes[str_to_num(cmd)]++;
get_user_name(id,name,31)
client_print(0,print_chat,"",pug_header, LANG_PLAYER, "PUG_VOTED_FOR", name, cmdname);
console_print(0,"%s %L",pug_header, LANG_PLAYER, "PUG_VOTED_FOR", name, cmdname);
pug_voted[id] = 1;
if(pug_should_stopvote() ) votemap_end()
return PLUGIN_HANDLED;
}
public votemap_count()
{
new winner, winner_votes, votes
for(new i = 0; i < pug_votemap_count; ++i)
{
votes = pug_votemap_votes[i]
if(votes > winner_votes) { winner = i; winner_votes = votes; }
else if(votes == winner_votes) if(random_num(0,1)) { winner = i; winner_votes = votes; }
}
if(pug_votemap_votes[winner] == 0) return pug_msg_tmp_empty(0,"PUG_VOTE_FAILED_NOVOTES") // Here returns to a msg and launches the condiguracion but does not change the map
new Float: tmp = float(pug_get_players()) * get_pcvar_float(pug_cvar_vote_perc)
if( pug_votemap_votes[winner] < floatround(tmp,floatround_floor) )
{
return pug_msg_tmp_empty(0,"PUG_VOTE_FAILED_INSUF_VOTES"); // Here returns to a msg and launches the condiguracion but does not change the map
}
client_print(0,print_chat,"%s %L",pug_header, LANG_PLAYER, "PUG_VOTE_WIN", pug_votemap_name[winner]);
console_print(0,"%s %L",pug_header, LANG_PLAYER, "PUG_VOTE_WIN", pug_votemap_name[winner]);
pug_voting = 0;
votemap_noswitch = 1;
set_pcvar_num(pug_cvar_votemap_e,0)
message_begin(MSG_ALL, SVC_INTERMISSION)
message_end()
set_task(5.0,"pug_votemap_change",winner)
return PLUGIN_CONTINUE
}
public pug_votemap_change(winner)
{
server_cmd("changelevel %s",pug_votemap_name[winner]);
}
How could implement the random map to the code? please help!