/* This plugin contains commands to vote to Llama or Gag or even Un-Llama, Un-Gag people that the public on your server don't like */
 
/* Commands:
admin_vote_gag <name> : Votes to gag someone
admin_vote_ungag <name> : Votes to ungag a gaged person
admin_vote_llama <name> : Votes to llama someone
admin_vote_unllama <name> : Votes to unllama a llamad person
*/
 
/* Access Required to use the Commands: 8192 (This is because i figure you   dont want people on your server llamaing and gaging people all over. Only   admins can use it and it logs who has used the commands in a file 'Logs.txt'. */
 
/* How to install: Compile the plugins as described in the Documentation (As you normaly would).  Place 'Logs.txt' into your CSTRIKE folder */
 
/* Should be steam compatible now. Untested! [WING] Black Knight */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
#define ACCESS_VOTE_GAG ACCESS_VOTE_KICK
#define ACCESS_VOTE_UNGAG 2
#define GAG_VOTE_RATIO 55
#define UNGAG_VOTE_RATIO 55
#define ACCESS_VOTE_LLAMA ACCESS_VOTE_KICK
#define LLAMA_VOTE_RATIO 51
#define ACCESS_VOTE_UNLLAMA 2
#define UNLLAMA_VOTE_RATIO 51
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.07";
new LogFile[]="Logs.txt";
 
public HandleGagVote(WinningOption,HLUser,VoteCount,UserCount) {
	new strNumber[MAX_NUMBER_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new Ratio = GAG_VOTE_RATIO;
	new VoteTarget[MAX_NAME_LENGTH];
	convert_string(HLUser,VoteTarget,MAX_NAME_LENGTH);
 
	if (WinningOption == 1) {
		if (VoteCount >= Ratio*UserCount/100) {
			snprintf(Text, MAX_TEXT_LENGTH, "%s is now gaged and he will not be able to 'say' anymore", VoteTarget);
			say(Text);
			message(VoteTarget,"You are now gaged");
			plugin_exec("admin_gag",VoteTarget);
		} else {
			numtostr(Ratio*UserCount/100,strNumber);
			snprintf(Text, MAX_TEXT_LENGTH, "Gag vote succeded but not enough for Gag (needed %s)",strNumber);
			say(Text);
		}
	} else {
		say("Gag vote failed.");
	}
}
 
public admin_vote_gag(HLCommand,HLData,HLUser,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new strAuthID[MAX_AUTHID_LENGTH];
 
	if (vote_allowed()!=1) {
		snprintf(Text, MAX_TEXT_LENGTH, "Sorry but you cannot open a vote right now", User);
		say(Text);
		return PLUGIN_HANDLED;
	}
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUser,User,MAX_NAME_LENGTH);
	if (check_user(Data) == 1) {
		new real_user[MAX_NAME_LENGTH];
		get_username(Data,real_user,MAX_NAME_LENGTH);
		say_command(User,Command,Data);
		snprintf(Text, MAX_TEXT_LENGTH, "[ADMIN] %s used %s %s.", User, Command, Data);
		if(check_immunity(real_user)!=0) {
			snprintf(Text, MAX_TEXT_LENGTH, "Laf. you cant vote gag %s. You silly bear.", real_user);
			say(Text);
		} else {
			snprintf(Text, MAX_TEXT_LENGTH, "Gag %s and shut his mouth?", real_user);
			if(getvar("sv_lan")==1) {
				vote(Text,"Gag Him!","Dont Gag Him","HandleGagVote",real_user);
			} else {
				get_userAuthID(real_user,strAuthID);
				vote(Text,"Gag Him!","Dont Gag Him!","HandleGagVote",strAuthID);
			}
		}
	} else {
		selfmessage("Unrecognized user name ");
		selfmessage(Data);
	}
	return PLUGIN_HANDLED;
}
 
public HandleUnGagVote(WinningOption,HLUser,VoteCount,UserCount) {
	new strNumber[MAX_NUMBER_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new Ratio = UNGAG_VOTE_RATIO;
	new VoteTarget[MAX_DATA_LENGTH];
	convert_string(HLUser,VoteTarget,MAX_DATA_LENGTH);
 
	if (WinningOption == 1) {
		if (VoteCount >= Ratio*UserCount/100) {
			snprintf(Text, MAX_TEXT_LENGTH, "%s is not gaged anymore he can now talk.", VoteTarget);
			say(Text);
			message(VoteTarget,"You are now gaged");
			plugin_exec("admin_ungag",VoteTarget);
		} else {
			numtostr(Ratio*UserCount/100,strNumber);
			snprintf(Text, MAX_TEXT_LENGTH, "Un-Gag vote succeded but not enough for Gag (needed %s)",strNumber);
			say(Text);
		}
	} else {
		say("Un-Gag vote failed.");
	}
}
 
public admin_vote_ungag(HLCommand,HLData,HLUser,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new strAuthID[MAX_AUTHID_LENGTH];
 
	if (vote_allowed()!=1) {
		snprintf(Text, MAX_TEXT_LENGTH, "Sorry %s but you cannot open a vote right now", User);
		say(Text);
		return PLUGIN_HANDLED;
	}
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUser,User,MAX_NAME_LENGTH);
	if (check_user(Data) == 1) {
		new real_user[MAX_NAME_LENGTH];
		get_username(Data,real_user,MAX_NAME_LENGTH);
		say_command(User,Command,Data);
		snprintf(Text, MAX_TEXT_LENGTH, "[ADMIN] %s used %s %s.", User, Command, Data);
		writefile(LogFile, Text);
		if(check_immunity(real_user)!=0) {
			snprintf(Text, MAX_TEXT_LENGTH, "Laf. you cant vote ungag %s. You silly bear.", real_user);
			say(Text);
		} else {
			snprintf(Text, MAX_TEXT_LENGTH, "Un-Gag %s he will be allowed to speak again?", real_user);
			if(getvar("sv_lan")==1) {
				vote(Text,"Un Gag him!","Dont Un Gag Him!","HandleGagVote",real_user);
			} else {
				get_userAuthID(real_user,strAuthID);
				vote(Text,"Un Gag Him!","Dont Un Gag Him!","HandleGagVote",strAuthID);
			}
		}
	} else {
		selfmessage("Unrecognized user name ");
		selfmessage(Data);
	}
	return PLUGIN_HANDLED;
}
 
