/* Slap vote plugin by Sleight_of_Mind
 * Please visit http://connect.to/clan_[-DEus-]
 * or mail me: windowswacker@hotmail.com
 */
/* $id plugin_slapvote.sma,v 1.0 2001/04/11 Sleight_of_Mind $ */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
/* change these for your own setup
*/
#define SLAP_VOTE_RATIO  50
#define ACCESS_VOTE_SLAP 1
#define SLAP_COUNT	 3
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.0";
 
public admin_vote_slap(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new Text[MAX_TEXT_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);
	if (check_user(Data) == 1) {
		new kankerPlayer[MAX_NAME_LENGTH];
		get_username(Data,kankerPlayer,MAX_NAME_LENGTH);
		say_command(User,Command,Data);
		if(check_immunity(kankerPlayer)!=0) {
			snprintf(Text, MAX_TEXT_LENGTH, "%s has immunity. You can't slap him.", kankerPlayer);
			say(Text);
		} else {
			snprintf(Text, MAX_TEXT_LENGTH, "Slap the lamer called %s?", kankerPlayer);
			vote(Text,"Yeah, let's slap that lamer","No, that might hurt him","HandleSlapVote",kankerPlayer);
 
		}
	}
	else {
		selfmessage("Not a valid user name ");
		selfmessage(Data);
	}
	return PLUGIN_HANDLED;
}
 
public HandleSlapVote(WinningOption,HLUser,VoteCount,UserCount) {
	new strNumber[MAX_NUMBER_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new VoteUser[MAX_DATA_LENGTH];
	convert_string(HLUser,VoteUser,MAX_DATA_LENGTH);
	new i;
 
	if (WinningOption == 1) {
		new Ratio = SLAP_VOTE_RATIO;
		if (VoteCount >= Ratio*UserCount/100) {
			snprintf(Text, MAX_TEXT_LENGTH, "Who's your daddy, %s.", VoteUser);
			typesay(Text,20,255,0,0);
			message(VoteUser,"Who's your daddy!");
 
			for(i=0;i<SLAP_COUNT;i++) {
				slap(VoteUser);
			}
		} else {
			numtostr(Ratio*UserCount/100,strNumber);
			snprintf(Text, MAX_TEXT_LENGTH, "A majority wants to slap, but %s people needed.^nNow majority, go slap him yourself!",strNumber);
			typesay(Text,20,255,255,255);
		}
	} else {
		snprintf(Text, MAX_TEXT_LENGTH, "Darn. A minority is sadistic. Let's all apologise to %s", VoteUser);
		typesay(Text,20,0,255,0);
	}
}
 
public plugin_init() {
	plugin_registerinfo("Slap Vote Plugin","Vote to slap a lame player",STRING_VERSION);
	plugin_registercmd("admin_vote_slap","admin_vote_slap",ACCESS_VOTE_SLAP,"admin_vote_slap: Starts a slap vote against a player");
}