Raised This Month: $ Target: $400
 0% 

[Problem] Menu comes out twice


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
edward0810
Member
Join Date: Mar 2009
Location: H.K.
Old 05-16-2009 , 22:28   [Problem] Menu comes out twice
Reply With Quote #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_file63);
  
format(maps_ini_file63"%s/maps.ini"maps_ini_file);
  if (!
file_exists(maps_ini_file))
   
get_cvar_string("mapcyclefile"maps_ini_file63)
  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 
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 
0
  
for (new 0g_mapVoteNum; ++a)
    if (
g_voteCount[b] < g_voteCount[a])
       
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_ALLget_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 floatvotesNum ) ,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.0g_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_ALLget_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_ALLget_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"nameg_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_ALLget_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=0a<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 
winlimit 2
     
if ( (g_teamScore[0]) && (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)==&& (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], amkeys 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-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_mapNumsa=0
    
}
    
g_nextName[g_mapVoteNum] = a
    
new showid=g_mapVoteNum+6
    
if (showid>9showid=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 
apos 0
  
new currentMap[32]
  
get_mapname(currentMap,31)
  while ( (
g_mapNums MAX_MAPS) && read_file(filename,pos++,szText,1023,a) ) {
    if ( 
szText[0] != ';'
    
&&  parse(szTextg_mapName[g_mapNums] ,31,maphelp[g_mapNums],1023 ,mapcheck[g_mapNums],1023)
    &&  
is_map_validg_mapName[g_mapNums] ) 
    &&  !
equalig_mapName[g_mapNums] ,g_lastMap)
    &&  !
equalig_mapName[g_mapNums] ,currentMap)
    &&  !
equalimapcheck[g_mapNums] ,"fall") )
      ++
g_mapNums
  
}
  return 
g_mapNums
}
public 
team_score() {
  new 
team[2]
  
read_data(1,team,1)
  
g_teamScore[ (team[0]=='C') ? ] = 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.0set_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!
edward0810 is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode