/* Dont forget to input your server defaults (second set of exec's) or have a config file labeled after the map your on
The only possible downfall is that for the plugin to decide if a sniperwar is already activated you must not turn make snipers infinite.
If you want unlimited snipers then make the limit 50 (cr_sniper 50) instead of infinite (cr_sniper 0)
Made by: Bryan Clay*/
 
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
#define SNIPER_VOTE_RATIO 50
 
#define ACCESS_VOTE_SNIPER 0
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.1";
 
public SniperVote() {
	new strDummy[10];
	vote("Have a Sniperwar?", "Yes", "No", "HandleSniperVote",strDummy);
}
 
public HandleSniperVote(WinningOption,HLData,VoteCount,UserCount) {
	new Text[MAX_TEXT_LENGTH];
	new strNumber[MAX_NUMBER_LENGTH];
	new Ratio = SNIPER_VOTE_RATIO;
	new strData[MAX_DATA_LENGTH];
	new Current[MAX_DATA_LENGTH];
	convert_string(HLData, strData,MAX_DATA_LENGTH);
	currentmap(Current,MAX_NAME_LENGTH);
	if (VoteCount >= Ratio*UserCount/100) {	
		if (WinningOption==1) {
			if(getvar("cr_sniper")==0) {
				centersay("Vote over.  Sniperwar will remain enabled.",18,249,244,0);
			} else {
				centersay("Vote successful. Sniperwar enabled.",18,249,244,0);
				changelevel(Current);
				exec("cr_sniper 0");
				exec("cr_spy -1");
				exec("cr_pyro -1");
				exec("cr_demoman -1");
				exec("cr_scout -1");
				exec("cr_medic -1");
				exec("cr_hwguy -1");
				exec("cr_engineer -1");
				exec("cr_soldier -1");
			}
		} else {
			if(getvar("cr_sniper")==0) {
				centersay("OK Ok...You got your way!^nSniperwar Is OFF",18,63,187,239);
				exec("cr_sniper 2");
				exec("cr_spy 0");
				exec("cr_pyro 0");
				exec("cr_demoman 0");
				exec("cr_scout 0");
				exec("cr_medic 0");
				exec("cr_hwguy 1");
				exec("cr_engineer 0");
				exec("cr_soldier 0");
				changelevel(Current);
			} else {
				centersay("Vote over.  Sniperwar will remain disabled.",18,63,187,239);
			}
		}
	} else {
		numtostr(Ratio*UserCount/100,strNumber);
		if(getvar("cr_sniper")==0) {
			snprintf(Text, MAX_TEXT_LENGTH, "Vote succeeded, but not enough votes for change (needed %s)^nSniperwar will remain enabled.", strNumber);
		} else {
			snprintf(Text, MAX_TEXT_LENGTH, "Vote succeeded, but not enough votes for change (needed %s)^nSniperwar will remain disabled.", strNumber);
		}
		centersay(Text,18,63,187,239);
	}
	return PLUGIN_CONTINUE;
}
 
public admin_vote_sniper(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
 
	if (vote_allowed()!=1) {
		selfmessage( "Vote not allowed at this time.");
		return PLUGIN_HANDLED;
	}
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	selfmessage("You started a sniperwar vote");
	SniperVote();
	return PLUGIN_HANDLED;
}
 
public plugin_init() {
	plugin_registerinfo("Sniperwar Plugin","Enables sniperwar voting.",STRING_VERSION);
	plugin_registercmd("admin_vote_sniper","admin_vote_sniper",ACCESS_VOTE_SNIPER,"admin_vote_sniper : Starts a vote to enable/disable a sniperwar");
	return PLUGIN_CONTINUE;
}