<?xml version="1.0" encoding="utf-8"?><waypoints type="TRAVEL" >
<!-- Rock5's Course of Terror waypoint file with teleport -->
<!--   version 1.4 . Thanks to lisa for original script   -->
<onload><![CDATA[
	local zoneid = RoMScript("GetZoneID()")
	if zoneid ~= 2 and zoneid ~= 353 then
		sendMacro("}LoginNextToon=true;a={")
        sendMacro("Logout();"); 
		waitForLoadingScreen();
        loadPaths("cot_tele");
	end


if 50 > player.Level then
player:sleep()
end
	if teleport_GetVersion == nil or  teleport_GetVersion() < 2.0 then
		cprintf(cli.yellow,"This waypoint file requires the userfunction \"teleport\" version 2.0 or newer.\n")
		error("You can download it from this address.",0)
	end

	numshells = inventory:getItemCount(240181)

	Malatina = GetIdName(111813)

	settings.profile.options.WP_NO_STOP = false
	table.insert(settings.profile.friends, "102382") -- adds the barrier to friend so doesn't try to kill it.
	changeProfileOption("HARVEST_DISTANCE", 450);

	function checkaggro()
		--[[repeat
			player:update()
			if player.Battling then
				local clown = player:findEnemy(true)
				player.X = clown.X player.Z = clown.Z -- Temporarily change player coords so we can find nearest seal to mob
				local seal = player:findNearestNameOrId(102384)
				player:target(seal) -- kills the summoning portal and not the ghost clown.
				player:fight()
				yrest(2000) -- give a couple of seconds for the clown to disappear.
				player:update()
			end
		until not player.Battling]]
	end


	function getallkeys()
		local lastSealAddress = 0
		repeat
			player:update()
			local seal = player:findNearestNameOrId(113112, lastSealAddress)
			if seal then
				-- goto seal
				teleport(nil,nil,70) 			-- go up to height if 75
				teleport(seal.X, seal.Z, 75)	-- teleport to above seal
				teleport(seal.X + 1, seal.Z, 57)	-- teleport in range to click seal

				-- click seal
				repeat
					checkaggro()
					player:target(seal)
					yrest(100)
					RoMScript("UseSkill(1,1)")
					yrest(2000)
					player:update()
				until player:findNearestNameOrId(113106) -- until a key appears

				-- Remember last seal
				lastSealAddress = seal.Address

				-- Collect key
				local keys = inventory:itemTotalCount(203027)

				repeat
					checkaggro()
					player:target_Object(113106,nil,nil,true) -- harvests key
				until inventory:itemTotalCount(203027) == keys + 1
				yrest(500)

			end
		until gotAllKeys()
	end

	function gotogate()
		teleport(nil,nil,75) 			-- go up to height if 75
		teleport(4080,3914,75) 		-- teleport to above portal
	end

	function gate()
		repeat
			player:update()
			dist = distance(player.X, player.Z, 4081, 3335)
			keyboardHold( settings.hotkeys.MOVE_FORWARD.key );
			yrest(700)
			keyboardRelease(settings.hotkeys.MOVE_FORWARD.key);
		until 100 > dist or 10 > player.HP
		printf("Distance checked and continuing.\n")
		currentshells = inventory:getItemCount(240181)
	end

	function gotAllKeys()
		local room = currentRoom()
		local keys = inventory:itemTotalCount(203027)
		local keyGoal = (room == 1 and 1) or (room == 2 and 3) or (room == 3 and 6) or (room == 4 and 10)
		return keys >= keyGoal
	end

	function currentRoom()
		return memoryReadRepeat("int",getProc(), player.Address + 0x1c8)
	end

	--[[
	inventory:getItemCount(203027) = keytotal
	if keytotal ~= 0 then
		__WPL:setWaypointIndex(__WPL:findWaypointTag(keytotal));
	end
	]]--
]]></onload>

	<!-- #  1 --><waypoint x="4863" z="-1909" y="112">
		
		player:target_NPC(Malatina);
		sendMacro("ChoiceOption(2);");
		yrest(2000)
		sendMacro("ChoiceOption(1);");
		waitForLoadingScreen()
		fly()
		player:target_NPC(Malatina);
		yrest(2000)
		sendMacro("ChoiceOption(2);");
		yrest(2000)
		sendMacro("ChoiceOption(1);");
		yrest(25000)
	</waypoint>

<!-- JUST BEFORE THE DOOR -->
	<!-- # 11 --><waypoint x="4081" z="3499" y="18" tag="START" >	</waypoint>
<!-- JUST AFTER THE DOOR -->
	<!-- # 12 --><waypoint x="4081" z="3600" y="28" >
		yrest(8000)
		getallkeys()
		gotogate()
	</waypoint>
	<!-- # 15 --><waypoint x="4081" z="3990" y="12">gate()</waypoint>
	<!-- # 10 --><waypoint x="4081" z="3370" y="18">
		-- flyoff()
		yrest(1000)
		if 5 > currentRoom() then -- Not finished. Go again.
			__WPL:setWaypointIndex(__WPL:findWaypointTag("START"));
		end
	</waypoint>

<!-- COLLECT CHESTS -->
	<!-- # 17 --><waypoint x="4081" z="3370" y="18">
	flyoff()
		local filename = getExecutionPath() .. "/logs/shells.log";
		local file, err = io.open(filename, "a+");
		if file then
			file:write(" Character name: " ..player.Name.. "   \tDate: " .. os.date() .. "   \tShells gained: "..currentshells - numshells..
			"\tTotal shells: "..currentshells.. "\n")
			file:close();
		end
		--=== Create table for chests ===--
		chests = {left = {}, right = {}}

		local objectList = CObjectList();
		objectList:update();
		local objSize = objectList:size()

		for i = 0,objSize do
			local obj = objectList:getObject(i);
			if obj.Id == 113114 or obj.Id == 113137 then
				if obj.X > 4081 then -- right side
					table.insert(chests.right, table.copy(obj))
				else -- left side
					table.insert(chests.left, table.copy(obj))
				end
			end
		end

		-- Sort chests
		table.sort(chests.left, function(a,b) return b.Z > a.Z end)
		table.sort(chests.right, function(a,b) return a.Z > b.Z end)

		-- Get left side
		for k,v in pairs(chests.left) do
			memoryWriteInt(getProc(), player.Address + addresses.pawnTargetPtr_offset, v.Address);
			RoMScript("UseSkill(1,1)");
			yrest(2000)
			RoMScript("UseSkill(1,1)");
			yrest(2000)
			repeat
				yrest(2000)
				player:update()
			until not player.Casting
		end

		-- Get right side
		for k,v in pairs(chests.right) do
			memoryWriteInt(getProc(), player.Address + addresses.pawnTargetPtr_offset, v.Address);
			RoMScript("UseSkill(1,1)");
			yrest(2000)
			RoMScript("UseSkill(1,1)");
			yrest(2000)
			repeat
				yrest(2000)
				player:update()
			until not player.Casting
		end
	</waypoint>
	<!-- # 24 --><waypoint x="4081" z="3335" y="18">

		sendMacro("}LoginNextToon=true;a={")
        sendMacro("Logout();"); 
		waitForLoadingScreen();
        loadPaths("cot_tele");
	</waypoint>
</waypoints>