public HandleLlamaVote(WinningOption,HLUser,VoteCount,UserCount) {
	new strNumber[MAX_NUMBER_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new Ratio = LLAMA_VOTE_RATIO;
	new VoteTarget[MAX_NAME_LENGTH];
	convert_string(HLUser,VoteTarget,MAX_NAME_LENGTH);
 
	if (WinningOption == 1) {
		if (VoteCount >= Ratio*UserCount/100) {
			snprintf(Text, MAX_TEXT_LENGTH, "%s was turned into a llama due to a vote", VoteTarget);
			say(Text);
			message(VoteTarget,"You are now a llama");
			plugin_exec("admin_llama",VoteTarget);
		} else {
			numtostr(Ratio*UserCount/100,strNumber);
			snprintf(Text, MAX_TEXT_LENGTH, "Llama vote succeded but not enough for Llama (needed %s)",strNumber);
			say(Text);
		}
	} else {
		say("Llama vote failed.");
	}
}
 
public admin_vote_llama(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Voter[MAX_NAME_LENGTH];
	new strAuthID[MAX_AUTHID_LENGTH];
 
	if (vote_allowed()!=1) {
		snprintf(Text, MAX_TEXT_LENGTH, "Sorry %s but you cannot open a vote right now", Voter);
		say(Text);
		return PLUGIN_HANDLED;
	}
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if (check_user(Data) == 1) {
		new real_user[MAX_NAME_LENGTH];
		get_username(Data,real_user,MAX_NAME_LENGTH);
		say_command(User,Command,Data);
		snprintf(Text, MAX_TEXT_LENGTH, "[ADMIN] %s used %s %s.", User, Command, Data);
		writefile(LogFile, Text);
		if(check_immunity(real_user)!=0) {
			snprintf(Text, MAX_TEXT_LENGTH, "Laf. you cant make %s into a llama", real_user);
			say(Text);
		} else {
			snprintf(Text, MAX_TEXT_LENGTH, "Turn %s into a llama", real_user);
			if(getvar("sv_lan")==1) {
				vote(Text,"Yes Llama Him!","Dont Llama Him!","HandleLlamaVote",real_user);
			} else {
				get_userAuthID(real_user,strAuthID);
				vote(Text,"Yes Llama Him!","Dont Llama Him!","HandleLlamaVote",strAuthID);
			}
		}
	} else {
		selfmessage("Unrecognized user name ");
		selfmessage(Data);
	}
	return PLUGIN_HANDLED;
}
 
public HandleUnLlamaVote(WinningOption,HLUser,VoteCount,UserCount) {
	new strNumber[MAX_NUMBER_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new Ratio = UNLLAMA_VOTE_RATIO;
	new VoteTarget[MAX_NAME_LENGTH];
	convert_string(HLUser,VoteTarget,MAX_NAME_LENGTH);
 
	if (WinningOption == 1) {
		if (VoteCount >= Ratio*UserCount/100) {
			snprintf(Text, MAX_TEXT_LENGTH, "Due to a vote %s will no longer be a llama", VoteTarget);
			say(Text);
			message(VoteTarget,"You are human again");
			plugin_exec("admin_unllama",VoteTarget);
		} else {
			numtostr(Ratio*UserCount/100,strNumber);
			snprintf(Text, MAX_TEXT_LENGTH, "Un-Llama vote succeded but not enough for Un-Llama (needed %s)",strNumber);
			say(Text);
		}
	} else {
		say("Un-Llama vote failed.");
	}
}
 
public admin_vote_unllama(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
	new strAuthID[MAX_NUMBER_LENGTH];
 
	if (vote_allowed()!=1) {
		snprintf(Text, MAX_TEXT_LENGTH, "Sorry %s but you cannot open a vote right now", User);
		say(Text);
		return PLUGIN_HANDLED;
	}
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if (check_user(Data) == 1) {
		new real_user[MAX_NAME_LENGTH];
		get_username(Data,real_user,MAX_NAME_LENGTH);
		say_command(User,Command,Data);
		snprintf(Text, MAX_TEXT_LENGTH, "[ADMIN] %s used %s %s.", User, Command, Data);
		writefile(LogFile, Text);
		if(check_immunity(real_user)!=0) {
			snprintf(Text, MAX_TEXT_LENGTH, "Laf. you cant make %s back into a human", real_user);
			say(Text);
		} else {
			snprintf(Text, MAX_TEXT_LENGTH, "Turn %s back into a llama", real_user);
			if(getvar("sv_lan")==1) {
				vote(Text,"Yes Make him Human","No Leave Him As Llama","HandleKickVote",real_user);
			} else {
				get_userAuthID(real_user,strAuthID);
				vote(Text,"Yes Make him Human","No Leave Him As Llama","HandleKickVote",strAuthID);
			}
		}
	} else {
		selfmessage("Unrecognized user name ");
		selfmessage(Data);
	}
	return PLUGIN_HANDLED;
}
 
public plugin_init() {
plugin_registerinfo("Admin llama Voteing Plugin","Allows you to open llama votes",STRING_VERSION);
 
plugin_registercmd("admin_vote_gag","admin_vote_gag",ACCESS_VOTE_GAG,"admin_vote_gag <name|wonid> : Opens a vote to gag someone");
 
plugin_registercmd("admin_vote_ungag","admin_vote_ungag",ACCESS_VOTE_UNGAG,"admin_vote_ungag <name|wonid> : Opens a vote to ungag a gagged person");
 
plugin_registercmd("admin_vote_llama","admin_vote_llama",ACCESS_VOTE_LLAMA,"admin_vote_llama <name|wonid> : Opens a vote to turn <name> into a llama");
 
plugin_registercmd("admin_vote_unllama","admin_vote_unllama",ACCESS_VOTE_UNLLAMA,"admin_vote_unllama <name|wonid> : Opens a vote to change a llama into human");
return PLUGIN_CONTINUE;
}