Try :
PHP Code:
//Add these 2 defines at the top of your plugin
#define TIME 10.0 //This is time after results will be checked, you can change it's value
#define TASK_CHECK 6459 //This is task id used to check if another task is not in process
public vote()
{
if(task_exists(TASK_CHECK)){
return PLUGIN_HANDLED
} //Blocking vote if another one is started or is in process
new ad[32],sznum[6]
new menu = menu_create("\rVote For CT","vote_handler")
for(new i = 1;i<=get_maxplayers();i++)
if(is_user_connected(i) && get_user_team(i) == 2)
{
num_to_str(i,sznum,5)
get_user_name(i,ad,31)
menu_additem(menu,ad,sznum)
}
arrayset(g_votes, 0 , 33)//Cleaning the array before vote
menu_display(id,menu, 0)
set_task(TIME, check_result, TASK_CHECK) //Setting a task to check our results
return PLUGIN_HANDLED
}
public vote_handler(id,menu,item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new ad[32],callback,access,data[6]
menu_item_getinfo(menu,item,access,data,5,ad,31,callback)
new tid = str_to_num(data)
g_votes[tid]++
}
public check_results(){
new leader;
for(new i; i < 33; i++){
for(new j; j < 33; j++){
if(g_votes[i] < g_votes[j])
break;
if(j==32)
leader=g_votes[i]
}
}
if(is_user_connected(leader))
{
name[32]
get_user_name(leader, name, 31)
client_print(0, print_chat, "[VOTE RESULT] The most voted player is ^"%s^"", name)
}else{
client_print(0, print_chat, "[VOTE RESULT] Vote has failed. Player is not connected")
}
}