
   /*********************************************************************
   ******
   *  amx_sy5_alltalk.sma
   *   version 1.0         Date: 04/10/2003
   *   Author: Eric Lidman     ejlmozart@hotmail.com
   *   Alias: Ludwig van       Upgrade:
   http://lidmanmusic.com/cs/plugins.html
   *
   * Edited:
   *   Sy5tem                  sy5tem@videotron.ca
   *
   *  Commands:
   *   amx_alltalk      -- toggles on and off alltalk jumping
   *   amx_votealltalk  -- starts a vote for alltalk style jumping
   *   stopvote        -- stops a vote in progress
   *
   **********************************************************************
   *****/
   #include <amxmod>
   #include <amxmisc>
   new vault_value[128]
   new alltalk_cvar[16]
   new votenumber = 0
   new votecontroller[33][2]
   new option[4]
   new Float:vote_ratio
   new totalvoters = 0
   new bool:bVoteToStop = false
   new st_vote
   public MXVote(id) {
       new Float:voting = get_cvar_float("amx_last_voting")
       if (voting > get_gametime()){
           console_print(id,"There is already one voting...")
           return PLUGIN_HANDLED
       }
       if   (voting   &&   voting  +  get_cvar_float("amx_vote_delay")  >
   get_gametime()) {
           console_print(id,"Voting not allowed at this time")
           return PLUGIN_HANDLED
       }
       new inprogress[32]
       get_cvar_string("amx_vote_inprogress",inprogress,32)
       if(equal(inprogress, "0",1)){
       new menu_msg[256]
       new keys
       format(menu_msg,256,"\yDo  you want Alltalk? \w^n^n1.  Yes want to
   hear everybody talk!^n2.  No hearing my team talking is enouf")
       keys = (1<<0)|(1<<1)
       new authid[16],name[32]
       get_user_authid(id,authid,16)
       get_user_name(id,name,32)
       log_to_file("addons/amx/admin.log","^"%s<%d><%s><>^"          vote
   alltalk",name,get_user_userid(id),authid)
       new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
       set_cvar_float("amx_last_voting",  get_gametime() + vote_time )
       vote_ratio = get_cvar_float("amx_alltalkvote_ratio")
       for(new a = 0; a < 33; a++){
           votecontroller[a][1] = 0
       }
       votenumber++
       set_cvar_string("amx_vote_inprogress","1")
       ejl_vault("WRITE","CURRENT_VOTE","ALLTALK")
       bVoteToStop = true
       totalvoters = 0
       new Team[33]
       new maxpl = get_maxplayers()+1
       for(new k = 1; k < maxpl; k++){
           get_user_team(k,Team,33)
           if(!((equali(Team,"UNAS",4))   ||  (equali(Team,"SPEC",4))  ||
   (get_user_time(k)== 0) )){
               show_menu(k,keys,menu_msg,floatround(vote_time))
               totalvoters++
           }
       }
       st_vote = 0
       set_task(vote_time,"HandleMXVote")
       client_print(id,print_console,"[AMX] Voting has started...")
       for(new j = 0; j < 4;++j) option[j] = 0
       }else{
       client_print(id,print_console,"[AMX]  Voting  not  allowed  yet.")
       }
       return PLUGIN_HANDLED
   }
   public vote_count(id,key){
       ejl_vault("READ","CURRENT_VOTE","")
       if(equal(vault_value,"ALLTALK")){
       new name[32]
       get_user_name(id,name,32)
       if(votenumber != votecontroller[id][0]){
           votecontroller[id][0] = votenumber
           if (get_cvar_float("amx_vote_answers")) {
               client_print(0,print_chat,"[AMX]  %s  voted  for  option #
   %d",name,key+1)
           }
           option[key] += 1
       }else{
           votecontroller[id][1] +=1
       }
       }else{
           return PLUGIN_CONTINUE
       }
       return PLUGIN_HANDLED
   }
   public HandleMXVote() {
       get_cvar_string("sv_alltalk",alltalk_cvar,16)
       set_hudmessage(63,187,239,  -1.0,  0.70, 2, 0.02, 10.0, 0.01, 0.1,
   4)
       set_cvar_string("amx_vote_inprogress","0")
       ejl_vault("WRITE","CURRENT_VOTE","NULL")
       bVoteToStop = false
       for(new a = 0; a < 33; a++){
           votecontroller[a][1] = 0
       }
       if(st_vote == 1){
           st_vote = 0
           client_print(0,print_chat,"[AMX]  Voting           sucessfully
   stopped.")
           return PLUGIN_HANDLED
       }
       new best = 0
       new best_count = 0
       for(new a = 0; a < 4; ++a) {
           if (option[a] > best_count){
               best_count = option[a]
               best = a
           }
       }
       new inum = totalvoters
       new  Float:result_v = inum ? (float(option[best]) / float(inum)) :
   0.0
       if (result_v >= vote_ratio) {
           if(best == 0){
               if(strtonum(alltalk_cvar) == 1) {
                   show_hudmessage(0,"Voting  Results:  alltalk will stay
   !!!^n^n%d   votes   to  keep  alltalk  enabled^n%d  votes  to  disable
   alltalk^n^n%d Total eligible voters",
                   option[0],option[1],totalvoters)
               } else {
                   show_hudmessage(0,"Voting   Results:  Alltalk  Enabled
   !!!^n^n%d  votes to enable alltalk^n%d votes to keep alltalk off^n^n%d
   Total eligible voters",
                   option[0],option[1],totalvoters)
                   set_cvar_string("sv_alltalk", "1")
               }
               log_to_file("addons/amx/admin.log","World        triggered
   ^"voting_success^"   (needed   ^"%.2f^")   (ratio   ^"%.2f^")  (result
   ^"alltalk^")",
                   vote_ratio,result_v)
           }else {
               if(         (strtonum(alltalk_cvar)         ==0)        ||
   (strtonum(alltalk_cvar) ==10)  ){
                   show_hudmessage(0,"Voting Results: Team only talk will
   remain^n^n%d  votes  to  enable  alltalk^n%d votes to keep normal team
   talk^n^n%d Total eligible voters",
                   option[0],option[1],totalvoters)
               } else {
                   show_hudmessage(0,"Voting     Results:    Team    talk
   only.^n^n%d  votes  to  keep alltalk enabled^n%d votes to turn alltalk
   back to team talk^n^n%d Total eligible voters",
                   option[0],option[1],totalvoters)
                   set_cvar_string("sv_alltalk", "0")
               }
               log_to_file("addons/amx/admin.log","World        triggered
   ^"voting_failure^" (needed ^"%.2f^") (ratio ^"%.2f^")",
                   vote_ratio,result_v)
           }
       }else{
           client_print(0,print_chat,"[AMX]  Voting for alltalk failed...
   No clear majority.")
       }
       return PLUGIN_HANDLED
   }
   public client_connect(id){
       votecontroller[id][1] = 0
   }
   public client_disconnect(id){
       votecontroller[id][1] = 0
   }
   public stopvote(id){
       if (!(get_user_flags(id)&ADMIN_MAP)){
           client_print(id,print_console,"[AMX]  You  have  no  access to
   that command")
           return PLUGIN_HANDLED
       }
       if(bVoteToStop == true){
           new name[32]
           get_user_name(id,name,32)
           st_vote = 1
           client_print(id,print_console,"[AMX]  ADMIN   !!!  Ignore  the
   unknown command message -- its ok")
           client_print(0,print_chat,"[AMX]  %s  has disabled the vote in
   progress.",name)
       }
       return PLUGIN_CONTINUE
   }
   public admin_vote_alltalk(id,level,cid) {
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       MXVote(id)
       return PLUGIN_HANDLED
   }
   public HandleSay(id) {
       new Speech[192]
       read_args(Speech,192)
       remove_quotes(Speech)
       if (containi(Speech, "alltalk")!=-1) {
           get_cvar_string("sv_alltalk",alltalk_cvar,16)
           set_hudmessage(0,255,0,  -1.0,  0.25, 2, 0.02, 7.0, 0.01, 0.1,
   2)
           if (strtonum(alltalk_cvar) == 1){
               show_hudmessage(0,"alltalk is on!")
           } else {
               show_hudmessage(0,"Boring normal talk is on now.")
           }
       }
       return PLUGIN_CONTINUE
   }
   public admin_alltalk(id,level,cid) {
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       if (read_argc() < 2){
           new onoff[4]
           get_cvar_string("sv_alltalk",alltalk_cvar,16)
           if(strtonum(alltalk_cvar) == 1){
               copy(onoff, 4, "ON")
           }else{
               copy(onoff, 4, "OFF")
           }
           console_print(id,"[AMX]   Usage:   amx_alltalk   <  on  |  off
   >     Currently: %s", onoff)
           return PLUGIN_HANDLED
       }
       new arg[10]
       read_argv(1,arg,10)
       if ( (equal(arg,"on", 2)) || (equal(arg,"1", 1)) ){
           set_cvar_string("sv_alltalk", "1")
           console_print(id,"[AMX] ALLTALK mode is now ON")
           client_print(0,print_chat,"[AMX] Admin has turned ALLTALK mode
   ON")
       }else{
           set_cvar_string("sv_alltalk", "0")
           console_print(id,"[AMX] ALLTALK mode is now OFF")
           client_print(0,print_chat,"[AMX] Admin has turned ALLTALK mode
   OFF")
       }
       new authid[16],name[32]
       get_user_authid(id,authid,16)
       get_user_name(id,name,32)
       log_to_file("addons/amx/admin.log","^"%s<%d><%s><>^"  alltalk_mode
   %s",name,get_user_userid(id),authid,arg)
       return PLUGIN_HANDLED
   }
   public plugin_init() {
       register_plugin("alltalk Plugin","1.0","Sy5tem")
       register_concmd("amx_votealltalk","admin_vote_alltalk")
       register_concmd("say vote_alltalk","admin_vote_alltalk")
       register_concmd("amx_alltalk","admin_alltalk",ADMIN_VOTE,"<#>    1
   turns alltalk on, 0 turns alltalk jumping off.")
       register_clcmd("stopvote","stopvote")
       register_clcmd("say","HandleSay")
       register_cvar("amx_last_voting","0")
       set_cvar_float("amx_last_voting",0.0)
       register_menucmd(register_menuid("Do     you     want     Alltalk?
   "),(1<<0)|(1<<1)|(1<<2)|(1<<3),"vote_count")
       register_cvar("amx_alltalkvote_ratio","0.70")
       register_cvar("amx_vote_inprogress","0")
       ejl_vault("WRITE","CURRENT_VOTE","NULL")
       return PLUGIN_CONTINUE
   }
   public ejl_vault(rw[],key[],value[]){
       new data[192]
       new stxtsize = 0
       new line = 0
       new skip = 0
       new vkey[64]
       new vvalue[128]
       new vaultwrite[192]
       if(equal(rw,"READ")){
           if(file_exists("addons/amx/ejl_vault.ini") == 1){
               copy(vault_value,128,"")
               while((line=read_file("addons/amx/ejl_vault.ini",line,data
   ,192,stxtsize))!=0){
                   parse(data,vkey,64,vvalue,128)
                   if(equal(vkey,key)){
                       copy(vault_value,128,vvalue)
                   }
               }
           }else{
               write_file("addons/amx/ejl_vault.ini",  "****  Plugins use
   to store values -- immune to crashes and map changes ****", 0)
           }
       }
       else if(equal(rw,"WRITE")){
           if(file_exists("addons/amx/ejl_vault.ini") == 1){
               format(vaultwrite,192,"%s %s",key,value)
               while((line=read_file("addons/amx/ejl_vault.ini",line,data
   ,192,stxtsize))!=0){
                   parse(data,vkey,64,vvalue,128)
                   if(skip == 0){
                       if( (equal(data,"")) || (equal(vkey,key)) ){
                           skip = 1
                           write_file("addons/amx/ejl_vault.ini",vaultwri
   te,line-1)
                       }
                   }
                   else if(equal(vkey,key)){
                       write_file("addons/amx/ejl_vault.ini","",line-1)
                   }
               }
               if(skip == 0){
                   write_file("addons/amx/ejl_vault.ini",vaultwrite,-1)
               }
           }
       }
       return PLUGIN_CONTINUE
   }
