// Plugin by AtomSmasher.id^wB (Atom@invadedefend.com).
// This plugin was made to work with FoxBot
//
// Parts of this plugin are ripped from the admin_vote_slay_stack plugin
//  written by [IKR] Soul Man (http://ikr.homeip.net).
//
// Adds two commands:
// admin_vote_nobots: Starts a vote to disable bots until mapchange. (access level: ADMIN_VOTE_MAP - 2)
// admin_nobots: Disables the bots until mapchange. (access level: ADMIN_KICK - 128)
//
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
// These may be edited:
#define ACCESS_VOTE_NOBOTS 2 /* the access level to start a vote to disable bots (default: 2) */
#define ACCESS_NOBOTS 128 /* the access level to disable bots (default: 128) */
#define NOBOTS_RATIO 60	/* a number between 0 and 100 */
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.3.1";
 
public admin_vote_nobots(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
 
	if (access(ACCESS_VOTE_KICK,"") != 1) {
		selfmessage("You don't have access to this command");
		return PLUGIN_HANDLED;
	}
 
	if (vote_allowed() != 1) {
		selfmessage("Vote not allowed at this time.");
		return PLUGIN_HANDLED;
	}
 
  //ask the server if the bots should be kicked
	snprintf(Text, MAX_TEXT_LENGTH, "Kick All Bots?");
	vote(Text, "Yes", "No", "HandleNoBotsVote", User);
 
	return PLUGIN_HANDLED;
}
 
public HandleNoBotsVote(WinningOption,HLData,VoteCount,UserCount) {
	new strNumber[MAX_NUMBER_LENGTH];
	new Text[MAX_TEXT_LENGTH];
 
	if ( (WinningOption == 1 && VoteCount >= (NOBOTS_RATIO/100)*UserCount) || (WinningOption == 2 && VoteCount <= (NOBOTS_RATIO/100)*UserCount) ) {
    //execute the command ---> bot "max_bots 0"
    snprintf(Text, MAX_TEXT_LENGTH, "bot ^"max_bots 0^"");
    exec(Text);
    snprintf(Text, MAX_TEXT_LENGTH, "Bot Disable vote succeeded.");
    say(Text);
	} else {
		numtostr((NOBOTS_RATIO/100)*UserCount, strNumber);
		snprintf(Text, MAX_TEXT_LENGTH, "Not enough votes to disable bots (needed %s).",  strNumber);
		say(Text);
	}
}
 
public admin_nobots(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_COMMAND_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
 
	if (access(ACCESS_KICK,"") != 1) {
		selfmessage("You don't have access to this command");
		return PLUGIN_HANDLED;
	}
 
	//tell the server that someone used a command
	say_command(User,Command,"");
 
	//execute the command ---> bot "max_bots 0"
	snprintf(Text, MAX_TEXT_LENGTH, "bot ^"max_bots 0^"");
	exec(Text);
 
	return PLUGIN_HANDLED;
}
 
public plugin_init() {
	plugin_registerinfo("Bot Disable plugin by AtomSmasher.id^^wB", "Die Bots!", STRING_VERSION);
 
	plugin_registercmd("admin_vote_nobots", "admin_vote_nobots", ACCESS_VOTE_NOBOTS, "admin_vote_nobots: Starts a vote to disable bots until mapchange.");
	plugin_registercmd("admin_nobots", "admin_nobots", ACCESS_NOBOTS, "admin_nobots: Disables bots until mapchange.");
 
	return PLUGIN_CONTINUE;
}