<?xml version="1.0" encoding="utf-8"?><waypoints type="TRAVEL">
<onLoad>
	
	--=== Set up Variables ===--
	settings.profile.options.EGGPET_ENABLE_ASSIST = false
	for k,v in pairs(settings.profile.skills) do
		v.AutoUse = false
	end
			
		--=== Setting up variables: ===--
	local koboldsFound = 0
	local numMoves = 0
	local ea1 = os.clock()
	local ea2 = os.clock()
	local barrelTbl = {
		[1]={ X=3010.98291 , Z=35.38862991, Score=5, Links={[1]={Num=2},[2]={Num=6},[3]={Num=7},}},
		[2]={ X=3036.711914 , Z=49.38666916, Score=5, Links={[1]={Num=1},[2]={Num=3},[3]={Num=6},[4]={Num=8},[5]={Num=7},}},
		[3]={ X=3061.070068 , Z=67.11927032, Score=5, Links={[1]={Num=2},[2]={Num=4},[3]={Num=7},[4]={Num=9},[5]={Num=8},}},
		[4]={ X=3086.976074 , Z=80.69120026, Score=5, Links={[1]={Num=3},[2]={Num=5},[3]={Num=8},[4]={Num=10},[5]={Num=9},}},
		[5]={ X=3113.544922 , Z=99.62309265, Score=5, Links={[1]={Num=4},[2]={Num=10},[3]={Num=9},}},
		[6]={ X=3027.961914 , Z=8.74179554, Score=5, Links={[1]={Num=11},[2]={Num=1},[3]={Num=2},[4]={Num=12},[5]={Num=7},}},
		[7]={ X=3053.081055 , Z=25.25625992, Score=5, Links={[1]={Num=1},[2]={Num=13},[3]={Num=3},[4]={Num=11},[5]={Num=6},[6]={Num=8},[7]={Num=2},[8]={Num=12},}},
		[8]={ X=3077.891113 , Z=41.24858856, Score=5, Links={[1]={Num=12},[2]={Num=4},[3]={Num=2},[4]={Num=14},[5]={Num=7},[6]={Num=9},[7]={Num=13},[8]={Num=3},}},
		[9]={ X=3103.554932 , Z=56.39542007, Score=5, Links={[1]={Num=5},[2]={Num=13},[3]={Num=15},[4]={Num=3},[5]={Num=8},[6]={Num=10},[7]={Num=4},[8]={Num=14},}},
		[10]={ X=3129.545898 , Z=73.40276337, Score=5, Links={[1]={Num=5},[2]={Num=15},[3]={Num=14},[4]={Num=4},[5]={Num=9},}},
		[11]={ X=3042.2229 , Z=-15.36034966, Score=5, Links={[1]={Num=16},[2]={Num=6},[3]={Num=7},[4]={Num=17},[5]={Num=12},}},
		[12]={ X=3068.716064 , Z=-0.087428153, Score=5, Links={[1]={Num=16},[2]={Num=8},[3]={Num=18},[4]={Num=6},[5]={Num=13},[6]={Num=11},[7]={Num=7},[8]={Num=17},}},
		[13]={ X=3094.581055 , Z=15.31999016, Score=5, Links={[1]={Num=7},[2]={Num=19},[3]={Num=9},[4]={Num=17},[5]={Num=14},[6]={Num=12},[7]={Num=18},[8]={Num=8},}},
		[14]={ X=3119.471924 , Z=31.05658913, Score=5, Links={[1]={Num=10},[2]={Num=18},[3]={Num=8},[4]={Num=20},[5]={Num=15},[6]={Num=13},[7]={Num=9},[8]={Num=19},}},
		[15]={ X=3145.129883 , Z=47.69260025, Score=5, Links={[1]={Num=10},[2]={Num=20},[3]={Num=19},[5]={Num=9},[6]={Num=14},}},
		[16]={ X=3059.019043 , Z=-40.57423019, Score=5, Links={[1]={Num=21},[2]={Num=11},[3]={Num=12},[4]={Num=22},[5]={Num=17},}},
		[17]={ X=3084.559082 , Z=-26.07653046, Score=5, Links={[1]={Num=13},[2]={Num=21},[3]={Num=11},[4]={Num=23},[5]={Num=16},[6]={Num=18},[7]={Num=12},[8]={Num=22},}},
		[18]={ X=3108.978027 , Z=-11.35186005, Score=5, Links={[1]={Num=14},[2]={Num=22},[3]={Num=24},[5]={Num=12},[6]={Num=17},[7]={Num=19},[8]={Num=23},[9]={Num=13},}},
		[19]={ X=3134.354004 , Z=4.835566044, Score=5, Links={[1]={Num=13},[2]={Num=25},[3]={Num=23},[4]={Num=15},[5]={Num=18},[6]={Num=20},[7]={Num=14},[8]={Num=24},}},
		[20]={ X=3160.509033 , Z=20.60238075, Score=5, Links={[1]={Num=15},[2]={Num=25},[3]={Num=24},[4]={Num=14},[5]={Num=19},}},
		[21]={ X=3073.481934 , Z=-66.05554962, Score=5, Links={[1]={Num=22},[2]={Num=16},[3]={Num=17},}},
		[22]={ X=3098.574951 , Z=-51.81417084, Score=5, Links={[1]={Num=23},[2]={Num=21},[3]={Num=18},[4]={Num=16},[5]={Num=17},}},
		[23]={ X=3125.886963 , Z=-36.31401062, Score=5, Links={[1]={Num=24},[2]={Num=22},[3]={Num=19},[4]={Num=17},[5]={Num=18},}},
		[24]={ X=3150.272949 , Z=-18.85281944, Score=5, Links={[1]={Num=25},[2]={Num=23},[3]={Num=20},[4]={Num=18},[5]={Num=19},}},
		[25]={ X=3175.987061 , Z=-3.51265502, Score=5, Links={[1]={Num=20},[2]={Num=24},[3]={Num=19},}},
	}

	local checkRound = {
		[1]={4, 6, 13, 20, 22},
		[2]={1, 5, 21, 25},
		[3]={3, 11, 15, 23},
		[4]={7, 9, 17, 19},
		[5]={8, 12, 14, 18},
	}
	
	--=== functions ===--
	local function actionBar(num)
		if num == 1 then
			repeat
				yrest(50)
			until os.clock()-ea1 > 5.1
			RoMScript("UseExtraAction(1)")
			ea1 = os.clock()
			yrest(500)
		elseif num == 2 then
			repeat
				yrest(50)
			until os.clock()-ea2 > 10.1
			RoMScript("UseExtraAction(2)")
			ea2 = os.clock()
		end
	end
	
	local function getStatus(barrelnum)
		player:moveTo(CWaypoint( barrelTbl[barrelnum].X-7,barrelTbl[barrelnum].Z-7 ), true)
		yrest(100)
		player:moveTo(CWaypoint( barrelTbl[barrelnum].X-1,barrelTbl[barrelnum].Z-1 ), true)
		curbarrel = player:findNearestNameOrId("Barrel")
		yrest(100)
		player:target_Object(curbarrel.Name)
		yrest(500)
		actionBar(1)
		yrest(500)
		local time, moreToCome, msg = EventMonitorCheck("MyMonitor", "1")
		if msg and string.find(msg, "Lobt Kayen") then
		--if getLastWarning("|cfffff266Please report the quest to Lobt Kayen.|r",3) then
			koboldsFound = 3
		elseif msg and string.find(msg, "something inside the barrel") then
		--if getLastWarning("|cfffff266It seems like there is something inside the barrel.|r",3) then
			--=== if kobold is found do:
			
			cprintf(cli.green,"\tKobold found in barrel "..barrelnum..". clicking barrel and marking it done.\n")
			actionBar(2)
			yrest(500)
			barrelTbl[barrelnum].Score = 0
			koboldsFound = koboldsFound + 1
			
		elseif msg and string.find(msg, "kobolds nearby") then
		--if getLastWarning("|cfffff266There seem to be kobolds nearby.|r",3) then
			--=== if kobolds are located nearby then do:
			cprintf(cli.yellow,"\t\tKobolds are near barrel "..barrelnum..". Setting it's score to ZERO\n")
			barrelTbl[barrelnum].Score = 0
			cprintf(cli.yellow,"\t\t\tAnd updating score for surrounding barrels.\n")
			for u,udbrl in ipairs(barrelTbl[barrelnum].Links) do
				if barrelTbl[udbrl.Num].Score >0 then
					barrelTbl[udbrl.Num].Score = barrelTbl[udbrl.Num].Score + 1
					print("\t\tBarrel score for "..udbrl.Num.." is "..barrelTbl[udbrl.Num].Score)
				else
					print("\t\t"..udbrl.Num.." is already ZERO!!! Not updating it.")
				end
			end			
		elseif msg and string.find(msg, "It doesn't look like") then
		--if getLastWarning("|cfffff266It doesn't look like there are any kobolds around.|r",3) then
			--=== if no kobolds are found nearby, then do this:
			
			cprintf(cli.red,"\tNo Kobolds are near "..barrelnum..". Setting this barrel Score to ZERO.\n")
			barrelTbl[barrelnum].Score = 0
			cprintf(cli.red,"\t\tand updating score for surrounding barrels to ZERO.\n")
			for u,udbrl in ipairs(barrelTbl[barrelnum].Links) do
				
				if barrelTbl[udbrl.Num].Score > 0 then
					barrelTbl[udbrl.Num].Score = 0
					print("\t\tSetting score for barrel "..udbrl.Num.." to ZERO")
				else
					print("\t\t"..udbrl.Num.." is already ZERO!!! Not updating it.")
				end
			end	
		end
	end
		
		
		
	function checkBarrels()
		for i,round in ipairs(checkRound) do
			if koboldsFound == 3 then
				break
			end
			--for each barrel during this round:
			print("Beginning Round "..i)
			for b, barrels in pairs(round) do
				if koboldsFound == 3 then
					break
				end
				print("Current Barrel to be checked: "..barrels)
				--if barrel not marked as empty then
				if barrelTbl[barrels].Score == 0 then
					cprintf(cli.red,"\tThis barrel has already been eliminated\n")
				elseif barrelTbl[barrels].Score > 0 then
					--print("\tWe will now check this barrel")
					numMoves = numMoves + 1
					getStatus(barrels)
				end
				if koboldsFound == 3 then
					break
				end
			end
			if koboldsFound == 3 then
				break
			end
		end
		for i,barrels in ipairs(barrelTbl) do
			if barrelTbl[i].Score > 2 then
				if koboldsFound == 3 then
					break
				end
				numMoves = numMoves + 1
				getStatus(i)
			end
		end
		for i,barrels in ipairs(barrelTbl) do
			if barrelTbl[i].Score > 1 then
				if koboldsFound == 3 then
					break
				end
				numMoves = numMoves + 1
				getStatus(i)				
			end
		end
		for i,barrels in ipairs(barrelTbl) do
			if barrelTbl[i].Score > 0 then
				if koboldsFound == 3 then
					break
				end
				numMoves = numMoves + 1
				getStatus(i)				
			end
		end
		cprintf(cli.pink,"All kobolds found in "..numMoves.." moves!")
	end
	
		
	--=== Bot actions ===--
	obj = player:findNearestNameOrId(121334)
	if not obj then
		travelTo("VaranasBridge")
		player:moveTo(CWaypoint( 3111, 212 ), true)
	elseif distance(player,obj) > 200 then
		player:moveTo(CWaypoint( 3111, 212 ), true)
	end
	if player.Mounted then
		player:mount("dismount")
	end
	speed()
	player:target_NPC(121334); -- Lobt Kayen
	yrest(500)
	sendMacro("ChoiceOption(1)");
	yrest(500)
	sendMacro("ChoiceOption(1)");
	yrest(1000)
	--=== Game is now active ===--
	EventMonitorStart("MyMonitor","SYSTEM_MESSAGE")
	checkBarrels()
	EventMonitorStop("MyMonitor")
	
	--=== This is where it resumes to when all kobolds are found:
	player:moveTo(CWaypoint( 3111, 212 ), true)
	player:target_NPC(121334); -- Lobt Kayen
	yrest(100)
	sendMacro("ChoiceOption(1)");
	yrest(100)
	player:moveTo(CWaypoint( 2794, 923 ), true)
	error("All done")
	
</onLoad>
</waypoints>