<?xml version="1.0" encoding="utf-8"?><waypoints type="TRAVEL">
<onload> 
	--=== 	NoobBotter's Kashaylan Eoj Script Version 2.2									===--
	--===	Does only channels 1 and 2, will start on whichever channel you're on 			===--
	--===	and then does the next channel, then waits till next round and goes from there. ===--
	--===	Update for 2.2:																	===--
	--===	Changed how it targets bottles. Now uses an old function I found and modified.	===--
	
	--===  User Settings  ===--
	local objectClickRest = 200 -- this is the delay time (in milliseconds) that it wait when clicking on one of the flasks. Higher ping time may need a higher value.
	local disableSkills = true 	-- set to true to disable skills, or false to keep skills enabled
	local maxEoj = 4000			-- set to the maximum amount of eoj's you want to have. Script will stop when you reach this amount. I believe in-game maximum is 4000.
	local maxMinutes = 50		-- Maximum amount of time (in minutes) to run the script for. 999 (or greater) will run indefinitely.
								-- the time check is performed between event rounds so if max time is passed during an event, it will complete that event before stopping. 
	
	local restTime = 120			-- this is how many minutes the bot will rest after reaching maxMinutes. A setting of 0 will cause the bot to never start back up after reaching max minutes.
		--=== Examples:					
			-- if you want the bot to run for 2 hours and then take a 3 hour break, set the following settings:
			-- local maxMinutes = 120
			-- local restTime = 180
			
			-- if you want the bot to run for 12 hours and then stop until you manually restart it, set the following:
			-- local maxMinutes = 720
			-- local restTime = 0
	
	When_Finished = "end"
		-- "end" to end script, "relog" to log next character, "charlist" to log next in 'charlist', or filename for next waypoint to load (without .xml).							
	
	CharList = {}
		-- Character list to use when using the "charlist" option above. Requires Rock5's "userfunction_LoginNextChar" userfunction.
		-- Find it here. http://www.solarstrike.net/phpBB3/viewtopic.php?p=10350
		--		eg.
		--		CharList = {
		--			{account=4,chars={}},
		--			{account=8,chars={1}},
		--			{account=7,chars={1,2,5}}
		--		}
		
	
	-- NO NEED TO EDIT BELOW THIS LINE.
	local QuestID = 427058
	startChannel = RoMScript("GetCurrentParallelID()")
	yrest(500)
	if startChannel == 3 then
		RoMScript("ChangeParallelID(1)")
		repeat
			yrest(4000)
		until RoMScript("GetCurrentParallelID()") == 1
	end
	
	--============= FUNCTIONS ===============--
	
	--============= function to check player location +==============--
	local function locationCheck()
		local myitem = player:findNearestNameOrId(123561) -- Jenn Shadoli
		if myitem then
			if distance(myitem, player) > 50 then
				print("%s is not close enough to start location for this eoj quest.\n")
				checkRelog()
			end
		else
			print("Cannot locate eoj quest giver Jenn Shadoli (ID: 123561).\n")
			checkRelog()
		end
	end
	
	--============= Function for enabling/disabling autoquest quest.================--
	function EOJ_AutoQuest(questid, state)
		-- Check that user used quest id as argument
		if type(tonumber(questid)) ~= "number" then
			error("EOJ_AutoQuest: invalid argument. Expected quest id.",0)
		end
		if onoff == "off" or onoff == "Off" or onoff == "OFF" or onoff == false then
			onoff = 0
		else
			onoff = 1
		end
		
		-- Check if DailyNotes is installed
		if RoMScript("DailyNotes == nil") then
			error("EOJ_AutoQuest: addon DailyNotes is not installed.",0)
		end

		-- Get server name
		local serverName = RoMScript("GetCurrentRealm()") or ""

		-- DailyNotes only uses last word of name
		serverName = string.match(serverName,"(%w*)$")

		-- Check if there is already an entry for server then enable Auto-Quest
		local serverSet = RoMScript("(DN_Options_Of_Char."..serverName.." ~= nil)")
		if serverSet then
			RoMCode("DN_Options_Of_Char."..serverName..".autoquest=true")
		else
			RoMCode("DN_Options_Of_Char."..serverName.." = {autoquest=true}")
		end

		-- Check that there is a quest list then add the quest id.
		local aq_accept = RoMScript("(DN_Options_Of_Char."..serverName..".aq_accept ~= nil)")
		if aq_accept then
			RoMCode("DN_Options_Of_Char."..serverName..".aq_accept["..questid.."]="..onoff)
		else
			RoMCode("DN_Options_Of_Char."..serverName..".aq_accept={["..questid.."]="..onoff.."}")
		end
	end

	--============= function to disable pet and skills for this quest ===============--
	
	function setSkills()
		if disableSkills == true then
			settings.profile.options.EGGPET_ENABLE_ASSIST = false
			for k,v in pairs(settings.profile.skills) do
				v.AutoUse = false
			end
		end
	end
	
	--=== relog function from Rock5's scripts ===--
	function checkRelog()
		
		-- Log result
		local filename = getExecutionPath() .. "/logs/eoj.log";
		local file, err = io.open(filename, "a+");
		if file then
			file:write("Acc: "..RoMScript("GetAccountName()").."\tName: " ..string.format("%-10s",player.Name ).." \tDate: " .. os.date() ..
			"\tEnergy of Justice Gained:"..totalEojEarned.." \tTotal EoJ on character: "..getCurrency("eoj").."\n")
			file:close();
		end

		if When_Finished == "relog" then
			ChangeChar()
			waitForLoadingScreen();
			yrest(3000)
			loadProfile()
			loadPaths(__WPL.FileName);
		elseif When_Finished == "charlist" then
			SetCharList(CharList)
			LoginNextChar()
			loadProfile()
			loadPaths(__WPL.FileName);
		elseif When_Finished == "end" then
			EOJ_AutoQuest(QuestID,"off")
			error("EOJ Script is complete")
		else
			EOJ_AutoQuest(QuestID,"off")
			loadProfile() -- Because we messed with the skills
			loadPaths(When_Finished)
		end
	end
	
	--=== Function to change channels when needed ===--
	function changeChannel()
		if RoMScript("GetCurrentParallelID()") == 1 then
			RoMScript("ChangeParallelID(2)")
		else
			RoMScript("ChangeParallelID(1)")
		end
		print("waiting 28 secs to change chan")
		yrest(28000)
		print("moving 1 step forward then waiting 1 second to stand up")
		keyboardPress(key.VK_W)
		yrest(1000)
	end
	
	
	--===  Function to target the objects very quickly in succession ===--
	function fastTarget(_objid, waittime)
		obj = player:findNearestNameOrId(_objid)
		player:target(obj.Address)
		yrest(100)
		Attack()
		yrest(waittime)
	end
	
	--===  New Function to find, aim at, and click the bottles without losing NPC Target ===--
	local function scan_for_Bottle(_Bottlenumber)

		--Rom must be the foreground, active window
		if( foregroundWindow() ~= getWin() ) then
			return;
		end

		local function scan()
			local mousePawn;
			-- Screen dimension variables
			local wx, wy, ww, wh = windowRect(getWin());
			local halfWidth = ww/2;
			local halfHeight = wh/2;

			-- Scan rect variables
			local scanWidth = 10; -- Width, in 'steps', of the area to scan
			local scanHeight = 10; -- Height, in 'steps', of area to scan
			local scanXMultiplier = 1;	-- multiplier for scan width
			local scanYMultiplier = 1;	-- multiplier for scan line height
			local scanStepSize = 5; -- Distance, in pixels, between 'steps'

			local mx, my; -- Mouse x/y temp values

			mouseSet(wx + (halfWidth*scanXMultiplier - (scanWidth/2*scanStepSize)),
			wy  + (halfHeight*scanYMultiplier - (scanHeight/2*scanStepSize)));
			yrest(200);

			local scanstart, scanende, scanstep;
			-- define scan direction top/down  or   bottom/up
			scanstart = 0;
			scanende = scanHeight-1;
			scanstep = 1;
			
			-- Scan nearby area for a node
			keyboardHold(key.VK_SHIFT);	-- press shift so you can scan trough players
			for y = scanstart, scanende, scanstep do
				my = math.ceil(halfHeight * scanYMultiplier - (scanHeight / 2 * scanStepSize) + ( y * scanStepSize ));

				for x = 0,scanWidth-1 do
					mx = math.ceil(halfWidth * scanXMultiplier - (scanWidth / 2 * scanStepSize) + ( x * scanStepSize ));

					mouseSet(wx + mx, wy + my);
					yrest(50);
					mousePawn = CPawn(memoryReadRepeat("uintptr", getProc(),
					addresses.staticbase_char, addresses.mousePtr_offset));

					-- id 110504 Waffenhersteller Dimar
					-- id 110502 Dan (Gemischtwarenh�ndler
					-- id 1000, 1001 Player
					if( mousePawn.Address ~= 0 and mousePawn.Id == _Bottlenumber ) then
						cprintf(cli.green, "We found a bottle.\n");
						return mousePawn.Address, mx, my;
					end
				end
			end
			keyboardRelease(key.VK_SHIFT);


			return 0, nil, nil;
		end


		detach(); -- Remove attach bindings
		local mouseOrigX, mouseOrigY = mouseGetPos();
		local foundHarvestNode, nodeMouseX, nodeMouseY = scan();

		if( foundHarvestNode ~= 0 and nodeMouseX and nodeMouseY ) then

			-- If out of distance, move and rescan
			local mousePawn = CPawn(foundHarvestNode);
			
			player:update();

			local wx,wy = windowRect(getWin());
			--mouseSet(wx + nodeMouseX, wy + nodeMouseY);
			mouseSet(wx + nodeMouseX, wy + nodeMouseY);
			yrest(50);		-- wait for zoom in / out movement bug

			-- click NPC
			keyboardHold(key.VK_SHIFT);
			mouseLClick();		-- one click to target npc
			yrest(50);
			-- mouseLClick();		-- one click to open dialog
			-- yrest(500);
			-- mouseLClick();		-- one click to be really sure
			keyboardRelease(key.VK_SHIFT);

			player:update();

			yrest(50);

		end

		mouseSet(mouseOrigX, mouseOrigY);
		attach(getWin()); -- Re-attach bindings
	end
	
	--== main function that loops over, and over, and over ===--
	local function mainfunction()
		setSkills()
		--============= create variables ===============--
		local gomsg = getTEXT("SC_ZONE_PE_3TH_ST1START")
		local endmsg = getTEXT("SC_ZONE_PE_3TH_FAIL")
		local endmsg2 = getTEXT("SC_ZONE_PE_3TH_ST1OVER")
		local roundStartTime = os.time()
		local nextRound = 0
		local roundTime = 0
		local roundCount = 1
		local eventFinished = false
		local eojs = getCurrency("eoj") 
		yrest(500)
		local neweoj = eojs
		local gained = neweoj-eojs
		local totalEojEarned = 0
		local roundendedtime = os.time()
		local EventComplete = false
		local firstRun = true
		local bottlesTbl = {
			123369,
			123368,
			123508,
		}
		
		EOJ_AutoQuest(QuestID) 	-- activate DailyNotes Autoquest 
		
		repeat				-- Loops once per event.
			eojs = getCurrency("eoj") 
			roundTime = (os.time()-roundStartTime)/60
			nextRound = 20-roundTime
			if firstRun == false then
				if nextRound > 5 and EventComplete == false then -- if more than 5 minutes remaining in round, change channel:
					cprintf(cli.yellow,"\r%0.1f minutes until next round starts... Changing channel.", nextRound)
					changeChannel()
					
				else
					repeat
						roundTime = (os.time()-roundStartTime)/60
						nextRound = 20-roundTime
							
						--============= insert option to change channel and continue =====--
						if 1 > nextRound then
							roundCount = 1
							cprintf(cli.yellow,"\rTime till next round start: %0.1f seconds.",nextRound/60)
						else
							
							cprintf(cli.yellow,"\rTime till next round start: %0.1f minutes.",nextRound)
						end
						
						yrest(500)
					until getLastWarning("|cffffff80"..gomsg.."|r", 10)
				end
			end
						
			repeat
				player:target_NPC(123561) -- Jenn Shadoli
				yrest(200)
				
				for k, j in ipairs(bottlesTbl) do
					local curBottle = player:findNearestNameOrId(j)
					player:aimAt({X=curBottle.X, Z=curBottle.Z, Y=curBottle.Y})
					scan_for_Bottle(j)
					yrest(50)
				end
				
				yrest(200)
				player:target_NPC(123561) -- Jenn Shadoli
				yrest(200)
				if getLastWarning("|cffffff80"..endmsg.."|r", 10) then
					eventFinished = true
				end
				if getLastWarning("|cffffff80"..endmsg2.."|r", 10) then
					eventFinished = true
					
				end			
				printf("Time since started this round: %0.1f \tBeen running for %0.1f minutes.\n", (os.time()-roundStartTime)/60,(os.time()-scriptStartTime)/60)
			until eventFinished == true 
			roundCount = roundCount + 1
			if roundCount >= 3 then
				roundCount = 1
				EventComplete = true
			end
			eventFinished = false
			inventory:update()
			yrest(1000)
			neweoj = getCurrency("eoj")
			gained = neweoj-eojs
			totalEojEarned = totalEojEarned + gained
			roundendedtime = os.time()
			roundTime = (roundendedtime-roundStartTime)/60
			cprintf(cli.red,"Round took %s Minutes. EOJ's Gained this round: %s.\t\tCurrent Energy of Justice: %s. \n",roundTime, gained, neweoj)
			
			--=== At start of script, I don't have a timer for when the event will start.                   ===--
			--=== but after first event completes, this variable is set to false so it can display a timer  ===--
			--=== for when the next event will start, located in waitevent() function.                      ===--
			if firstRun == true then  
				firstRun = false
			end
			if neweoj >= maxEoj then
				print("You have reached your maximum number of EoJ's as per the maxEoj variable.\n")
				checkRelog()
			end
			--== section to determine max run time, and rest time ==--
			if 999 > maxMinutes then
				if (roundendedtime-scriptStartTime)/60 >= maxMinutes then
					if restTime == 0 then
						print("Maximum run time has been exceeded.")
						checkRelog()
					else
						printf("Now resting for %s minutes.\n", restTime)
						repeat
							local doneResting = ((roundendedtime/60)+restTime)-os.time()/60
							yrest(6000)
							cprintf(cli.yellow,"\rTime till done resting: %0.1f minutes.",doneResting)
						until 0 >= doneResting
						
						scriptStartTime = os.time()
					end
				end
			end
		until 5 == 1
	end
	
	locationCheck()
	scriptStartTime = os.time() 	-- to determine total script run time
	mainfunction()

</onload>
</waypoints>