Code:
#include <amxmodx>
#include <amxmisc>
// array of votes - votes[1] is yes and votes[0] is no
new votes[2];
public plugin_init() {
register_plugin("Eargh!","0.10","Catwoman?!$4");
register_menucmd(register_menuid("voting"),1023,"voting_handler");
register_concmd("amx_dotehvote","cmd_dotehvote",ADMIN_VOTE,"- starts teh votez0rz!");
register_cvar("amx_vote_time","20.0");
}
public cmd_dotehvote(id,level,cid) {
if(!cmd_access(id,level,cid,1)) {
return PLUGIN_HANDLED;
}
new menubody[128], keys;
format(menubody,127,"Do you like d00ds wit teh swurd?^n^n1. Yesergh^n2. Noes");
keys = MENU_KEY_1|MENU_KEY_2;
// player, keys, text, hold time, title
show_menu(id,keys,menubody,get_cvar_num("amx_vote_time"),"voting");
set_task(get_cvar_float("amx_vote_time"),"display_results");
return PLUGIN_HANDLED;
}
public voting_handler(id,key) {
// number they pressed -> key variable
// 1 -> 0
// 2 -> 1
// 3 -> 2
// ...
// 8 -> 7
// 9 -> 8
// 0 -> 9
// if they voted yes
if(key == 0) {
votes[0]++;
}
// if they voted no
if(key == 1) {
votes[1]++;
}
// if we should display their choices
if(get_cvar_num("amx_vote_answers")) {
new username[32];
get_user_name(id,username,31);
client_print(0,print_chat,"%s voted %s",username,(key == 0) ? "Yes" : "No");
}
}
public display_results() {
client_print(0,print_chat,"Voting results: %i Yes -- %i No",votes[0],votes[1]);
votes[0] = 0;
votes[1] = 0;
}