/* This plugin enables alltalk votes and auto-responses. 
 * Based on yensid's FF code.
 */
 
/* $Id: plugin_vote_alltalk.sma,v 1.0 6/21/2002 -=[KS]=-BoogeyMan */
/* contact: ksclan@hotmail.com */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
#include <sound>
 
/* Change this to whatever ratio of players need to vote for a setting to change it. */
#define ALLTALK_VOTE_RATIO 51
 
/* Change to 1 to have a Friendly Fire vote start 160 seconds in to a map */
#define AUTO_ALLTALK_VOTE 0
 
#define ACCESS_VOTE_ALLTALK 1
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.0";
 
public ALLTALKVote() {
	new strDummy[10];
	vote("ALLTALK?", "Yes", "No", "HandleALLTALKVote",strDummy);
}
 
public HandleALLTALKVote(WinningOption,HLData,VoteCount,UserCount) {
	new Text[MAX_TEXT_LENGTH];
	new strNumber[MAX_NUMBER_LENGTH];
	new Ratio = ALLTALK_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_alltalk")==1) {
				playsoundall("misc\who.wav");
				centersay("Vote over.  Alltalk will remain enabled.",18,249,244,0);
			} else {
				playsoundall("misc\who.wav");
				centersay("Vote successful. Alltalk changed to enabled.^nTalk bitch Talk!",18,249,244,0);
				setstrvar("sv_alltalk","1");
			}
		} else {
			if(getvar("sv_alltalk")==1) {
				centersay("OK Ok...You got your way!^nAlltalk Is OFF...^nNow STFU:D",18,63,187,239);
				setstrvar("sv_alltalk","0");
			} else {
				centersay("Vote over.  Alltalk will remain disabled.",18,63,187,239);
			}
		}
	} else {
		numtostr(Ratio*UserCount/100,strNumber);
		if(getvar("sv_alltalk")==1) {
			playsoundall("misc\who.wav");
			snprintf(Text, MAX_TEXT_LENGTH, "Vote succeeded, but not enough votes for change (needed %s)^nAlltalk will remain enabled.", strNumber);
		} else {
			snprintf(Text, MAX_TEXT_LENGTH, "Vote succeeded, but not enough votes for change (needed %s)^nAlltalk will remain disabled.", strNumber);
		}
		centersay(Text,18,63,187,239);
	}
}
 
public admin_vote_Alltalk(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);		
	ALLTALKVote();
	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, "Alltalk on")!=-1) {
		Match = TRUE;
	} else if (strcasestr(Data, "Alltalk is on")!=-1) {
		Match = TRUE;
	} else if (strcasestr(Data, "Alltalk on")!=-1) {
		Match = TRUE;
	}
	if (Match==TRUE) {
		if (getvar("sv_alltalk") == 1){ 
			centersay ("Alltalk is ON! Talk you bitch!^nYou can even SCREAM!",7,0,255,0); 
		} else {
			centersay ("Alltalk is OFF.^nNow STFU :D ",7,0,255,0);
		}
	}
	if (strcasestr(Data, "vote_Alltalk")!=-1) {
		if (vote_allowed()!=1) {
			selfmessage( "Vote not allowed at this time.");
			return PLUGIN_HANDLED;
		}
		ALLTALKVote();
	}
	return PLUGIN_CONTINUE;
}
 
 
public plugin_init() {
	plugin_registerinfo("Alltalk Plugin","Enables Alltalk votes and auto-responses.",STRING_VERSION);
	plugin_registercmd("admin_vote_alltalk","admin_vote_alltalk",ACCESS_VOTE_ALLTALK,"admin_vote_alltalk : Starts a vote to enable/disable alltalk.");
	plugin_registercmd("say","HandleSay",ACCESS_ALL);
	plugin_registerhelp("say",ACCESS_ALL,"say alltalk on, alltalk is on, alltalk  on: Will give alltalk status.");
 
#if AUTO_ALLTALK_VOTE==1	
	if (vote_allowed()!=1) {
		selfmessage( "Vote not allowed at this time.");
		return PLUGIN_HANDLED;
	}
	set_timer("ALLTALKVote",160,1);
#endif
 
	return PLUGIN_CONTINUE;
}