<?xml version="1.0" encoding="utf-8"?><waypoints>
<onload>
table.insert(settings.profile.friends, "102382") -- adds the barrier to friend so doesn't try to kill it.
-- changeProfileNames("friends", "102382") -- personal userfunction
changeProfileOption("HARVEST_DISTANCE", 300);

function getkey(keys)
repeat
if not player.Battling  then
	if not player:findNearestNameOrId(113106) then
		player:target_Object(113112,3000,nil,true) -- opens seal to reveal key
	else
	yrest(2000)
		player:target_Object(113106,3000,nil,true) -- harvests key
	end
else
	player:target(102384) -- kills the summoning portal and not the ghost clown, not sure if this code is working.
	fight()
end
until inventory:getItemCount(203027) == keys -- repeats until it has the specified number of keys.
end

function gate()
	repeat
	player:update()
	dist = distance(player.X, player.Z, 4080, 3499)
	keyboardHold( settings.hotkeys.MOVE_FORWARD.key );
	yrest(700)
	keyboardRelease(settings.hotkeys.MOVE_FORWARD.key);
	until 100 > dist
	printf("Distance checked and continuing.\n")
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(1000)
		sendMacro("ChoiceOption(1);");
		waitForLoadingScreen()
		player:target_NPC("Malatina");
		sendMacro("ChoiceOption(2);");
		yrest(1000)
		sendMacro("ChoiceOption(1);");
		yrest(25000)
		

	</waypoint>
	<!-- # 10 --><waypoint x="4080" z="3499" y="18">		fly()
	</waypoint>
	<!-- # 12 --><waypoint x="4081" z="3586" y="28">	</waypoint>
	<!-- # 13 --><waypoint x="4088" z="3742" y="132">
getkey(1)
	</waypoint>
	<!-- # 13 --><waypoint x="4088" z="3742" y="132"></waypoint> 
	
	<!-- # 15 --><waypoint x="4080" z="3990" y="12">gate()</waypoint> 
	<!-- # 10 --><waypoint x="4080" z="3499" y="18">		
	</waypoint>
	<!-- # 12 --><waypoint x="4081" z="3586" y="28">	</waypoint>
	<!-- # 13 --><waypoint x="4088" z="3742" y="132">		
getkey(2)
	</waypoint>	
	<!-- # 13 --><waypoint x="4088" z="3742" y="132">		
getkey(3)
	</waypoint>	
<!-- # 13 --><waypoint x="4088" z="3742" y="132"></waypoint> 
	
	<!-- # 15 --><waypoint x="4080" z="3990" y="12">gate()</waypoint> 
	<!-- # 10 --><waypoint x="4080" z="3499" y="18">		
	</waypoint>
	<!-- # 12 --><waypoint x="4081" z="3586" y="28">	</waypoint>
	<!-- # 13 --><waypoint x="4088" z="3742" y="132">		
getkey(4)
	</waypoint>	
	<!-- # 13 --><waypoint x="4088" z="3742" y="132">		
getkey(5)
	</waypoint>	
		<!-- # 13 --><waypoint x="4088" z="3742" y="132">		
getkey(6)
	</waypoint>	
	<!-- # 13 --><waypoint x="4088" z="3742" y="132"></waypoint> 
	<!-- # 15 --><waypoint x="4080" z="3990" y="12">gate()</waypoint>  
	<!-- # 10 --><waypoint x="4080" z="3499" y="18">			
	</waypoint>
	<!-- # 12 --><waypoint x="4081" z="3586" y="28">	</waypoint>
	<!-- # 13 --><waypoint x="4088" z="3742" y="132">		
getkey(7)
	</waypoint>	
	<!-- # 13 --><waypoint x="4088" z="3742" y="132">		
getkey(8)
	</waypoint>	
		<!-- # 13 --><waypoint x="4088" z="3742" y="132">		
getkey(9)
	</waypoint>	
	
	<!-- # 13 --><waypoint x="4088" z="3742" y="132">		
getkey(10)
	</waypoint>	
	<!-- # 13 --><waypoint x="4088" z="3742" y="132"> </waypoint> 	
	<!-- # 15 --><waypoint x="4080" z="3990" y="12">gate()</waypoint> 

	<!-- # 17 --><waypoint x="4031" z="3377" y="23"> flyoff() </waypoint> 
	<!-- # 24 --><waypoint x="4133" z="3370" y="23">
	chests = {}
		--=== Createtable for chests ===--
	local objectList = CObjectList();
	objectList:update();
	local objSize = objectList:size()
	
	for i = 0,objSize do 
		obj = objectList:getObject(i);
		if obj.Id == 113114 or obj.Id == 113137 then
			table.insert(chests, {Address = obj.Address, Name = obj.Name, Id = obj.Id})
		end
	end
	
	for k,v in pairs(chests) do
		memoryWriteInt(getProc(), player.Address + addresses.pawnTargetPtr_offset, v.Address);
		RoMScript("UseSkill(1,1)");
		yrest(2000)
		RoMScript("UseSkill(1,1)");
		yrest(8000)
	end
		</waypoint>
	<!-- # 24 --><waypoint x="4133" z="3370" y="23">		
	player:target_NPC("Malatina");
		sendMacro("ChoiceOption(1);");
		yrest(1000)
		sendMacro("ChoiceOption(1);");
		waitForLoadingScreen()
		player:sleep()
	</waypoint>
</waypoints>