<?xml version="1.0" encoding="utf-8"?><waypoints>
<onLoad>
--=== V 1.5 ===--

--=== Turn off looting, wastes time ===--
settings.profile.options.LOOT = false

--=== Start of tiles function ===--
function breaktiles()

	--=== all 36 tiles and corresponding ID ===--
	tilecoords = {
		{x="2472", z="2955", id=111811},	
		{x="2504", z="3042", id=111812},
		{x="2503", z="2942", id=111812},	
		{x="2534", z="3032", id=111811},	
		{x="2528", z="2932", id=111811},	
		{x="2564", z="3022", id=111812},	
		{x="2559", z="2921", id=111812},	
		{x="2593", z="3011", id=111811},	
		{x="2590", z="2912", id=111811},	
		{x="2624", z="3001", id=111812},	
		{x="2620", z="2896", id=111812},	
		{x="2652", z="2983", id=111811},
		{x="2484", z="2981", id=111812},	
		{x="2518", z="3071", id=111811},	
		{x="2510", z="2969", id=111811},	
		{x="2545", z="3060", id=111812},	
		{x="2541", z="2959", id=111812},	
		{x="2576", z="3052", id=111811},	
		{x="2573", z="2951", id=111811},	
		{x="2607", z="3040", id=111812},	
		{x="2600", z="2937", id=111812},
		{x="2634", z="3026", id=111811},	
		{x="2629", z="2926", id=111811},	
		{x="2663", z="3018", id=111812},	
		{x="2495", z="3014", id=111811},	
		{x="2525", z="3100", id=111812},	
		{x="2521", z="2995", id=111812},	
		{x="2557", z="3093", id=111811},	
		{x="2552", z="2990", id=111811},	
		{x="2584", z="3079", id=111812},	
		{x="2582", z="2978", id=111812},	
		{x="2615", z="3069", id=111811},	
		{x="2610", z="2970", id=111811},	
		{x="2645", z="3058", id=111812},	
		{x="2641", z="2959", id=111812},	
		{x="2674", z="3048", id=111811},	
	}
	
	
	--=== Don't try to attack the wand ===--
	function evalwand(address)
		local target = CPawn(address);
		if target.Name == "Malatina's Magic Wand" then 
			return false
		else
			return true
		end
	end
	
	--=== look for indicator that the tile is clickable ===--
	function clicktile(address)
		local tmp = memoryReadRepeat("int", getProc(), address + addresses.pawnAttackable_offset) or 0;
		if bitAnd(tmp,0x8) then
			return true
		else
			return false
		end
	end
	
	--=== look for indicator that the chest has loot ===--
	function clickchest(address)
		local chest = memoryReadRepeat("byte", getProc(), address + 0x2F0) or 0
		if chest ~= 0 then
			return true
		else
			return false
		end
	end	
	
	--=== First run of tiles ===--
	function tiles1()
		for i,v in pairs(tilecoords) do
			teleport(v.x,v.z,14)
			tile1 = player:findNearestNameOrId("Treasure Tile", nil)
			local disttile = distance(player.X, player.Z, tile1.X, tile1.Z)
			repeat
				teleport(tile1.X,tile1.Z,14)
				player:target_Object(tile1.Id, nil, nil, true, clicktile);
			until clicktile(tile1.Address) == false
		end
	end
	
	tiles1()
	
	--=== get any left over tiles ===--
	repeat
	tile = player:findNearestNameOrId("Treasure Tile", nil, clicktile)
		if tile then
			teleport(tile.X,tile.Z,14)
			player:target_Object({111811,111812}, nil, nil, true, clicktile);
		end
	until tile == nil
	
	local currshells = inventory:getItemCount(240181)
	
	--=== Open chests ===--
	local function chests()
		local chests = {}
		local objectList = CObjectList();
		objectList:update();
		local objSize = objectList:size()

		for i = 0,objSize do
			local obj = objectList:getObject(i);
			if obj.Name == "Brown wooden chest" then
				table.insert(chests, table.copy(obj))
			end
		end	

		for k,v in pairs(chests) do
			if not RoMScript("TimeKeeperFrame:IsVisible()") then
				player:sleep()
			end
			if clickchest(v.Address) == true then
				teleport(v.X,v.Z,20)
				repeat
					player:target_Object(v.Id, nil, nil, true);
				until clickchest(v.Address) ~= true
			end
		end
	end
	
	--=== doesn't usually break because of shell count ===--
	--=== should break because of TimeKeeperFrame check ===--
	--=== this loop is important though to keep it opening chests ===--
	repeat
		chests()
		yrest(1000)
		inventory:update()
	until currshells ~= inventory:getItemCount(240181)
	player:sleep()
end

breaktiles()
player:sleep()

</onLoad>
</waypoints>