
   /* AMX Mod Script
   *
   * map_rate by p00h <admin@p00hsan.zive.net>
   *
   * VER 0.1
   *
   * URL >> http://members.jcom.home.ne.jp/p00h_san/
   *
   * First, make dir /cstrike/map_rate.
   *
   */
   #include <amxmod>
   new logdir[32] = "map_rate"
   new state[3]
   new nowstate[3]
   new plnum
   new conducting = false
   new bshow = true
   public write_log(){
       new mapname[33]
       new tmp[10]
       get_mapname(mapname,32)
       new writefile[64]
       format(writefile,255,"%s/%s",logdir,mapname)
       if(file_exists(writefile)) {
           delete_file(writefile)
       }
       format(tmp,9,"%i",state[0])
       write_file(writefile,tmp,-1)
       format(tmp,9,"%i",state[1])
       write_file(writefile,tmp,-1)
       format(tmp,9,"%i",state[2])
       write_file(writefile,tmp,-1)
       return PLUGIN_CONTINUE
   }
   public read_log(){
       //console_print(id,"OK,readrate!!")
       new readdata[10]
       new mapname[33]
       new readfile[64]
       new len
       new i
       get_mapname(mapname,32)
       format(readfile,255,"%s/%s",logdir,mapname)

       if(!file_exists(readfile)) {
           state[0] = 0
           state[1] = 0
           state[2] = 0
           write_log()
           return PLUGIN_CONTINUE
       }
       for(i = 0; i < 3;){
           i = read_file(readfile,i,readdata,9,len)
           state[i-1] = strtonum(readdata)
           //client_print(0,print_chat,"state[%i] %i",i-1,state[i-1])
       }
       return PLUGIN_CONTINUE
   }
   public ask_menu() {
       new menu[256]
       new mapname[33]
       get_mapname(mapname,32)
       plnum = 0
       nowstate[0] = 0
       nowstate[1] = 0
       nowstate[2] = 0
       format(menu,255,"\yWhat  do you think about %s?\w^n^n1.  Very Good
   ! !^n2.  Medium .^n3.  So Bad . . .",mapname)
       show_menu(0,(1<<0)|(1<<1)|(1<<2),menu,10)
       conducting = true
       client_cmd(0,"spk Gman/Gman_Choose2")
       set_task(10.0,"end_conduct")
       client_print(0,print_chat,"* Conducting a survey of players...")
   }
   public vote_count(id,key) {
       new name[32]
       get_user_name(id,name,31)

       if(key == 0) {
           client_print(0,print_chat,"* %s selected Very Good!!",name)
           state[0]++
           nowstate[0]++
       }
       if(key == 1) {
           client_print(0,print_chat,"* %s selected Medium.",name)
           state[1]++
           nowstate[1]++
       }
       if(key == 2) {
           client_print(0,print_chat,"* %s selected So Bad...",name)
           state[2]++
           nowstate[2]++
       }
       plnum++
   }
   public end_conduct() {
       new Float:ans[3]
       new Float:tans[3]
       new Float:total

       if(nowstate[0] == 0) {
           nowstate[0] = 0
       }else {
           ans[0] = float(nowstate[0]) / float(plnum)
       }
       if(nowstate[2] == 0) {
           nowstate[2] = 0
       }else {
           ans[2] = float(nowstate[2]) / float(plnum)
       }
       ans[1] = 1.00 - (ans[0] + ans[2])
       client_print(0,print_chat,"*   Now   Rate   :  Very  Good!!!(%.2f)
   Medium.(%.2f) So Bad...(%.2f)",ans[0],ans[1],ans[2])

       total = float(state[0] + state[1] + state[2])
       if(state[0] == 0) {
           tans[0] = float(0)
       }else {
           tans[0] = float(state[0]) / total
       }
       if(state[2] == 0) {
           tans[2] = float(0)
       }else {
           tans[2] = float(state[2]) / total
       }
       tans[1] = 1.00 - (tans[0] + tans[2])
       client_print(0,print_chat,"*   Total  Rate  :  Very  Good!!!(%.2f)
   Medium.(%.2f) So Bad...(%.2f)",tans[0],tans[1],tans[2])
       set_task(10.0,"print_message")
       write_log()
       conducting = false
       return PLUGIN_CONTINUE
   }
   public print_message() {
       client_print(0,print_chat,"[AMX]  You  can check rate of map : say
   /showrate")
   }
   public show_rate(id) {
       if(conducting) {
           return PLUGIN_CONTINUE
       }

       read_log()

       new Float:tans[3]
       new Float:total
       total = float(state[0] + state[1] + state[2])
       if(state[0] == 0) {
           tans[0] = float(0)
       }else {
           tans[0] = float(state[0]) / total
       }
       if(state[2] == 0) {
           tans[2] = float(0)
       }else {
           tans[2] = float(state[2]) / total
       }
       tans[1] = 1.00 - (tans[0] + tans[2])
       client_print(0,print_chat,"*   Total  Rate  :  Very  Good!!!(%.2f)
   Medium.(%.2f) So Bad...(%.2f)",tans[0],tans[1],tans[2])

       return PLUGIN_CONTINUE
   }
   public read_rate() {
       new timeleft = get_timeleft()

       if(bshow&&(timeleft>0)&&(timeleft<60)) {
           bshow = false
           read_log()
           ask_menu()
       }
   }
   public plugin_init(){
       register_plugin("Map_Rate","0.1","p00h")
       register_menucmd(register_menuid("What    do   you   think   about
   "),(1<<0)|(1<<1)|(1<<2),"vote_count")
       register_clcmd("say /showrate","show_rate")
       set_task(10.0,"read_rate",777,"",0,"b")
           return PLUGIN_CONTINUE
   }
