/* plugin_cavey_funkyvote.sma version 0.1, By Caveman ICQ# 70710878
                    Please read the readme                          */
 
 
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.11";
 
new Voted[MAX_PLAYERS];
new Vote1;
new Vote2;
new GTimer = 0;
 
public plugin_init() {
	/*Vote commands to cover with this method*/
	plugin_registercmd("admin_vote_kick","VoteMonitor",ACCESS_ALL,"");
	plugin_registercmd("admin_vote_map","VoteMonitor",ACCESS_ALL,"");
	plugin_registercmd("admin_vsay","VoteMonitor",ACCESS_ALL,"");
 
	plugin_registerinfo("Cavey's funky vote plugin","Makes votes that little bit funkier",STRING_VERSION);
 
	plugin_registercmd("menuselect","VoteResponse",ACCESS_ALL,"");
	plugin_registercmd("admin_cancel_vote","admin_cancel_vote",ACCESS_KICK,"");
 
	return PLUGIN_CONTINUE;
}
 
 
public VoteMonitor(HLCommand, HLData, HLUserName, UserIndex){
	new i;
 
	if (vote_allowed()!=1) {
		return PLUGIN_CONTINUE;
	}
	for (i=0;i<=MAX_PLAYERS;i++){
		Voted[i] = 0;
	}
	if (GTimer != 0){
		kill_timer(GTimer);
	}
	Vote1=0;
	Vote2=0;
	GTimer = set_timer("VoteDisplay", 1, 30, "");
 
	return PLUGIN_CONTINUE;
 
}
 
public admin_cancel_vote(HLCommand, HLData, HLUserName, UserIndex){
	kill_timer(GTimer);
	typesay("[Admin] Vote cancelled by admin", 10, 250, 250, 250);
	return PLUGIN_CONTINUE;
}
 
public VoteDisplay(Timer,Repeat,HLUser,HLParam){
	new Text[MAX_TEXT_LENGTH];
 
	strinit(Text);
	snprintf(Text, MAX_TEXT_LENGTH, "Vote time remaining:- %d^nCurrent results:-^n%d - Yes^n%d - No", Repeat-1, Vote1, Vote2);
	typesay(Text, 1, 250, 250, 250);
}
 
public VoteResponse(HLCommand, HLData, HLUserName, UserIndex){
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new int;
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
 
	if ( Voted[UserIndex] == 1 ) {
		return PLUGIN_CONTINUE;
	}
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	int = strtonum(Data);
	if (int == 1){
		Vote1++;
		Voted[UserIndex] = 1;
		return PLUGIN_CONTINUE;
	} else if ( int == 2 ){
		Vote2++;
		Voted[UserIndex] = 1;
		return PLUGIN_CONTINUE;
	} else {
		return PLUGIN_CONTINUE;
	}
	return PLUGIN_CONTINUE;
}