/************************************************************************************
With this script you will be able to waypoint a map just by running around it.

Original idea by Bladen (thanks)

Modified by [GNU]FeelGood/Nobody
Contact : et@netrusk.net

You need to give a valid rconpassword before any command

usage (in console) :
	/rcon bot myautowpon  : start autowaypointing
	/rcon bot myautowpoff : stop autowaypointing
	/rcon bot wptwowayconnect  : waypoints will be bi-connected
	/rcon bot wponewayconnect  : waypoints will be mono-connected
	/rcon bot wpwiderange  : waypoints will spaced by 300 and have radius = 70
	/rcon bot wpshortrange  : waypoints will spaced by 150 and have radius = 35
	
Can by used with bind like this in your ET client :

unbind s
set ShortWay "rcon bot wpshortrange; echo ^g short range; set WaySize vstr LongWay"
set LongWay "rcon bot wpwiderange; echo ^g wide range; set WaySize vstr ShortWay"
set WaySize "vstr ShortWay" 
bind s "vstr WaySize"
set binds "echo ^cs ^f Cycle Short / Long connexions"
vstr binds

unbind TAB
set AutoWayOn "rcon bot myautowpon; echo ^g Auto waypointing ON; set WayCnx vstr AutoWayOff"
set AutoWayOff "rcon bot myautowpoff; echo ^g Auto waypointing OFF; set WayCnx vstr AutoWayOn"
set AutoWay "vstr AutoWayOn" 
bind TAB "vstr AutoWay"
set bindTAB "echo ^cb ^f Cycle Auto waypointing on / off"
vstr bindTAB

unbind b
set MonoWay "rcon bot wponewayconnect; echo ^g Mono-connect; set WayCnx vstr BiWay"
set BiWay "rcon bot wptwowayconnect; echo ^g Bi-connect; set WayCnx vstr MonoWay"
set WayCnx "vstr MonoWay" 
bind b "vstr WayCnx"
set bindb "echo ^cTAB ^f Cycle monoconnect / biconnect"
vstr bindb

unbind h
set bindh "^ch^f for waypoint binding help"
set bindhelp "vstr bindTAB;vstr binds;vstr bindb;vstr bindh"
bind h "vstr bindhelp"
vstr bindh
 
Now, when you press :

	TAB : you cycle Autwaypoint ON/ OFF
	s : you cycle Short / Wide connections
	b : you cycle mono / bi connections
	h : help about this binding

**************************************************************************************/

// Load any other scripts that we will need.
ExecScript("et_utilities.gm");


// Set up a list of Names, optionally associated with a script.
Names["[BOT]Walter"] = "";
Names["[BOT]Fred"] = "";
Names["[BOT]Morgan"] = "";
Names["[BOT]Lawrence"] = "";
Names["[BOT]Richard"] = "";
Names["[BOT]Michael"] = "";
Names["[BOT]Brad"] = "";
Names["[BOT]George"] = "";
Names["[BOT]Anton"] = "";
Names["[BOT]Monty"] = "";
Names["[BOT]Bean"] = "";
Names["[BOT]Sean"] = "";

// Set minbots/maxbots on map start
MinBots(0);
MaxBots(8);


global WPDistance = 150;
global WPRadius = "35.0";
global WPConnect = 2;


global WPReset = function()
{
	global iAutoWaypoint = null;
	global myWaypoint = null;
};


global WPAutoConnect = function()
{
	if (WPConnect == 2)
	{
		ExecCommand("waypoint_biconnect");
	}
	else
	{
		ExecCommand("waypoint_connect");
	}
};



global WPAdd = function()
{
	ExecCommand("waypoint_add");
		
	waypointerFlags = GetEntFlags(GetGameEntityFromId(0));
	if(waypointerFlags & ENTFLAG.CROUCHED)
	{
		ExecCommand("waypoint_addflag crouch");
	}
	
	if(waypointerFlags & ENTFLAG.PRONE)
	{
		ExecCommand("waypoint_addflag prone");
	}
	
	if(waypointerFlags & ENTFLAG.INWATER)
	{
		ExecCommand("waypoint_addflag inwater");
	}
	
	if(waypointerFlags & ENTFLAG.UNDERWATER)
	{
		ExecCommand("waypoint_addflag underwater");
	}

	ExecCommand("waypoint_setradius " + WPRadius);
	
	WPAutoConnect();
};


Commands["myautowpon"] = function(_params)
{
	if(myWaypoint == null)
	{
		global iAutoWaypoint = 1;
		print("auto waypointing mode on");

		global myWaypoint = table();
		
		framecounter = 0;
		ExecCommand("waypoint_view on");
		ExecCommand("dontshoot 1");
		
		while(iAutoWaypoint)
		{
			sleep(0.05);
			if(framecounter == 0)
			{
				WPAdd();				
			}
				
			myWaypoint.new = GetEntPosition(GetGameEntityFromId(0)); 
			
			if(myWaypoint.old)
			{
				Distance = (myWaypoint.new - myWaypoint.old).Length();
				print("Distance: ",Distance);
			}
			else
			{
				myWaypoint.old = myWaypoint.new;
			};
			
			if(Distance > WPDistance)
			{
				myWaypoint.old = myWaypoint.new;
				WPAdd();				
				WPAutoConnect();
			}
			
			framecounter += 1;
			sleep(0.2);
		}
		print("auto waypointing mode off");
	}
	else
	{
		print("auto waypointing mode already on");
	}
};

Commands["myautowpoff"] = function(_params)
{
	WPAutoConnect();
	WPReset();
};


Commands["wptwowayconnect"] = function(_params)
{
	print("WPTwoWayConnect");
	global WPConnect = 2;
};

Commands["wponewayconnect"] = function(_params)
{
	print("WPTwoWayConnect");
	global WPConnect = 1;
};

Commands["wpwiderange"] = function(_params)
{
	print("WP wide Range");
	global WPDistance = 300;
	global WPRadius = "70.0";
};


Commands["wpshortrange"] = function(_params)
{
	print("WP Short Range");
	global WPDistance = 150;
	global WPRadius = "35.0";
};
