<?xml version="1.0" encoding="utf-8"?><waypoints type="TRAVEL">
<onLoad>

--=== version 3.3 ===--
	local downwards = {[1] ={ X=4132, Z=4303, Y=7},[2] ={ X=3327, Z=3834, Y=7},[3] ={ X=4109, Z=3397, Y=7}}
	
	for k,v in pairs(settings.profile.skills) do
	      v.AutoUse = false
	end
	
	--=== changing teleport settings
	teleport_SetStepSize(40)
	teleport_SetStepPause(1000)

	local elemental = GetIdName(113614) -- Elemental Candstick
	local luke = GetIdName(113622) 
	local ange = GetIdName(113689) 
	if getZoneId() ~= 355 then 
		player:target_NPC(ange);
		yrest(2000);
		sendMacro("ChoiceOption(4);");
		yrest(2000);
		sendMacro("ChoiceOption(1);");
		yrest(1000);		
		repeat
			waitForLoadingScreen(10)
		until getZoneId() == 355
	end	
	
	fly()
	
	local function getunder()
		if not RoMScript("TimeKeeperFrame:IsVisible()") then -- no timer so click NPC and start it
			player:target_NPC(luke);
			yrest(2000);
			sendMacro("ChoiceOption(3);");
			yrest(2000);
			sendMacro("ChoiceOption(1);");
			yrest(5000);
		end
		
		teleport(nil,nil,74)
		player:update() 
		for i = 1,30,1 do teleport(nil,nil,74+i) player:turnDirection(1) yrest(50) end
		yrest(1000)
		teleport(nil,nil,120)
		local dist,bestdist,bestX,bestZ
		for k,v in pairs(downwards) do
			--table.print(v)
			dist = distance(player.X,player.Z,v.X,v.Z)
			if bestdist == nil then 
				bestdist = dist
				bestX = v.X
				bestZ = v.Z			
			else
				if bestdist > dist then 
					bestdist = dist 
					bestX = v.X
					bestZ = v.Z
				end
			end
		end
				
		teleport(bestX,bestZ)
		teleport(nil,nil,7)
		teleport(3890,3788) -- under instance in the middle
	end
	
	local function getcandles()
		local candles = {}
		local objectList = CObjectList();
		objectList:update();
		local objSize = objectList:size()
		for i = 0,objSize do 
			obj = objectList:getObject(i);
			if obj.Name == elemental then
				table.insert(candles, obj)
			end
		end
		--table.print(candles)

		for k,v in pairs(candles) do
			teleport(v.X,v.Z,7)
			teleport(nil,nil,12)
			keyboardPress(settings.hotkeys.MOVE_FORWARD.key);
			local stt = os.time()
			repeat
			yrest(1)
			player:target_Object(elemental)
			until memoryReadRepeat("int", getProc(), player.Address + addresses.pawnCasting_offset) or os.time() - stt > 15
			teleport(nil,nil,7)
		end
		teleport(3838,3994) 
		yrest(10000) -- 10 seconds to let mobs despawn
		for i = 1,10,1 do teleport(nil,nil,14+i) player:turnDirection(1) yrest(50) end
		keyboardPress(settings.hotkeys.MOVE_FORWARD.key);
		keyboardPress(settings.hotkeys.MOVE_BACKWARD.key);
		for i = 1,10,1 do teleport(nil,nil,24+i) player:turnDirection(1) yrest(50) end
		keyboardPress(settings.hotkeys.MOVE_FORWARD.key);
		keyboardPress(settings.hotkeys.MOVE_BACKWARD.key);		
		teleport(nil,nil,50)
		keyboardPress(settings.hotkeys.MOVE_FORWARD.key);
		teleport(3842,3838,49) -- get to chest room
	end
	
	
	local function getchests()
		--=== Open chests ===--
		function clickchest(address)
			local chest = memoryReadRepeat("byte", getProc(), address + 0x2F0) or 0
			if chest ~= 0 then
				return true
			else
				return false
			end
		end

		function matchests()
			local matchest
			repeat
				matchest = player:findNearestNameOrId(113617,nil,clickchest)
				if matchest then
					teleport(matchest.X,matchest.Z,matchest.Y+11)
					keyboardPress(settings.hotkeys.MOVE_FORWARD.key);
					repeat
						player:target_Object(matchest.Id, nil, nil, true);
					until clickchest(matchest.Address) ~= true
				end
			until matchest == nil
		end
		function runechests()
			local runechest
			repeat
				runechest = player:findNearestNameOrId(113618,nil,clickchest)
				if runechest then
					teleport(runechest.X,runechest.Z,runechest.Y+11)
					keyboardPress(settings.hotkeys.MOVE_FORWARD.key);
					repeat
						player:target_Object(runechest.Id, nil, nil, true);
					until clickchest(runechest.Address) ~= true
				end
			until runechest == nil
		end
		matchests()
		runechests()
	end
	if player.Y > 15 then
		getunder()
	end
	
	getcandles()
	getchests()
	
player:sleep()

</onLoad>
</waypoints>
