/* This plugin enables matrix votes by clients and auto-responses. 
 * Note: you might want to turn your vote_freq down to 15 or 30 in server.cfg if your going to have a lot of voting happening (FF, Grav, other ect.)
 */
 
/* $Id: plugin_matrix.sma,v 1.0b 2001/04/12 by Shady Milmman $ */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
/* Change this to whatever ratio of players need to vote for a setting to change it. */
#define MX_VOTE_RATIO 40
 
/* Change to 1 to have a gravity vote start 30 seconds in to a map */
#define AUTO_MX_VOTE 0
 
#define ACCESS_VOTE_MX 1
#define ACCESS_FUN 8192
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.0";
 
public MXVote() {
	new strDummy[10];
	if(vote_allowed()!=1){
		selfmessage("Voting not allowed at this time.");
		return PLUGIN_HANDLED;
	}
	if (getvar("admin_fun_mode")==0) {
		selfmessage("The Matrix Jumping can only be turned on during fun mode.");
		return PLUGIN_HANDLED;
	}
	vote("Do you want Matrix style jumping?", "Hand me the red pill!", "No thanks", "HandleMXVote",strDummy);
	return PLUGIN_HANDLED;
}
 
public HandleMXVote(WinningOption,HLData,VoteCount,UserCount) {
	new Text[MAX_TEXT_LENGTH];
	new strNumber[MAX_NUMBER_LENGTH];
	new Ratio = MX_VOTE_RATIO;
	new strData[MAX_DATA_LENGTH];
	convert_string(HLData, strData,MAX_DATA_LENGTH);
 
	if (VoteCount >= Ratio*UserCount/100) {	
		if (WinningOption==1) {
			if(getvar("sv_airaccelerate")==-15) {
				centersay("Vote over. Matrix will stay.",18,249,244,0);
			} else {
				centersay("Vote successful. Welcome to the Matrix",18,249,244,0);
				exec("sv_airaccelerate -15");
			}
		} else {
			if(getvar("sv_airaccelerate")==-15) {
				centersay("Vote over. Welcome back, Neo.",18,63,187,239);
				exec("sv_airaccelerate 15");
			} else {
				centersay("Vote over.  Normal jumping will remain.",18,63,187,239);
			}
		}
	} else {
		numtostr(Ratio*UserCount/100,strNumber);
		if(getvar("sv_airaccelerate")==-15) {
			snprintf(Text, MAX_TEXT_LENGTH, "Matrix vote succeeded, but not enough votes for change (needed %s)^nMatrix jumping will stay.", strNumber);
		} else {
			snprintf(Text, MAX_TEXT_LENGTH, "Matrix vote succeeded, but not enough votes for change (needed %s)^nNormal jumping will remain.", strNumber);
		}
		centersay(Text,18,63,187,239);
	}
}
 
public admin_vote_matrix(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_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);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	say_command(User,Command,Data);		
	MXVote();
	return PLUGIN_HANDLED;
}
 
public HandleSay(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
 
	strstripquotes(Data);
	new Match = FALSE;
	if (strcasestr(Data, "vote_matrix")!=-1) { 
		MXVote(); 
		return PLUGIN_CONTINUE;
	}
	if (strcasestr(Data, "matrix")!=-1) {
		Match = TRUE;
		}
	if (Match==TRUE) {
		if (getvar("sv_airaccelerate") == -15){ 
			centersay ("Matrix jumping is on!^n To change say vote_matrix!",7,0,255,0); 
		} else {
			centersay ("Boring normal jumping is on now. ^n To change say vote_matrix. ",7,0,255,0);
		}
	}
	return PLUGIN_CONTINUE;
}
public admin_matrix(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if(check_param(Data)==1) {
		execute_command(User,Command,"sv_airaccelerate","-15");
		centersay ("Matrix jumping is on!^n To change say vote_matrix!",7,0,255,0); 
	} else {
		execute_command(User,Command,"sv_airaccelerate","15");
		centersay ("Boring normal jumping is on now. ^n To change say vote_matrix. ",7,0,255,0);
	}
	MXVote();
	return PLUGIN_HANDLED;
}
 
public plugin_init() {
	plugin_registerinfo("Matrix Plugin","Enables Matrix vote on/off and auto-responses.",STRING_VERSION);
	plugin_registercmd("admin_vote_matrix","admin_vote_matrix",ACCESS_VOTE_MX,"admin_vote_gravity : Starts a vote to enable matrix style jumping.");
	plugin_registercmd("admin_matrix","admin_matrix",ACCESS_FUN,"admin_matrix <#> 1 turns matrix on, 0 turns matrix jumping off.");
	plugin_registercmd("say","HandleSay",ACCESS_ALL);
	plugin_registerhelp("say",ACCESS_ALL,"say matrix: Will give matrix status, Clients say vote_matrix will start vote.");
	plugin_registerhelp("say",ACCESS_ALL,"say vote_matrix: Will start matrix vote.");
 
#if AUTO_MX_VOTE==1	
	set_timer("MXVote",30,1);
#endif
 
	return PLUGIN_CONTINUE;
}