public admin_novote() {

  AdminForceNoVote = 1;

}


public admin_vote_kick(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 WONID;
	new strWONID[MAX_NUMBER_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 real_user[MAX_NAME_LENGTH];
		AdminForceNoVote = 0;
		get_username(Data,real_user,MAX_NAME_LENGTH);
		say_command(User,Command,Data);
		if(check_immunity(real_user)!=0) {
			snprintf(Text, MAX_TEXT_LENGTH, "Laf. You can't kick %s, you silly bear.", real_user);
			say(Text);
		} else {
			snprintf(Text, MAX_TEXT_LENGTH, "Kick %s?", real_user);
			if(getvar("sv_lan")==1) {
				vote(Text,"Yes","No","HandleKickVote",real_user);
			} else {
				get_userWONID(real_user,WONID);
				numtostr(WONID,strWONID);
				vote(Text,"Yes","No","HandleKickVote",strWONID);
			}
		}
	} else {
		selfmessage("Unrecognized user name ");
		selfmessage(Data);
	}
	return PLUGIN_HANDLED;
}

/* Handle a kick vote's results. */
public HandleKickVote(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);
	
	if (AdminForceNoVote == 1) {
			snprintf(Text, MAX_TEXT_LENGTH, "Vote cancelled by admin.");
			say(Text);
			return PLUGIN_HANDLED;
	}

	if (WinningOption == 1) {
		new Ratio = getvar("kick_ratio");
		if (VoteCount >= Ratio*UserCount/100)  {
			snprintf(Text, MAX_TEXT_LENGTH, "%s was kicked due to a vote.", VoteUser);
			say(Text);
			message(VoteUser,"You have been kicked due to a vote.");
			kick(VoteUser);
		} else {
			numtostr(Ratio*UserCount/100,strNumber);
			snprintf(Text, MAX_TEXT_LENGTH, "Kick vote succeeded, but not enough votes for kick (needed %s)",strNumber);
			say(Text);
		}
	} else {
		say("Kick vote failed.");
	}
	return PLUGIN_HANDLED;
}

public admin_vote_map(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 (valid_map(Data) == 1) {
		AdminForceNoVote = 0;      
		snprintf(Text, MAX_TEXT_LENGTH, "Change map to %s?", Data);
		log(Text);
		vote(Text,"Yes","No","HandleMapVote",Data);
	} else {
		selfmessage("Bad map name");
		selfmessage(Data);
	}
	return PLUGIN_HANDLED;
}

/* Handle a map vote's results. */
public HandleMapVote(WinningOption,HLMap,VoteCount,UserCount) {
	new strNumber[MAX_NUMBER_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new VoteMap[MAX_DATA_LENGTH];
	convert_string(HLMap,VoteMap,MAX_DATA_LENGTH);
	new sTimelimit[10];
	getstrvar("mp_timelimit", sTimelimit, 10);

	if (AdminForceNoVote == 1) {
			snprintf(Text, MAX_TEXT_LENGTH, "Vote cancelled by admin.");
			say(Text);
			return PLUGIN_HANDLED;
	}
	
	if (WinningOption == 1) {
		new Ratio = getvar("map_ratio");
		if (VoteCount >= Ratio*UserCount/100)  {
			snprintf(Text, MAX_TEXT_LENGTH, "Changing map to %s due to vote.", VoteMap);
			say(Text);
			exec(PRECHANGE_TIMELIMIT);
			set_serverinfo( "config_mp_timelimit", sTimelimit );
			set_timer("ChangeMap",2,1,VoteMap);
		} else {
			numtostr(Ratio*UserCount/100,strNumber);
			snprintf(Text, MAX_TEXT_LENGTH, "Map vote succeeded, but not enough votes for change (needed %s)", strNumber);
			say(Text);
		}
	} else {
		say("Map vote failed.");
	}
	return PLUGIN_HANDLED;
}


