Код:
//**********************************************************************
// AUTOVOTE FUNCTIONS
//**********************************************************************
// start the autovote
public autovote_start()
{
// vote in progress
if(autovotes[0] || autovotes[1] || autovotes[2] || task_exists(TASK_AUTOVOTE_RESULT)) return 0;
// if autovote_mode < 0, we haven't actually checked it yet
if(autovote_mode < 0)
{
new info[6];
get_localinfo("gg_av_iter",info,5);
new iter = str_to_num(info);
new rotation[32];
get_pcvar_string(gg_autovote_mode,rotation,31);
new amount = str_count(rotation,',')+1;
if(iter <= 0 || iter > amount)
{
iter = 1;
set_localinfo("gg_av_iter","1");
}
// no rotation, just use the given value
if(amount <= 1)
{
if(iter != 1) set_localinfo("gg_av_iter","1");
autovote_mode = str_to_num(rotation);
}
else
{
for(new i=1;i<=amount;i++)
{
if(contain(rotation,",") != -1)
{
strtok(rotation,info,5,rotation,31,',');
if(i == iter) // this is the one we're looking for
{
autovote_mode = str_to_num(info);
break;
}
}
else // we've stripped away everything else and are left with the last one, so use it
{
autovote_mode = str_to_num(rotation);
break;
}
}
iter++;
if(iter > amount) iter = 1;
num_to_str(iter,info,5);
set_localinfo("gg_av_iter",info);
}
}
// turns out it's disabled
if(autovote_mode <= 0) return 0;
new Float:autovote_time = get_pcvar_float(gg_autovote_time);
new i;
for(i=1;i<=maxPlayers;i++)
{
if(!is_user_connected(i)) continue;
switch(autovote_mode)
{
case 1:
{
formatex(menuText,511,"\y%L^n^n\w1. %L^n2. %L^n^n0. %L",i,"PLAY_GUNGAME",i,"YES",i,"NO",i,"CANCEL");
show_menu(i,MENU_KEY_1|MENU_KEY_2|MENU_KEY_0,menuText,floatround(autovote_time),"autovote_menu");
}
case 2:
{
formatex(menuText,511,"\y%L^n^n\w1. %L^n2. %L^n^n0. %L",i,"PLAY_GUNGAME",i,"YES_TEAMPLAY",i,"YES_REGULAR",i,"CANCEL");
show_menu(i,MENU_KEY_2|MENU_KEY_1|MENU_KEY_0,menuText,floatround(autovote_time),"autovote_menu");
}
default:
{
formatex(menuText,511,"\y%L^n^n\w1. %L^n2. %L^n3. %L^n^n0. %L",i,"PLAY_GUNGAME",i,"YES_TEAMPLAY",i,"YES_REGULAR",i,"NO",i,"CANCEL");
show_menu(i,MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_0,menuText,floatround(auto
vote_time),"autovote_menu");
}
}
}
gungame_print(0,0,1,"%L",LANG_PLAYER_C,"VOTING_STARTED");
set_task(autovote_time,"autovote_result",TASK_AUTOVOTE_RESULT);
return 1;
}
// take in votes
public autovote_menu_handler(id,key)
{
switch(key)
{
case 0: // 1.
{
/* MODE 1- YES
MODE 2- YES_TEAMPLAY
MODE 3- YES_TEAMPLAY */
autovotes[0]++;
}
case 1: // 2.
{
/* MODE 1- NO
MODE 2- YES_REGULAR
MODE 3- YES_REGULAR */
if(autovote_mode == 1) autovotes[2]++;
else autovotes[1]++;
}
case 2: // 3.
{
/* MODE 1-
MODE 2-
MODE 3- NO */
autovotes[2]++;
}
//case 9: 0. /* ALL MODES- CANCEL */ let menu close
}
return PLUGIN_HANDLED;
}
// calculate end of vote, some of this was thanks to VEN
public autovote_result()
{
new vYes = autovotes[0] + autovotes[1], vNo = autovotes[2], vTotal = vYes + vNo, vSuccess, teamplay = get_pcvar_num(gg_teamplay), key[16];
switch(autovote_mode)
{
case 1: // this mode asks if they want to play GunGame, yes/no
{
if(vTotal)
{
if(float(vYes) / float(vTotal) >= get_pcvar_float(gg_autovote_ratio))
vSuccess = 1;
// the choice that changes the current game mode is the one that needs to meet the ratio. so if you are
// playing GunGame, at least however many people as defined by the ratio need to vote for it off to switch it,
// and vice-versa.
if( ( ggActive && (float(vNo) / float(vTotal)) < get_pcvar_float(gg_autovote_ratio))
|| (!ggActive && (float(vYes) / float(vTotal)) >= get_pcvar_float(gg_autovote_ratio)) )
vSuccess = 1; // means that we will be playing GunGame
}
else if(ggActive) vSuccess = 1;
if(vSuccess && !ggActive)
{
restart_round(5);
set_task(4.8,"toggle_gungame",TASK_TOGGLE_GUNGAME+TOGGLE_ENABLE);
}
else if(!vSuccess && ggActive)
{
restart_round(5);
set_task(4.8,"toggle_gungame",TASK_TOGGLE_GUNGAME+TOGGLE_DISABLE);
set_pcvar_num(gg_enabled,0);
ggActive = 0;
}
if(vSuccess && teamplay) key = "AUTOVOTE_RES1";
else if(vSuccess && !teamplay) key = "AUTOVOTE_RES2";
else key = "AUTOVOTE_RES3";
gungame_print(0,0,1,"%L %i %L - %i %L - %L :: %L",LANG_PLAYER_C,"PLAY_GUNGAME",vYes,LANG_PLAYER_C,"YES",vNo,LANG_PLAYER_C,"NO",LANG_PLAYER_C,"THE_RESULT",LANG_PLAYER_C,key);
}
case 2: // this mode asks if they want to play teamplay, yes/no
{
if(!ggActive)
{
restart_round(5);
set_task(4.8,"toggle_gungame",TASK_TOGGLE_GUNGAME+TOGGLE_ENABLE);
}
if(vTotal)
{
// see above comment
if( ( teamplay && (float(autovotes[1]) / float(vTotal)) < get_pcvar_float(gg_autovote_ratio))
|| (!teamplay && (float(autovotes[0]) / float(vTotal)) >= get_pcvar_float(gg_autovote_ratio)) )
vSuccess = 1; // means that we will be playing teamplay mode
}
else if(teamplay) vSuccess = 1;
if(vSuccess)
{
if(!teamplay)
{
set_pcvar_num(gg_teamplay,1);
if(ggActive && warmup <= 0) restart_round(3);
exec_gg_config_file(0,0);
exec_gg_config_file(1,0);
}
set_task(4.9,"force_teamplay",1);
}
else if(!vSuccess)
{
if(teamplay)
{
set_pcvar_num(gg_teamplay,0);
if(ggActive && warmup <= 0) restart_round(3);
exec_gg_config_file(0,0);
}
set_task(4.9,"force_teamplay",0);
}
if(vSuccess) key = "AUTOVOTE_RES1";
else key = "AUTOVOTE_RES2";
gungame_print(0,0,1,"%L %i %L - %i %L - %L :: %L",LANG_PLAYER_C,"PLAY_GUNGAME",autovotes[0],LANG_PLAYER_C,"YES_TEAMPLAY",autovotes[1],LANG_PLAYER_C,"YES_REGULAR",LANG_PLAYER_C,"THE_RESULT",LANG_PLAYER_C,key);
}
default: // this mode asks if they want to play, teamplay/regular/no
{
if(vTotal)
{
// see above comment
if( ( ggActive && (float(vNo) / float(vTotal)) < get_pcvar_float(gg_autovote_ratio))
|| (!ggActive && (float(vYes) / float(vTotal)) >= get_pcvar_float(gg_autovote_ratio)) )
vSuccess = 1; // means that we will be playing GunGame
}
else if(ggActive) vSuccess = 1;
if(vSuccess)
{
if(!ggActive)
{
restart_round(5);
set_task(4.8,"toggle_gungame",TASK_TOGGLE_GUNGAME+TOGGLE_ENABLE);
}
// pick a random value for teamplay if we need it, then see if we should be using it.
// use it in the case that we have a tie, and we are using random teamplay mode.
new rand_val = random_num(0,1);
new use_rand = (autovotes[0] == autovotes[1] && (teamplay == 2 || initTeamplayInt == 2));
if(autovotes[0] > autovotes[1] || (use_rand && rand_val == 1)) // more votes for teamplay
{
if(!teamplay)
{
set_pcvar_num(gg_teamplay,1);
if(ggActive && warmup <= 0) restart_round(3);
exec_gg_config_file(0,0);
exec_gg_config_file(1,0);
}
key = "AUTOVOTE_RES1";
set_task(4.9,"force_teamplay",1);
}
else if(autovotes[0] < autovotes[1] || (use_rand && rand_val == 0)) // more votes for regular
{
if(teamplay)
{
set_pcvar_num(gg_teamplay,0);
if(ggActive && warmup <= 0) restart_round(3);
exec_gg_config_file(0,0);
}
key = "AUTOVOTE_RES2";
set_task(4.9,"force_teamplay",0);
}
else // if equal, leave it be
{
if(teamplay)
{
key = "AUTOVOTE_RES1";
set_task(4.9,"force_teamplay",1);
}
else
{
key = "AUTOVOTE_RES2";
set_task(4.9,"force_teamplay",0);
}
}
}
else if(!vSuccess && ggActive)
{
restart_round(5);
set_task(4.8,"toggle_gungame",TASK_TOGGLE_GUNGAME+TOGGLE_DISABLE);
set_pcvar_num(gg_enabled,0);
ggActive = 0;
}
if(!vSuccess) key = "AUTOVOTE_RES3";
gungame_print(0,0,1,"%L %i %L - %i %L - %i %L - %L :: %L",LANG_PLAYER_C,"PLAY_GUNGAME",autovotes[0],LANG_PLAYER_C,"YES_TEAMPLAY",autovotes[1],LANG_PLAYER_C,"YES_REGULAR",vNo,LANG_PLAYER_C,"NO",LANG_PLAYER_C,"THE_RESULT",LANG_PLAYER_C,key);
}
}
autovotes[0] = 0;
autovotes[1] = 0;
autovotes[2] = 0;
}
// force teamplay mode to what we want after a vote has been completed.
// otherwise, when switching from GunGame off to on, it will be overwritten by gungame.cfg.
public force_teamplay(teamplay)
{
set_pcvar_num(gg_teamplay,teamplay);
exec_gg_config_file(0,0);
if(teamplay) exec_gg_config_file(1,0);
}