|
Member
Join Date: Mar 2009
Location: H.K.
|

05-16-2009
, 22:28
[Problem] Menu comes out twice
|
#1
|
PHP Code:
#include <amxmodx> #include <amxmisc> #define MAX_MAPS 128 #define SELECTMAPS 5 new g_voteforchange,g_voted_map[33] new g_mapName[MAX_MAPS][32] new g_mapNums new g_nextName[SELECTMAPS] new g_voteCount[SELECTMAPS] new g_mapVoteNum new g_teamScore[2] new g_lastMap[32] new g_voteYN[3] new Float:g_ori_timelimit=0.0 new g_coloredMenus new bool:g_selected = false new maphelp[MAX_MAPS][1024] new mapcheck[MAX_MAPS][1024] public plugin_init() { register_plugin("Nextmap Chooser","1.30","AMXX Dev Team") register_dictionary("mapchooser.txt") register_dictionary("common.txt") new MenuName[64] format(MenuName,63,"%L","en","CHOOSE_NEXTM") register_menucmd(register_menuid(MenuName),(1<<5|1<<6|1<<7|1<<8|1<<9),"countVote")//6-0 new YNMenuName[64] format(YNMenuName,63,"%L","en","SHOULD_CHANGE_MAP") register_menucmd(register_menuid(YNMenuName),(1<<7|1<<8|1<<9),"countYN") register_concmd("amx_votechange","cmdVoteChange",ADMIN_VOTE,"- vote for change map") register_concmd("cds_maplist","cmdMapList",ADMIN_MAP,"- List Maps") register_cvar("amx_extendmap_max","90") register_cvar("amx_extendmap_step","15") if ( cstrike_running() ) register_event("TeamScore", "team_score", "a") get_localinfo("lastMap",g_lastMap,31) set_localinfo("lastMap","") new maps_ini_file[64] get_configsdir(maps_ini_file, 63); format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file); if (!file_exists(maps_ini_file)) get_cvar_string("mapcyclefile", maps_ini_file, 63) if ( loadSettings(maps_ini_file) ) set_task(15.0,"voteShoudChange",987456,"",0,"b") g_coloredMenus = colored_menus() g_ori_timelimit=0.0 g_voteforchange=0 } public cmdMapList(id){ for(new i = 1;i<MAX_MAPS;i++){ console_print(id,"%s - %s",g_mapName[i],maphelp[i]) } } public change_map() server_cmd("changelevel %s",g_voted_map) public checkVotes() { new b = 0 for (new a = 0; a < g_mapVoteNum; ++a) if (g_voteCount[b] < g_voteCount[a]) b = a new nxtmapmsg[1024] new smap[32] if(!g_voteforchange){ if ( g_voteCount[b]) set_cvar_string("amx_nextmap", g_mapName[g_nextName[b]] ) get_cvar_string("amx_nextmap",smap,31) format(nxtmapmsg,1023,"%L", LANG_SERVER, "CHO_FIN_NEXT", smap,g_voteCount[b]) }else{ g_voteforchange=0 format(nxtmapmsg,1023,"%L", LANG_SERVER, "CHO_FIN_CHANGEMAP", g_mapName[g_nextName[b]],g_voteCount[b]) copy(g_voted_map,32,g_mapName[g_nextName[b]]) set_task(5.0,"change_map") } while(replace(nxtmapmsg,1023,"0x01","^x01")){} while(replace(nxtmapmsg,1023,"0x02","^x02")){} while(replace(nxtmapmsg,1023,"0x03","^x03")){} while(replace(nxtmapmsg,1023,"0x04","^x04")){} new id=0 for(id=1;id<=32;id++){ if(is_user_connected(id)){ message_begin(MSG_ALL, get_user_msgid("SayText"), {0,0,0}, 1) write_byte(1) write_string(nxtmapmsg) message_end() break; } } client_cmd(0,"spk events/task_complete") } public checkYN(){ new votemsg[129] if(g_voteforchange){ new Float:g_voteRatio=get_cvar_float("amx_votemap_ratio") new votesNum=g_voteYN[0]+g_voteYN[1] new iRatio=votesNum?floatround(g_voteRatio * float( votesNum ) ,floatround_ceil) : 1//Need vote count if(g_voteYN[0]>=iRatio){ format(votemsg,128,"%L",LANG_SERVER,"CHO_FIN_SUCESS",g_voteYN[0],iRatio) set_task(5.0,"voteNextmap") } else{ format(votemsg,128,"%L",LANG_SERVER,"CHO_FIN_FAIL",g_voteYN[0],iRatio) g_voteforchange=0 } }else { if(g_voteYN[0]>g_voteYN[1]){ format(votemsg,128,"%L",LANG_SERVER,"CHO_FIN_ANOTHER",g_voteYN[0]) //log_amx("Vote: Voting for if changeing map finished, We will start another Vote.") set_task(5.0,"voteNextmap") } else { new mapname[32] get_mapname(mapname,31) new Float:steptime = get_cvar_float("amx_extendmap_step") if(g_ori_timelimit==0.0) g_ori_timelimit = get_cvar_float("mp_timelimit") set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") + steptime ) g_selected=false format(votemsg,128,"%L", LANG_SERVER, "CHO_FIN_EXT", steptime,g_voteYN[1] ) } } while(replace(votemsg,128,"0x01","^x01")){} while(replace(votemsg,128,"0x02","^x02")){} while(replace(votemsg,128,"0x03","^x03")){} while(replace(votemsg,128,"0x04","^x04")){} new id=0 for(id=1;id<=32;id++){ if(is_user_connected(id)){ message_begin(MSG_ALL, get_user_msgid("SayText"), {0,0,0}, 1) write_byte(1) write_string(votemsg) message_end() break; } } client_cmd(0,"spk events/task_complete") return } public countYN(id,key){//Yes, Or No if(get_cvar_float("amx_vote_answers")){ new choose[21],yes[21],no[21],disclaim[21] new name[32],votemsg[129]="" format(choose,20,"%L",id,"CHOOSE") format(yes,20,"%L",id,"YES_MAP") format(no,20,"%L",id,"NO_MAP") format(disclaim,20,"%L",id,"DISCLAIM") get_user_name(id,name,31) //client_print(id,print_chat,"%s:%d",name,key) if(key==9){ format(votemsg,128,"^x03%s^x01%s^x04%s",name,choose,disclaim) } else if(key==8){ format(votemsg,128,"^x03%s^x01%s^x04%s",name,choose,no) } else if(key==7){ format(votemsg,128,"^x03%s^x01%s^x04%s",name,choose,yes) } message_begin(MSG_ALL, get_user_msgid("SayText"), {0,0,0}, id) write_byte(id) write_string(votemsg) message_end() } g_voteYN[key-7]++ return PLUGIN_HANDLED } public countVote(id,key) { if ( get_cvar_float("amx_vote_answers") ) { new name[32],votemsg[129] get_user_name(id,name,31) format(votemsg,128,"%L", LANG_SERVER, "X_CHOSE_X", name, g_mapName[g_nextName[key-5]] ) while(replace(votemsg,128,"0x01","^x01")){} while(replace(votemsg,128,"0x02","^x02")){} while(replace(votemsg,128,"0x03","^x03")){} while(replace(votemsg,128,"0x04","^x04")){} message_begin(MSG_ALL, get_user_msgid("SayText"), {0,0,0}, id) write_byte(id) write_string(votemsg) message_end() } ++g_voteCount[key-5] return PLUGIN_HANDLED } bool:isInMenu(id) { for (new a=0; a<g_mapVoteNum; ++a) if (id==g_nextName[a]) return true return false } public cmdVoteChange(id,level,cid){ if (!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED new Float:voting = get_cvar_float("amx_last_voting") if (voting > get_gametime()) { console_print(id, "%L", id, "ALREADY_VOTING") return PLUGIN_HANDLED } if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime()) { console_print(id, "%L", id, "VOTING_NOT_ALLOW") return PLUGIN_HANDLED } new timeleft=get_timeleft() if(timeleft<=5){ console_print(id, "%L", id, "VOTING_NOT_ALLOW") return PLUGIN_HANDLED } VoteChangeMap() return PLUGIN_HANDLED } public VoteChangeMap(){ new timeleft = get_timeleft() if(timeleft<3) return PLUGIN_HANDLED if(g_selected) return PLUGIN_HANDLED g_voteforchange=1 voteShoudChange() return PLUGIN_HANDLED } public voteShoudChange(){ new winlimit=get_cvar_num("mp_winlimit") new maxrounds = get_cvar_num("mp_maxrounds") if(!g_voteforchange){ if ( winlimit ) { new c = winlimit - 2 if ( (c > g_teamScore[0]) && (c > g_teamScore[1]) ) { g_selected = false return PLUGIN_HANDLED } } else if ( maxrounds ) { if ( (maxrounds - 2) > (g_teamScore[0] + g_teamScore[1]) ){ g_selected = false return PLUGIN_HANDLED } } else { new timeleft = get_timeleft() if (timeleft<1||timeleft>129){ g_selected = false return PLUGIN_HANDLED } } if (g_selected) return PLUGIN_HANDLED g_selected = true } new Float:voting = get_cvar_float("amx_last_voting") if (voting > get_gametime()) { return PLUGIN_HANDLED } new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0 set_cvar_float("amx_last_voting", get_gametime() + vote_time ) if (g_voteforchange||((winlimit + maxrounds)==0 && (get_cvar_float("mp_timelimit") < get_cvar_float("amx_extendmap_max")))){//vote for Extended new menu[512],mkeys= (1<<7|1<<8|1<<9) new pos=format(menu,511,g_coloredMenus? "\y%L:\w^n^n" : "%L:^n^n",LANG_SERVER,"SHOULD_CHANGE_MAP") pos+=format(menu[pos],511-pos,"8.%L^n",LANG_SERVER,"YES_MAP") pos+=format(menu[pos],511-pos,"9.%L^n",LANG_SERVER,"NO_MAP") pos+=format(menu[pos],511-pos,"^n0.%L",LANG_SERVER,"DISCLAIM") for(new i=0;i<3;i++)g_voteYN[i]=0//Reset Vote Map new MenuName[64] format(MenuName,63,"%L","en","SHOULD_CHANGE_MAP") show_menu(0,mkeys,menu,15,MenuName) set_task(15.0,"checkYN") client_cmd(0,"spk events/enemy_died") }else { voteNextmap() } return PLUGIN_HANDLED } public voteNextmap() { new menu[512], a, mkeys = 0 new mapname[32] new pos = format(menu,511,g_coloredMenus ? "\y%L:\w^n^n" : "%L:^n^n", LANG_SERVER, "CHOOSE_NEXTM") new dmax = (g_mapNums-1 > SELECTMAPS) ? SELECTMAPS : g_mapNums-1 get_mapname(mapname,31) for(g_mapVoteNum = 0;g_mapVoteNum<dmax;++g_mapVoteNum){ a=random_num(0,g_mapNums-1) for(;;){ if(isInMenu(a)||equal(g_mapName[a],mapname)) ++a else break; if(a>=g_mapNums) a=0 } g_nextName[g_mapVoteNum] = a new showid=g_mapVoteNum+6 if (showid>9) showid=0 pos += format(menu[pos],511-pos,"%d. %s^n\r|-\y%s^n\w",showid,g_mapName[a],maphelp[a],1023)//We Start From 6-0 mkeys |= (1<<g_mapVoteNum+5) g_voteCount[g_mapVoteNum] = 0 } for(new i=dmax;i<SELECTMAPS;++i)g_voteCount[i]=0 //Clear Unused Maps new MenuName[64] format(MenuName,63,"%L","en","CHOOSE_NEXTM") show_menu(0,mkeys,menu,15,MenuName) set_task(15.0,"checkVotes") client_print(0,print_chat,"%L",LANG_SERVER,"TIME_CHOOSE") client_cmd(0,"spk events/tutor_msg.wav") } loadSettings(filename[]) { if (!file_exists(filename)) return 0 new szText[1024] new a, pos = 0 new currentMap[32] get_mapname(currentMap,31) while ( (g_mapNums < MAX_MAPS) && read_file(filename,pos++,szText,1023,a) ) { if ( szText[0] != ';' && parse(szText, g_mapName[g_mapNums] ,31,maphelp[g_mapNums],1023 ,mapcheck[g_mapNums],1023) && is_map_valid( g_mapName[g_mapNums] ) && !equali( g_mapName[g_mapNums] ,g_lastMap) && !equali( g_mapName[g_mapNums] ,currentMap) && !equali( mapcheck[g_mapNums] ,"fall") ) ++g_mapNums } return g_mapNums } public team_score() { new team[2] read_data(1,team,1) g_teamScore[ (team[0]=='C') ? 0 : 1 ] = read_data(2) } public plugin_end() { new current_map[32] get_mapname(current_map,31 ) set_localinfo("lastMap",current_map) if(g_ori_timelimit!=0.0) set_cvar_float("mp_timelimit", g_ori_timelimit) }
This is mapchooser.amxx modified. amx_votechange is use for vote earlier.
When I use the cmd 'amx_votechange' of course a menu comes.
However, after about 15-20 seconds, it comes again.
Can any one fix this? thanks a lot!
|
|