<?xml version="1.0" encoding="utf-8"?><waypoints type="TRAVEL">
<onload> 
	--=============================================================================================--
	--===  						NoobBotter's Research Expert EOJ script							===--
	--===  									Version 1.7											===--
	--===  															  							===--
	--===  	This script will farm Energy of Justice	in Kashaylan using the Research 			===--
	--===   Expert public quest.				  	  											===--
	--===  															  							===--
	--===  	The script will start farming immediately when script starts regardless of 			===--
	--===  	where the event is (started, finished, etc...). After it gets a message that 		===--
	--===  	the event is finished that first time, it will wait for an event start message.		===--
	--===  	Once the Event starting message appears, it will farm until event is complete. 		===--
	--===  	Then if there is more than 5 minutes left in the event, it will change channel 		===--
	--===  	and then farm there until it gets an ending message.								===--
	--===   																					===--   
	--===   This Waypoint has user settings to tell it when to stop, by either max EOJ in 		===--
	--===   inventory, or by amount of time the script has been running. It can stop and rest 	===--
	--===   for an amount of time, and then resume, or run continuously.						===--
	--===   																					===--
	--===   Additionally, I am using Rock5's checkRelog() function to allow you to either end  	===--
	--===   the script, change characters, or load a different waypoint file once this one 		===--
	--===   completes.																			===--
	--===  															  							===--
	--===  	Revision Notes: Testing Fix of doing each of the 3 channels then waiting 			===--
	--===	on next round to start.																===--
	--===  															  							===--
	--=============================================================================================--
	--===  	*** USER INSTRUCTIONS ***								  							===--
	--===															  							===--
	--===  	1. This script depends on having the DailyNotes Addon activated for auto accepting  ===--
	--===      the Research Expert public quest.												===--
	--===  	2. This script also requires the LoginNextChar userfunction by Rock5.				===--
	--===															  							===--
	--===  	3. Set preferences in the following User Settings section.							===--
	--===															  							===--
	--=============================================================================================--
	
	--===  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.

		
	
	--============= 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 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
			error("EOJ Script is complete")
		else
			loadProfile() -- Because we messed with the skills
			loadPaths(When_Finished)
		end
	end
	
	--=== Function to change channels when needed ===--
	function changeChannel()
		local currentChannel = RoMScript("GetCurrentParallelID()")
		yrest(1000)
		printf("Current Channel is %s\n",currentChannel)
		if currentChannel == 3 then
			currentChannel = 1
		else
			currentChannel = currentChannel + 1
		end
		printf("Changing to channel %s.\n",currentChannel)
		RoMScript("ChangeParallelID("..currentChannel..")")
		repeat
			yrest(4000)
		until RoMScript("GetCurrentParallelID()") == currentChannel
		yrest(2000)
	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
	
	
	--== 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 startTime = os.time()
		local nextRound = 0
		local roundTime = 0
		local eventFinished = false
		local firstRun = true
		local timerIncorrect = true
		local changedChannels = false
		local eojs = getCurrency("eoj") 
		yrest(500)
		local neweoj = eojs
		local gained = neweoj-eojs
		local totalEojEarned = 0
		local roundendedtime = os.time()
		local roundCount = 1
		repeat				-- Loops once per event.
			eojs = getCurrency("eoj") 
			if firstRun == false then
				eventFinished = false
				
				repeat
					roundTime = (os.time()-startTime)/60
					if timerIncorrect == false then
						nextRound = 20-roundTime
						
						--============= insert option to change channel and continue =====--
						if nextRound > 5 and 3 > roundCount 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)
							roundCount = roundCount + 1
							changeChannel()
							firstRun = false
							timerIncorrect = false
							changedChannels = true
							break
						elseif 1 > nextRound then
							roundCount = 1
							changedChannels = false
							cprintf(cli.yellow,"\rTime till next round start: %0.1f seconds.",nextRound/60)
						else
							changeChannel()
							roundCount = 1
							changedChannels = false
							cprintf(cli.yellow,"\rTime till next round start: %0.1f minutes.",nextRound)
						end
					else -- After very first run, it will wait on start of next round:
						changedChannels = false
						--cprintf(cli.red,"timerIncorrect = %s.\t\tfirstRun = %s.",timerIncorrect, firstRun)
						cprintf(cli.yellow,"\rWaiting on next round to start.")
					end
					yrest(500)
				until getLastWarning("|cffffff80"..gomsg.."|r", 10)
				if changedChannels == false then
					startTime = os.time()
				end
				if 5 > nextRound then
					print("Event has started...\n")
				else
					print("Continuing event...\n")
				end
				if firstRun == false and timerIncorrect == true then -- This sets the Timer properly after frsh start of a new round:
					cprintf(cli.red,"timerIncorrect should be true: %s.\t\tfirstRun should be false: %s.\n",timerIncorrect, firstRun)
					timerIncorrect = false
					
				end
				cprintf(cli.red,"timerIncorrect = %s.\t\tfirstRun = %s.\n",timerIncorrect, firstRun)
				print("Event has started...\n")
			else -- This section runs on very first start of script:
				timerIncorrect = true
				cprintf(cli.yellow,"\rStarting immediately...\n")
			end
			repeat
				player:target_NPC(123561) -- Jenn Shadoli
				yrest(200)
				fastTarget(123369,objectClickRest);
				fastTarget(123368,objectClickRest);
				fastTarget(123508,objectClickRest);
				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("Been running for %0.1f minutes.\n", (os.time()-scriptStartTime)/60)
			until eventFinished == true 
			inventory:update()
			yrest(1000)
			neweoj = getCurrency("eoj")
			gained = neweoj-eojs
			totalEojEarned = totalEojEarned + gained
			roundendedtime = os.time()
			roundTime = (roundendedtime-startTime)/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 false
	end
	
	locationCheck()
	scriptStartTime = os.time() 	-- to determine total script run time
	mainfunction()

</onload>
</waypoints>