<?xml version="1.0" encoding="utf-8"?><waypoints>

<onLoad>

function relog()
   -- 2 CharLists for 2 clients running at the same time
   SetCharList({{
      {account=1 , chars= {1,2,3}},
      {account=2 , chars= {}},

   },{
      {account=3 , chars= {}},
      {account=4 , chars= {}},
   }})

      LoginNextChar()
      loadProfile()
      loadPaths(__WPL.FileName)
   
end

function logchest()
   local tweakit = 100  --Adjust for ping
   local path = {
{X= -139 , Z= -291, Y= 5 },
{X= -106 , Z= -253, Y= 4 },
{X= -73 , Z= -219, Y= 5 },
{X= -38 , Z= -184, Y= 6 },
{X= -5 , Z= -147, Y= 7 },
{X= 30 , Z= -110, Y= 8 },
{X= 67 , Z= -78, Y= 10 },
{X= 101 , Z= -38, Y= 13 },
{X= 135 , Z= -4, Y= 15 },
{X= 169 , Z= 33, Y= 13 },
{X= 101 , Z= 104, Y= 14 },
{X= 66 , Z= 68, Y= 15 },
{X= 32 , Z= 32, Y= 14 },
{X= -2 , Z= -4, Y= 12 },
{X= -35 , Z= -39, Y= 9 },
{X= -70 , Z= -74, Y= 6 },
{X= -104 , Z= -110, Y= 4 },
{X= -140 , Z= -148, Y= 4 },
{X= -173 , Z= -183, Y= 5 },
{X= -208 , Z= -220, Y= 7 },
{X= -286 , Z= -154, Y= 8 },
{X= -252 , Z= -118, Y= 7 },
{X= -216 , Z= -79, Y= 7 },
{X= -182 , Z= -43, Y= 8 },
{X= -148 , Z= -8, Y= 9 },
{X= -111 , Z= 27, Y= 10 },
{X= -81 , Z= 60, Y= 12 },
{X= -44 , Z= 99, Y= 15 },
{X= -9 , Z= 134, Y= 16 },
}
   player:target_NPC("Kekonee")
   yrest(500)
   RoMScript("ChoiceOption(2)")
   yrest(1000)
   local starttime = os.time()
   local count = 0
   local tablechest = {}
   
   local function openchest()
      local tablechest = {}
      local objectList = CObjectList();
      objectList:update();
      local objSize = objectList:size()
      for i = 0,objSize do
         local obj = objectList:getObject(i);
         if obj.Id == 123536 then
            obj.distance = distance(obj,player)
            table.insert(tablechest, table.copy(obj))
         end
      end
      -- sort by distance
      local function distancesortfunc(a,b)
         return b.distance > a.distance
      end
      table.sort(tablechest, distancesortfunc)
      for i = 1, 2 do
         if (os.time() - starttime) > 60 then break end
         local ttkeeper = os.time()
         if 30 > tablechest[i].distance then
            player:target(tablechest[i].Address)
            yrest(50)
            Attack()
            yrest(500)
            if i == 1 then
               yrest(250+tweakit)
            else
               yrest(400+tweakit)
            end
            count = count + 1
         end
      end
   end
   for i = 1, #path do
      if (os.time() - starttime) > 60 then break end
      teleport(path[i].X,path[i].Z,path[i].Y)
      openchest(true)
   end
   print(count)
end
	
function getchests()	
	local chest
	chest = player:findNearestNameOrId(123536)
	player:target_Object(chest.Id);		
end		
	 
__WPL:setForcedWaypointType("TRAVEL") -- Will ignore mobs
__WPL:setWaypointIndex(1)

</onLoad>

	<!-- #  1 --><waypoint x="3431" z="210" y="44" tag="start">	
		player:target_NPC(123583); -- Kekonee
		sendMacro("ChoiceOption(1);");
		waitForLoadingScreen();
		logchest()
		speed(100); 
	</waypoint>
	
	<!-- #  2 --><waypoint x="43" z="151" y="14" >	getchests(); </waypoint> -- Last 6 chests
	<!-- #  3 --><waypoint x="9" z="187" y="15">	getchests(); </waypoint>
	<!-- #  4 --><waypoint x="-22" z="220" y="18">	getchests(); </waypoint>
	<!-- #  5 --><waypoint x="-59" z="188" y="16">	getchests(); </waypoint>
	<!-- #  6 --><waypoint x="-31" z="157" y="16">	getchests(); </waypoint>
	<!-- #  7 --><waypoint x="-96" z="152" y="16">	getchests(); </waypoint>
	<!-- #  8--><waypoint x="-151" z="-292" y="6">	
		speed(50);
		player:target_NPC(123562); -- Kekonee
		sendMacro("ChoiceOption(1);");
		waitForLoadingScreen();
		yrest(1000)
	
	local item
	for slot = 61, 240 do
    item = inventory.BagSlot[slot]
    item:update()
        if item.Available and (not item.InUse) and item.ItemShopItem == true then
        item:moveTo("itemshop")
		end;
	end;
	
	relog()
	
	</waypoint>
	
</waypoints>