/*********************************************************
                     Foxbot Control Plugin
                     By: -=AS1=-MjrStryker
*********************************************************/
 
/*
*
*This plugins was made to allow normal server
*admins to turn on or off foxbots as well as alter
*their fire ability and skill level.
*
*When the plugin is first initialized the max_bots
*setting will be stored. From that point on the 
*command admin_bot_on will restore the number
*of bots to that setting. The setting can be manually
*changed by using the admin_bot_max command.
*
*Also, in order to change bot skill levels in game
*all current bots must be kicked. When 
*admin_bot_level is used the current bots will
*be kicked and the new replacement bots will
*be at the specified skill level.
*
*Currently it only allows server admins access
*to the following commands:
*
*admin_bot_on
*admin_bot_off
*admin_bot_level
*admin_bot_max
*admin_bot_add
*admin_bot_kick
*
*access level required: 8192
*
*/
 
/* Inclusion Files. */
#include <core>
#include <string>
#include <admin>
#include <adminlib>
 
/* Keep track of original max_bots variable. */
new BotID[MAX_DATA_LENGTH];
 
/* Store max_bots data to variable */
public grabinfo() {
	convert_string(getvar("max_bots"),BotID,MAX_DATA_LENGTH);
	return PLUGIN_CONTINUE;
}
 
/* Sound function */
PlaySoundToAll(sSound[]) {
	new i;
	new iMaxPlayers = maxplayercount();
	new Name[MAX_NAME_LENGTH];
 
	if (getvar("admin_fx") != 0) {  
		for (i = 1; i <= iMaxPlayers; i++) {
			if (playerinfo(i,Name,MAX_NAME_LENGTH) != 0) {
				playsound(Name, sSound);
			}
		}
	}
}
 
/* admin_bot_off */
public admin_bot_off(HLCommand,HLData,HLUserName,Userindex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	grabinfo();
	exec("bot max_bots -1");
	exec("bot kickall");
	centersay("Say goodbye to the bots now.",5,0,255,0);
	PlaySoundToAll("vox/goodbye.wav");
	return PLUGIN_HANDLED;
}
 
/* admin_bot_on */
public admin_bot_on(HLCommand,HLData,HLUserName,Userindex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Cmd[MAX_DATA_LENGTH];
 
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	snprintf(Cmd,MAX_COMMAND_LENGTH,"bot ^"max_bots %s^"",BotID);
	exec(Cmd);
	centersay("Seems the bots have^njoined the game.", 5, 0, 255, 0);
	PlaySoundToAll("misc/wlcm2as1.wav");
	return PLUGIN_HANDLED;
}
 
/* admin_bot_level */
public admin_bot_level(HLCommand,HLData,HLUserName,Userindex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Cmd[MAX_COMMAND_LENGTH];
	new Text[MAX_TEXT_LENGTH];
 
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if (strtonum(Data) < 6 && strtonum(Data) > 0) {
		snprintf(Text, MAX_TEXT_LENGTH, "Bot difficulty level set to %s.", Data);
		snprintf(Cmd, MAX_COMMAND_LENGTH, "bot ^"botskill %s^"", Data);
		exec(Cmd);
		exec("bot kickall");
		selfmessage(Text);
	}
	return PLUGIN_HANDLED;
}
 
/* admin_bot_max */
public admin_bot_max(HLCommand,HLData,HLUserName,userindex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Cmd[MAX_DATA_LENGTH];
	new Text[MAX_TEXT_LENGTH];
 
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if (strtonum(Data) < 32 && strtonum(Data) > -2) {
		strcpy(BotID,Data,MAX_DATA_LENGTH);
		snprintf(Cmd,MAX_COMMAND_LENGTH,"bot ^"max_bots %s^"",BotID);
		exec(Cmd);
	} else {
		snprintf(Text,MAX_TEXT_LENGTH,"max_bots cannot be set to %s",Data);
		selfmessage(Text);
	}
	return PLUGIN_HANDLED;
}
 
/* admin_bot_add */
public admin_bot_add(HLCommand,HLData,HLUserName,userindex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new CmdA[MAX_COMMAND_LENGTH];
	new CmdB[MAX_COMMAND_LENGTH];
	new i = strtonum(BotID);
 
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	++i; ++i;
	if (i < maxplayercount()) {
		--i;
		numtostr(i,BotID);
		snprintf(CmdA,MAX_COMMAND_LENGTH,"bot ^"max_bots %s^"",BotID);
		snprintf(CmdB,MAX_COMMAND_LENGTH,"bot ^"addbot^"");
		exec(CmdA); exec(CmdB);
	} else {
		selfmessage("It would be unwise to add another bot at the moment.");
	}
	return PLUGIN_HANDLED;
}
 
/* admin_bot_kick */
public admin_bot_kick(HLCommand,HLData,HLUserName,userindex) {
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new i = strtonum(BotID);
	new CmdA[MAX_COMMAND_LENGTH];
 
	convert_string(HLCommand,Command,MAX_NAME_LENGTH);
	convert_string(HLData,Data,MAX_NAME_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	if (i > 0) {
		--i;
		numtostr(i,BotID);
		snprintf(CmdA,MAX_COMMAND_LENGTH,"bot ^"max_bots %s^"",BotID);
		exec(CmdA);
	} else {
		selfmessage("There are no bots to kick.");
	}
	return PLUGIN_HANDLED;
}
public plugin_init() {
	plugin_registerinfo("Admin BotController Plugin","Commands for limited control of FoxBots during the game.","version 3.7");
 
	plugin_registercmd("admin_bot_on","admin_bot_on",8192,"admin_bot_on : Activate FoxBots on the server.");
	plugin_registercmd("admin_bot_off","admin_bot_off",8192,"admin_bot_off : Deactivate FoxBots on the server and kick all bots.");
	plugin_registercmd("admin_bot_level","admin_bot_level",8192,"admin_bot_level <1-5> : Alters the difficulty level of the FoxBots.");
	plugin_registercmd("admin_bot_max","admin_bot_max",8192,"admin_bot_max <Max bots> | Sets the maximum number of bots allowed on the server.");
	plugin_registercmd("admin_bot_add","admin_bot_add",8192,"admin_bot_add | Adds one random bot to the server.");
	plugin_registercmd("admin_bot_kick","admin_bot_kick",8192,"admin_bot_kick | Kicks the next bot that dies from the server.");
 
	return PLUGIN_CONTINUE;
}