<?xml version="1.0" encoding="utf-8"?><waypoints type="TRAVEL" >
<onload><![CDATA[
	--=== Rock5's MalatinaRepeat ===--
	--===       Version 2.1      ===--

	--=== User Options ===--
	When_Finished = "end"
		-- "end" to end script, "relog" to log next character, "charlist" to log next in 'charlist' and "waypointfilename" to load that waypointfile.
	CharList = {}
		-- Character list to use when using the "charlist" option above. Requires my "userfunction_LoginNextChar" userfunction.
		-- Find it here. http://www.solarstrike.net/phpBB3/viewtopic.php?p=10350
		--		eg.
		--		CharList = {
		--			{account=4,chars={}},
		--			{account=8,chars={1}},
		--			{account=7,chars={1,2,5}},
		--		}
	FirstMalatinaRepeatFile = "survivalr5" -- "survivalr5" or "cot_tele", whichever you do first.
	NextFileToLoad = "survivalr5" -- File to load after changing character. The first file in your chain of files.
	--====================--

	Malatina = 113120
	IWantToLeave = RoMScript("TEXT(\"SC_111813_YU_42\")")
	Confirm = RoMScript("TEXT(\"SC_OKAY\")")

	function checkRelog()
		if When_Finished == "relog" then
			ChangeChar()
			waitForLoadingScreen();
			yrest(3000)
			loadProfile()
			loadPaths(NextFileToLoad);
		elseif When_Finished == "charlist" then
			SetCharList(CharList)
			LoginNextChar()
			loadProfile()
			loadPaths(NextFileToLoad);
		elseif When_Finished == "end" then
			error("Ending script",2)
		else
			if not string.find(When_Finished,".", 1, true) then
				When_Finished = When_Finished .. ".xml"
			end
			local filename = getExecutionPath() .. "/waypoints/" .. When_Finished
			local file, err = io.open(filename, "r");
			if file then
				file:close();
				loadPaths(When_Finished)
			else
				error("'When_Finished' option is invalid",0)
			end
		end
	end

	-- Exit COT if still in COT
	if getZoneId() == 353 and player:target_NPC(Malatina) then
		ChoiceOptionByName(IWantToLeave)
		ChoiceOptionByName(Confirm)
		waitForLoadingScreen()
		yrest(3000)
	end

	-- Use ticket if you have it.
	eventTickets = inventory:itemTotalCount(205814)
	cotTickets = inventory:itemTotalCount(205816)
	survivalTickets = inventory:itemTotalCount(205815)
	coins = inventory:itemTotalCount(203038)

	if coins >= 60 then
		if eventTickets > 0 then -- Both event ticket
			inventory:useItem(205814)
			loadPaths(FirstMalatinaRepeatFile)
		elseif cotTickets > 0 or survivalTickets > 0 then
			inventory:useItem(205815) -- Survival ticket
			inventory:useItem(205816) -- Cot ticket
			loadPaths(FirstMalatinaRepeatFile)
		end
	elseif coins >= 30 then
		if cotTickets > 0 then
			inventory:useItem(205816) -- Cot ticket
			loadPaths(FirstMalatinaRepeatFile)
		elseif survivalTickets > 0 then
			inventory:useItem(205815) -- Survival ticket
			loadPaths(FirstMalatinaRepeatFile)
		end
	else -- coins is < 30
		checkRelog()
	end
]]></onload>
</waypoints>
