<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.atitd.org/wiki/t5w/index.php?action=history&amp;feed=atom&amp;title=User%3AKasiya%2Fflax</id>
	<title>User:Kasiya/flax - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://www.atitd.org/wiki/t5w/index.php?action=history&amp;feed=atom&amp;title=User%3AKasiya%2Fflax"/>
	<link rel="alternate" type="text/html" href="http://www.atitd.org/wiki/t5w/index.php?title=User:Kasiya/flax&amp;action=history"/>
	<updated>2026-06-06T03:02:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>http://www.atitd.org/wiki/t5w/index.php?title=User:Kasiya/flax&amp;diff=16830&amp;oldid=prev</id>
		<title>Kasiya: Flax, flax_seeds and flax_common from 1.5.2 (working)</title>
		<link rel="alternate" type="text/html" href="http://www.atitd.org/wiki/t5w/index.php?title=User:Kasiya/flax&amp;diff=16830&amp;oldid=prev"/>
		<updated>2010-09-09T23:20:17Z</updated>

		<summary type="html">&lt;p&gt;Flax, flax_seeds and flax_common from 1.5.2 (working)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;flax.lua&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-- Edit these first 2 to adjust how much is planted in a pass&lt;br /&gt;
-- May need to adjust walk_time in flax_common.inc if you move too slowly to keep up&lt;br /&gt;
-- grids tested: 2x2, 3x3, 5x5, 6x6 (probably need 3+ dex and 600ms walk time)&lt;br /&gt;
grid_w = 5;&lt;br /&gt;
grid_h = 5;&lt;br /&gt;
&lt;br /&gt;
loadfile(&amp;quot;luaScripts/flax_common.inc&amp;quot;)();&lt;br /&gt;
loadfile(&amp;quot;luaScripts/screen_reader_common.inc&amp;quot;)();&lt;br /&gt;
loadfile(&amp;quot;luaScripts/ui_utils.inc&amp;quot;)();&lt;br /&gt;
&lt;br /&gt;
-- Just testing spiral algorithm, ignore this...&lt;br /&gt;
function spiraltest()&lt;br /&gt;
	-- for spiral&lt;br /&gt;
	local dxi=1;&lt;br /&gt;
	local dt_max=grid_w;&lt;br /&gt;
	local dt=grid_w;&lt;br /&gt;
	local dx={1, 0, -1, 0};&lt;br /&gt;
	local dy={0, -1, 0, 1};&lt;br /&gt;
	local num_at_this_length = 3;&lt;br /&gt;
	&lt;br /&gt;
	-- Plant and pin&lt;br /&gt;
	for y=1, grid_h do&lt;br /&gt;
		for x=1, grid_w do&lt;br /&gt;
			lsPrintln('doing ' .. x .. ',' .. y);&lt;br /&gt;
&lt;br /&gt;
			-- move to next position&lt;br /&gt;
			if not ((x == grid_w) and (y == grid_h)) then&lt;br /&gt;
				lsPrintln('walking dx=' .. dx[dxi] .. ' dy=' .. dy[dxi]);&lt;br /&gt;
				dt = dt - 1;&lt;br /&gt;
				if dt == 1 then&lt;br /&gt;
					dxi = dxi + 1;&lt;br /&gt;
					num_at_this_length = num_at_this_length - 1;&lt;br /&gt;
					if num_at_this_length == 0 then&lt;br /&gt;
						dt_max = dt_max - 1;&lt;br /&gt;
						num_at_this_length = 2;&lt;br /&gt;
					end&lt;br /&gt;
					if dxi == 5 then&lt;br /&gt;
						dxi = 1;&lt;br /&gt;
					end&lt;br /&gt;
					dt = dt_max;&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				lsPrintln('skipping walking, on last leg');&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function doit()&lt;br /&gt;
	-- num_loops = promptNumber(&amp;quot;How many &amp;quot; .. grid_w .. &amp;quot;x&amp;quot; .. grid_h .. &amp;quot; passes ?&amp;quot;, 5);&lt;br /&gt;
	promptFlaxNumbers(1);&lt;br /&gt;
&lt;br /&gt;
	askForWindow(&amp;quot;Make sure the plant flax window is pinned and you are in F8F8 cam zoomed in.  You may need to F12 at low resolutions or hide your chat window (if it starts planting and fails to move downward, it probably clicked on your chat window).  Will plant grid NE of current location.  'Plant all crops where you stand' must be ON.  'Right click pins/unpins a menu' must be ON.&amp;quot;);&lt;br /&gt;
	&lt;br /&gt;
	initGlobals();&lt;br /&gt;
	&lt;br /&gt;
	local went_to_seeds = 0; -- Don't loop if we lost one, it'll mess us up!&lt;br /&gt;
	srReadScreen();&lt;br /&gt;
	local xyPlantFlax = srFindImage(imgFlax1);&lt;br /&gt;
	if not xyPlantFlax then&lt;br /&gt;
		xyPlantFlax = srFindImage(imgFlax2);&lt;br /&gt;
		if not xyPlantFlax then&lt;br /&gt;
			error 'Could not find plant window';&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	xyPlantFlax[0] = xyPlantFlax[0] + 5;&lt;br /&gt;
	local xyCenter = getCenterPos();&lt;br /&gt;
	local xyFlaxMenu = {};&lt;br /&gt;
	xyFlaxMenu[0] = xyCenter[0] - 43;&lt;br /&gt;
	xyFlaxMenu[1] = xyCenter[1] + 0;&lt;br /&gt;
	&lt;br /&gt;
	for loop_count=1, num_loops do&lt;br /&gt;
		&lt;br /&gt;
		-- for spiral&lt;br /&gt;
		local dxi=1;&lt;br /&gt;
		local dt_max=grid_w;&lt;br /&gt;
		local dt=grid_w;&lt;br /&gt;
		local dx={1, 0, -1, 0};&lt;br /&gt;
		local dy={0, -1, 0, 1};&lt;br /&gt;
		local num_at_this_length = 3;&lt;br /&gt;
		local x_pos = 0;&lt;br /&gt;
		local y_pos = 0;&lt;br /&gt;
		&lt;br /&gt;
		-- Plant and pin&lt;br /&gt;
		for y=1, grid_h do&lt;br /&gt;
			for x=1, grid_w do&lt;br /&gt;
				lsPrintln('doing ' .. x .. ',' .. y .. ' of ' .. grid_w .. ',' .. grid_h);&lt;br /&gt;
	&lt;br /&gt;
				statusScreen(&amp;quot;(&amp;quot; .. loop_count .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Planting &amp;quot; .. x .. &amp;quot;, &amp;quot; .. y);&lt;br /&gt;
	&lt;br /&gt;
				-- Plant&lt;br /&gt;
				lsPrintln('planting ' .. xyPlantFlax[0] .. ',' .. xyPlantFlax[1]);&lt;br /&gt;
				setWaitSpot(xyFlaxMenu[0], xyFlaxMenu[1]);&lt;br /&gt;
				srClickMouseNoMove(xyPlantFlax[0], xyPlantFlax[1], 0);&lt;br /&gt;
				srSetMousePos(xyFlaxMenu[0], xyFlaxMenu[1]);&lt;br /&gt;
				waitForChange();&lt;br /&gt;
				-- lsSleep(delay_time);&lt;br /&gt;
				&lt;br /&gt;
				-- Bring up menu&lt;br /&gt;
				lsPrintln('menu ' .. xyFlaxMenu[0] .. ',' .. xyFlaxMenu[1]);&lt;br /&gt;
				setWaitSpot(xyFlaxMenu[0]+5, xyFlaxMenu[1]);&lt;br /&gt;
				srClickMouse(xyFlaxMenu[0], xyFlaxMenu[1], 0);&lt;br /&gt;
				waitForChange();&lt;br /&gt;
				-- lsSleep(delay_time);&lt;br /&gt;
				&lt;br /&gt;
				-- Check for window size&lt;br /&gt;
				checkWindowSize(xyFlaxMenu[0], xyFlaxMenu[1]);&lt;br /&gt;
				&lt;br /&gt;
				-- Pin&lt;br /&gt;
				lsPrintln('pin ' .. (xyFlaxMenu[0]+5) .. ',' .. xyFlaxMenu[1]);&lt;br /&gt;
				srClickMouseNoMove(xyFlaxMenu[0]+5, xyFlaxMenu[1]+0, 1);&lt;br /&gt;
				-- lsSleep(delay_time);&lt;br /&gt;
				&lt;br /&gt;
				-- Move window&lt;br /&gt;
				local pp = pinnedPos(x, y);&lt;br /&gt;
				lsPrintln('move ' .. (xyFlaxMenu[0]+5) .. ',' .. xyFlaxMenu[1] .. ' to ' .. pp[0] .. ',' .. pp[1]);&lt;br /&gt;
				drag(xyFlaxMenu[0] + 5, xyFlaxMenu[1],&lt;br /&gt;
					pp[0], pp[1], 0);&lt;br /&gt;
				-- lsSleep(delay_time);&lt;br /&gt;
&lt;br /&gt;
				-- move to next position&lt;br /&gt;
				if not ((x == grid_w) and (y == grid_h)) then&lt;br /&gt;
					lsPrintln('walking dx=' .. dx[dxi] .. ' dy=' .. dy[dxi]);&lt;br /&gt;
					x_pos = x_pos + dx[dxi];&lt;br /&gt;
					y_pos = y_pos + dy[dxi];&lt;br /&gt;
					srClickMouseNoMove(xyCenter[0] + walk_px_x*dx[dxi], xyCenter[1] + walk_px_y*dy[dxi], 0);&lt;br /&gt;
					lsSleep(walk_time);&lt;br /&gt;
					dt = dt - 1;&lt;br /&gt;
					if dt == 1 then&lt;br /&gt;
						dxi = dxi + 1;&lt;br /&gt;
						num_at_this_length = num_at_this_length - 1;&lt;br /&gt;
						if num_at_this_length == 0 then&lt;br /&gt;
							dt_max = dt_max - 1;&lt;br /&gt;
							num_at_this_length = 2;&lt;br /&gt;
						end&lt;br /&gt;
						if dxi == 5 then&lt;br /&gt;
							dxi = 1;&lt;br /&gt;
						end&lt;br /&gt;
						dt = dt_max;&lt;br /&gt;
					end&lt;br /&gt;
				else&lt;br /&gt;
					lsPrintln('skipping walking, on last leg');&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			checkBreak();&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		statusScreen(&amp;quot;(&amp;quot; .. loop_count .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Refocusing windows...&amp;quot;);&lt;br /&gt;
		&lt;br /&gt;
		-- Bring windows to front&lt;br /&gt;
		for y=grid_h, 1, -1 do&lt;br /&gt;
			for x=grid_w, 1, -1 do &lt;br /&gt;
				local rp = refreshPosUp(x, y);&lt;br /&gt;
				srClickMouseNoMove(rp[0], rp[1], 0);&lt;br /&gt;
				lsSleep(refocus_click_time);&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		lsSleep(refocus_time); -- Wait for last window to bring to the foreground before clicking again&lt;br /&gt;
		&lt;br /&gt;
		local did_harvest=false;&lt;br /&gt;
		local water_step = 0;&lt;br /&gt;
		while not did_harvest do&lt;br /&gt;
			-- Monitor for Weed This/etc&lt;br /&gt;
			water_step = water_step + 1;&lt;br /&gt;
			for y=1, grid_h do&lt;br /&gt;
				for x=1, grid_w do &lt;br /&gt;
					statusScreen(&amp;quot;(&amp;quot; .. loop_count .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Weeding/Harvest step &amp;quot; .. water_step);&lt;br /&gt;
					local pp = pinnedPos(x, y);&lt;br /&gt;
					local rp = refreshPosDown(x, y);&lt;br /&gt;
					local seeds_retry=3;&lt;br /&gt;
					while 1 do&lt;br /&gt;
						srClickMouseNoMove(rp[0], rp[1], 0);&lt;br /&gt;
						lsSleep(screen_refresh_time);&lt;br /&gt;
						srReadScreen();&lt;br /&gt;
						local weed = srFindImageInRange(imgWeed, pp[0], pp[1] - 50, 120, 100);&lt;br /&gt;
						if weed then&lt;br /&gt;
							srClickMouseNoMove(weed[0] + 5, weed[1], 0);&lt;br /&gt;
							break;&lt;br /&gt;
						end&lt;br /&gt;
						local weed = srFindImageInRange(imgWeedAndWater, pp[0], pp[1] - 50, 120, 100);&lt;br /&gt;
						if weed then&lt;br /&gt;
							srClickMouseNoMove(weed[0] + 5, weed[1], 0);&lt;br /&gt;
							break;&lt;br /&gt;
						end&lt;br /&gt;
						local harvest = srFindImageInRange(imgHarvest, pp[0], pp[1] - 50, 110, 100);&lt;br /&gt;
						if harvest then&lt;br /&gt;
							srClickMouseNoMove(harvest[0] + 5, harvest[1], 0);&lt;br /&gt;
							srClickMouseNoMove(pp[0], pp[1], 1); -- unpin&lt;br /&gt;
							did_harvest = true;&lt;br /&gt;
							break;&lt;br /&gt;
						end&lt;br /&gt;
						local seeds = srFindImageInRange(imgSeeds, pp[0], pp[1] - 50, 120, 100);&lt;br /&gt;
						if seeds then&lt;br /&gt;
							seeds_retry = seeds_retry - 1;&lt;br /&gt;
							if (seeds_retry == 0) then&lt;br /&gt;
								if nil then -- Don't do this, it causes us to walk out of range of the rest!&lt;br /&gt;
									lsPrintln('Went to seed, grabbing the seeds and ignoring.');&lt;br /&gt;
									srClickMouseNoMove(seeds[0] + 5, seeds[1], 0);&lt;br /&gt;
								end&lt;br /&gt;
								srSetMousePos(pp[0]+5, pp[1]+37);&lt;br /&gt;
								lsSleep(100);&lt;br /&gt;
								srClickMouseNoMove(pp[0]+5, pp[1]+37, 0); -- Utility&lt;br /&gt;
								lsSleep(100);&lt;br /&gt;
								srReadScreen();&lt;br /&gt;
								local rip = srFindImage(&amp;quot;FlaxRipOut.png&amp;quot;);&lt;br /&gt;
								if rip then&lt;br /&gt;
									srClickMouseNoMove(rip[0] + 5, rip[1] + 2, 0); -- Rip out&lt;br /&gt;
								else&lt;br /&gt;
									error 'Flax went to seed, but failed to find rip out option';&lt;br /&gt;
								end&lt;br /&gt;
								lsSleep(100);&lt;br /&gt;
							&lt;br /&gt;
								srClickMouseNoMove(pp[0]-3, pp[1], 1); -- unpin&lt;br /&gt;
								went_to_seeds = 1;&lt;br /&gt;
								did_harvest = true;&lt;br /&gt;
								break;&lt;br /&gt;
							end&lt;br /&gt;
						end&lt;br /&gt;
						checkBreak();&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
				&lt;br /&gt;
			-- Bring windows to front&lt;br /&gt;
			if not did_harvest then&lt;br /&gt;
				statusScreen(&amp;quot;(&amp;quot; .. loop_count .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Refocusing windows...&amp;quot;);&lt;br /&gt;
				for y=grid_h, 1, -1 do&lt;br /&gt;
					for x=grid_w, 1, -1 do &lt;br /&gt;
						local rp = refreshPosUp(x, y);&lt;br /&gt;
						srClickMouseNoMove(rp[0], rp[1], 0);&lt;br /&gt;
						lsSleep(refocus_click_time);&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
				lsSleep(refocus_time); -- Wait for last window to bring to the foreground before clicking again&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		lsSleep(2500); -- Wait for last flax bed to disappear before accidentally clicking on it!&lt;br /&gt;
		statusScreen(&amp;quot;(&amp;quot; .. loop_count .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Walking...&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		if went_to_seeds == 0 then	&lt;br /&gt;
			-- Walk back&lt;br /&gt;
			for x=1, x_pos do&lt;br /&gt;
				srClickMouseNoMove(xyCenter[0] + walk_px_x*-1, xyCenter[1], 0);&lt;br /&gt;
				lsSleep(walk_time);&lt;br /&gt;
			end&lt;br /&gt;
			for x=1, -y_pos do&lt;br /&gt;
				srClickMouseNoMove(xyCenter[0], xyCenter[1] + walk_px_y, 0);&lt;br /&gt;
				lsSleep(walk_time);&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		if went_to_seeds and not loop_count == num_loops then&lt;br /&gt;
			error 'Some of the plants went to seeds, stopping loop'&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	lsPlaySound(&amp;quot;Complete.wav&amp;quot;);&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
flax_seeds.lua&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-- This script has not yet been updated to use the new UI utilties&lt;br /&gt;
-- See flax.lua instead&lt;br /&gt;
&lt;br /&gt;
-- Edit these first 3 to adjust how much is planted in a pass and how many passes&lt;br /&gt;
-- May need to adjust walk_time in flax_common.inc if you move too slowly to keep up&lt;br /&gt;
-- grids tested up to 7x7, can probably do more&lt;br /&gt;
grid_w = 5;&lt;br /&gt;
grid_h = 5;&lt;br /&gt;
&lt;br /&gt;
harvest_seeds_time = 1300;&lt;br /&gt;
&lt;br /&gt;
loadfile(&amp;quot;luaScripts/flax_common.inc&amp;quot;)();&lt;br /&gt;
loadfile(&amp;quot;luaScripts/screen_reader_common.inc&amp;quot;)();&lt;br /&gt;
loadfile(&amp;quot;luaScripts/ui_utils.inc&amp;quot;)();&lt;br /&gt;
&lt;br /&gt;
-- Harvest seeds&lt;br /&gt;
function doit()&lt;br /&gt;
	--num_loops = promptNumber(&amp;quot;How many &amp;quot; .. grid_w .. &amp;quot;x&amp;quot; .. grid_h .. &amp;quot; passes ?&amp;quot;, 5);&lt;br /&gt;
	promptFlaxNumbers(false);&lt;br /&gt;
	askForWindow(&amp;quot;Make sure the plant flax window is pinned and you are in F8F8 cam zoomed in.  You may need to F12 at low resolutions or hide your chat window (if it starts planting and fails to move downward, it probably clicked on your chat window).  Will plant grid NE of current location.  'Plant all crops where you stand' must be ON.  'Right click pins/unpins a menu' must be ON.&amp;quot;);&lt;br /&gt;
	initGlobals();&lt;br /&gt;
	srReadScreen();&lt;br /&gt;
	local xyPlantFlax = srFindImage(imgFlax1);&lt;br /&gt;
	if not xyPlantFlax then&lt;br /&gt;
		xyPlantFlax = srFindImage(imgFlax2);&lt;br /&gt;
		if not xyPlantFlax then&lt;br /&gt;
			error 'Could not find plant window';&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	xyPlantFlax[0] = xyPlantFlax[0] + 5;&lt;br /&gt;
	local xyCenter = getCenterPos();&lt;br /&gt;
	local xyFlaxMenu = {};&lt;br /&gt;
	xyFlaxMenu[0] = xyCenter[0] - 43;&lt;br /&gt;
	xyFlaxMenu[1] = xyCenter[1] + 0;&lt;br /&gt;
	&lt;br /&gt;
	-- for spiral&lt;br /&gt;
	local dxi=1;&lt;br /&gt;
	local dt_max=grid_w;&lt;br /&gt;
	local dt=grid_w;&lt;br /&gt;
	local dx={1, 0, -1, 0};&lt;br /&gt;
	local dy={0, -1, 0, 1};&lt;br /&gt;
	local num_at_this_length = 3;&lt;br /&gt;
	local x_pos = 0;&lt;br /&gt;
	local y_pos = 0;&lt;br /&gt;
	&lt;br /&gt;
	-- Plant and pin&lt;br /&gt;
	for y=1, grid_h do&lt;br /&gt;
		for x=1, grid_w do&lt;br /&gt;
			lsPrintln('doing ' .. x .. ',' .. y);&lt;br /&gt;
			&lt;br /&gt;
			statusScreen(&amp;quot;Planting...&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
			-- Plant&lt;br /&gt;
			lsPrintln('planting ' .. xyPlantFlax[0] .. ',' .. xyPlantFlax[1]);&lt;br /&gt;
			setWaitSpot(xyFlaxMenu[0], xyFlaxMenu[1]);&lt;br /&gt;
			srClickMouseNoMove(xyPlantFlax[0], xyPlantFlax[1], 0);&lt;br /&gt;
			srSetMousePos(xyFlaxMenu[0], xyFlaxMenu[1]);&lt;br /&gt;
			waitForChange();&lt;br /&gt;
			-- lsSleep(delay_time);&lt;br /&gt;
			&lt;br /&gt;
			-- Bring up menu&lt;br /&gt;
			lsPrintln('menu ' .. xyFlaxMenu[0] .. ',' .. xyFlaxMenu[1]);&lt;br /&gt;
			setWaitSpot(xyFlaxMenu[0]+5, xyFlaxMenu[1]);&lt;br /&gt;
			srClickMouse(xyFlaxMenu[0], xyFlaxMenu[1], 0);&lt;br /&gt;
			waitForChange();&lt;br /&gt;
			-- lsSleep(delay_time);&lt;br /&gt;
			&lt;br /&gt;
			-- Pin&lt;br /&gt;
			lsPrintln('pin ' .. (xyFlaxMenu[0]+5) .. ',' .. xyFlaxMenu[1]);&lt;br /&gt;
			srClickMouseNoMove(xyFlaxMenu[0]+5, xyFlaxMenu[1]+0, 1);&lt;br /&gt;
			-- lsSleep(delay_time);&lt;br /&gt;
			&lt;br /&gt;
			-- Check for window size&lt;br /&gt;
			checkWindowSize(xyFlaxMenu[0], xyFlaxMenu[1]);&lt;br /&gt;
			&lt;br /&gt;
			-- Move window&lt;br /&gt;
			local pp = pinnedPos(x, y);&lt;br /&gt;
			lsPrintln('move ' .. (xyFlaxMenu[0]+5) .. ',' .. xyFlaxMenu[1] .. ' to ' .. pp[0] .. ',' .. pp[1]);&lt;br /&gt;
			drag(xyFlaxMenu[0] + 5, xyFlaxMenu[1],&lt;br /&gt;
				pp[0], pp[1], 0);&lt;br /&gt;
			-- lsSleep(delay_time);&lt;br /&gt;
&lt;br /&gt;
			-- move to next position&lt;br /&gt;
			if not ((x == grid_w) and (y == grid_h)) then&lt;br /&gt;
				lsPrintln('walking dx=' .. dx[dxi] .. ' dy=' .. dy[dxi]);&lt;br /&gt;
				x_pos = x_pos + dx[dxi];&lt;br /&gt;
				y_pos = y_pos + dy[dxi];&lt;br /&gt;
				srClickMouseNoMove(xyCenter[0] + walk_px_x*dx[dxi], xyCenter[1] + walk_px_y*dy[dxi], 0);&lt;br /&gt;
				lsSleep(walk_time);&lt;br /&gt;
				dt = dt - 1;&lt;br /&gt;
				if dt == 1 then&lt;br /&gt;
					dxi = dxi + 1;&lt;br /&gt;
					num_at_this_length = num_at_this_length - 1;&lt;br /&gt;
					if num_at_this_length == 0 then&lt;br /&gt;
						dt_max = dt_max - 1;&lt;br /&gt;
						num_at_this_length = 2;&lt;br /&gt;
					end&lt;br /&gt;
					if dxi == 5 then&lt;br /&gt;
						dxi = 1;&lt;br /&gt;
					end&lt;br /&gt;
					dt = dt_max;&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				lsPrintln('skipping walking, on last leg');&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if (lsShiftHeld() and lsControlHeld()) then&lt;br /&gt;
			error 'broke out of loop from Shift+Ctrl';&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	for loop_count=1, num_loops do&lt;br /&gt;
		&lt;br /&gt;
		statusScreen(&amp;quot;(&amp;quot; .. loop_count .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Refocusing&amp;quot;);&lt;br /&gt;
		-- Bring windows to front&lt;br /&gt;
		for y=grid_h, 1, -1 do&lt;br /&gt;
			for x=grid_w, 1, -1 do &lt;br /&gt;
				local rp = refreshPosUp(x, y);&lt;br /&gt;
				srClickMouseNoMove(rp[0], rp[1], 0);&lt;br /&gt;
				lsSleep(refocus_click_time);&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		lsSleep(refocus_time); -- Wait for last window to bring to the foreground before continuing&lt;br /&gt;
	&lt;br /&gt;
		-- And harvest&lt;br /&gt;
		for y=1, grid_h do&lt;br /&gt;
			for x=1, grid_w do &lt;br /&gt;
&lt;br /&gt;
				statusScreen(&amp;quot;(&amp;quot; .. loop_count .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Harvesting &amp;quot; .. x .. &amp;quot;, &amp;quot; .. y);&lt;br /&gt;
				&lt;br /&gt;
				local pp = pinnedPos(x, y);&lt;br /&gt;
				local rp = refreshPosDown(x, y);&lt;br /&gt;
				while 1 do&lt;br /&gt;
					srClickMouseNoMove(rp[0], rp[1], 0);&lt;br /&gt;
					lsSleep(screen_refresh_time);&lt;br /&gt;
					srReadScreen();&lt;br /&gt;
					local seeds = srFindImageInRange(imgSeeds, pp[0], pp[1] - 50, 160, 100);&lt;br /&gt;
					if seeds then&lt;br /&gt;
						srClickMouseNoMove(seeds[0] + 5, seeds[1], 0);&lt;br /&gt;
						lsSleep(harvest_seeds_time);&lt;br /&gt;
						break;&lt;br /&gt;
					end&lt;br /&gt;
					checkBreak();&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	statusScreen(&amp;quot;Refocusing&amp;quot;);&lt;br /&gt;
	-- Bring windows to front&lt;br /&gt;
	for y=grid_h, 1, -1 do&lt;br /&gt;
		for x=grid_w, 1, -1 do &lt;br /&gt;
			local rp = refreshPosUp(x, y);&lt;br /&gt;
			srClickMouseNoMove(rp[0], rp[1], 0);&lt;br /&gt;
			lsSleep(refocus_click_time);&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	lsSleep(refocus_time); -- Wait for last window to bring to the foreground before continuing&lt;br /&gt;
	&lt;br /&gt;
	-- and clean up!&lt;br /&gt;
	for y=1, grid_h do&lt;br /&gt;
		for x=1, grid_w do &lt;br /&gt;
			local rp = refreshPosDown(x, y);&lt;br /&gt;
			srClickMouseNoMove(rp[0], rp[1], 1); -- unpin&lt;br /&gt;
			lsSleep(refocus_click_time);&lt;br /&gt;
			checkBreak();&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	lsPlaySound(&amp;quot;Complete.wav&amp;quot;);&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
flax_common.inc&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Also using these for other planting automation&lt;br /&gt;
&lt;br /&gt;
xyWindowSize = srGetWindowSize();&lt;br /&gt;
imgFlax1 = &amp;quot;FlaxOldEgypt.png&amp;quot;;&lt;br /&gt;
imgFlax2 = &amp;quot;FlaxNileGreen.png&amp;quot;;&lt;br /&gt;
imgHarvest = &amp;quot;HarvestThisFlax.png&amp;quot;;&lt;br /&gt;
imgWeedAndWater = &amp;quot;WeedAndWater.png&amp;quot;;&lt;br /&gt;
imgWeed = &amp;quot;WeedThisFlaxBed.png&amp;quot;;&lt;br /&gt;
imgSeeds = &amp;quot;HarvestSeeds.png&amp;quot;;&lt;br /&gt;
imgHarvestThese = &amp;quot;HarvestThese.png&amp;quot;;&lt;br /&gt;
imgWeedThese = &amp;quot;WeedThese.png&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
delay_time = 100;&lt;br /&gt;
screen_refresh_time = 110;&lt;br /&gt;
walk_px_y = 340;&lt;br /&gt;
walk_px_x = 380;&lt;br /&gt;
walk_y_drift = 18;&lt;br /&gt;
walk_x_drift = 14;&lt;br /&gt;
walk_time = 570;&lt;br /&gt;
refocus_time = 500;&lt;br /&gt;
refocus_click_time = 100;&lt;br /&gt;
&lt;br /&gt;
function initGlobals()&lt;br /&gt;
	pixel_scale = xyWindowSize[0] / 1720; -- Macro written with 1720 pixel wide window&lt;br /&gt;
	lsPrintln(&amp;quot;pixel_scale &amp;quot; .. pixel_scale);&lt;br /&gt;
&lt;br /&gt;
	walk_px_y = math.floor(walk_px_y * pixel_scale);&lt;br /&gt;
	walk_px_x = math.floor(walk_px_x * pixel_scale);&lt;br /&gt;
	if (lsScreenX &amp;lt; 1280) then&lt;br /&gt;
		-- Have to click way off center in order to not move at high resoltuions&lt;br /&gt;
		walk_y_drift = math.floor(walk_y_drift * pixel_scale);&lt;br /&gt;
		walk_x_drift = math.floor(walk_x_drift * pixel_scale);&lt;br /&gt;
	else&lt;br /&gt;
		-- Very little drift at these resolutions, clicking dead center barely moves&lt;br /&gt;
		walk_y_drift = 1;&lt;br /&gt;
		walk_x_drift = 1;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- The flax bed window&lt;br /&gt;
-- T4, guilded?: window_w = 166;&lt;br /&gt;
-- T4, guilded?: window_h = 116;&lt;br /&gt;
window_w = 174;&lt;br /&gt;
window_h = 100;&lt;br /&gt;
refresh_down_y_offs = 4;&lt;br /&gt;
refresh_up_y_offs = 0;&lt;br /&gt;
&lt;br /&gt;
-- adjust if &amp;quot;plant all guild owned&amp;quot; option is enabled&lt;br /&gt;
window_check_done_once = false;&lt;br /&gt;
function checkWindowSize(x, y)&lt;br /&gt;
	if not window_check_done_once then&lt;br /&gt;
		srReadScreen();&lt;br /&gt;
		window_check_done_once = true;&lt;br /&gt;
		local pos = srFindImageInRange(&amp;quot;UseableBy.png&amp;quot;, x-5, y-50, 150, 100)&lt;br /&gt;
		if pos then&lt;br /&gt;
			window_w = 166;&lt;br /&gt;
			window_h = 116;&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- position to drag window to&lt;br /&gt;
function pinnedPos(x, y)&lt;br /&gt;
	local ret = {};&lt;br /&gt;
	ret[0] = xyWindowSize[0] - 25*(x-1) - (window_w - 5);&lt;br /&gt;
	ret[1] = (y-1)*14 + (window_h/2) + 2;&lt;br /&gt;
	lsPrintln(&amp;quot;pinnedPos(&amp;quot; .. x .. &amp;quot;,&amp;quot; .. y .. &amp;quot;)=&amp;quot; .. ret[0] .. &amp;quot;,&amp;quot; .. ret[1]);&lt;br /&gt;
	return ret;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function refreshPosUp(x, y)&lt;br /&gt;
	local ret = pinnedPos(x, y);&lt;br /&gt;
	ret[0] = ret[0] + (window_w - 15);&lt;br /&gt;
	ret[1] = ret[1] - (window_h/2 - 4); -- - (window_h - 66) + refresh_up_y_offs; -- 50 for flax;&lt;br /&gt;
	lsPrintln(&amp;quot;refreshPosUp(&amp;quot; .. x .. &amp;quot;,&amp;quot; .. y .. &amp;quot;)=&amp;quot; .. ret[0] .. &amp;quot;,&amp;quot; .. ret[1]);&lt;br /&gt;
	return ret;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function refreshPosDown(x, y)&lt;br /&gt;
	local ret = pinnedPos(x, y);&lt;br /&gt;
	ret[0] = ret[0] - 2;&lt;br /&gt;
	ret[1] = ret[1] + (window_h / 2) - refresh_down_y_offs;&lt;br /&gt;
	lsPrintln(&amp;quot;refreshPosDown(&amp;quot; .. x .. &amp;quot;,&amp;quot; .. y .. &amp;quot;)=&amp;quot; .. ret[0] .. &amp;quot;,&amp;quot; .. ret[1]);&lt;br /&gt;
	return ret;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function getCenterPos()&lt;br /&gt;
	local ret = {};&lt;br /&gt;
	ret[0] = xyWindowSize[0] / 2 - walk_x_drift;&lt;br /&gt;
	ret[1] = xyWindowSize[1] / 2 + walk_y_drift;&lt;br /&gt;
	return ret;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function setWaitSpot(x0, y0)&lt;br /&gt;
	setWaitSpot_x = x0;&lt;br /&gt;
	setWaitSpot_y = y0;&lt;br /&gt;
	setWaitSpot_px = srReadPixel(x0, y0);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function waitForChange()&lt;br /&gt;
	local c=0;&lt;br /&gt;
	while srReadPixel(setWaitSpot_x, setWaitSpot_y) == setWaitSpot_px do&lt;br /&gt;
		lsSleep(1);&lt;br /&gt;
		c = c+1;&lt;br /&gt;
		if (lsShiftHeld() and lsControlHeld()) then&lt;br /&gt;
			error 'broke out of loop from Shift+Ctrl';&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	lsPrintln('Waited ' .. c .. 'ms for pixel to change.');&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function drag(x0, y0, x1, y1)&lt;br /&gt;
	srSetMousePos(x0, y0);&lt;br /&gt;
	setWaitSpot(x1, y1);&lt;br /&gt;
	srMouseDown(x0, y0, 0);&lt;br /&gt;
	-- lsSleep(15);&lt;br /&gt;
	srSetMousePos(x1, y1);&lt;br /&gt;
	-- lsSleep(50);&lt;br /&gt;
	waitForChange();&lt;br /&gt;
	srMouseUp(x0, y0, 0);&lt;br /&gt;
	-- lsSleep(50);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function promptFlaxNumbers(is_plant)&lt;br /&gt;
	scale = 1.0;&lt;br /&gt;
	&lt;br /&gt;
	local z = 0;&lt;br /&gt;
	local is_done = nil;&lt;br /&gt;
	local value = nil;&lt;br /&gt;
	-- Edit box and text display&lt;br /&gt;
	while not is_done do&lt;br /&gt;
		-- Put these everywhere to make sure we don't lock up with no easy way to escape!&lt;br /&gt;
		checkBreak(&amp;quot;disallow pause&amp;quot;);&lt;br /&gt;
		&lt;br /&gt;
		lsPrint(10, 10, z, scale, scale, 0xFFFFFFff, &amp;quot;Choose passes and grid size&amp;quot;);&lt;br /&gt;
		&lt;br /&gt;
		-- lsEditBox needs a key to uniquely name this edit box&lt;br /&gt;
		--   let's just use the prompt!&lt;br /&gt;
		-- lsEditBox returns two different things (a state and a value)&lt;br /&gt;
		local y = 40;&lt;br /&gt;
		lsPrint(5, y, z, scale, scale, 0xFFFFFFff, &amp;quot;Passes:&amp;quot;);&lt;br /&gt;
		is_done, num_loops = lsEditBox(&amp;quot;passes&amp;quot;,&lt;br /&gt;
			100, y, z, 50, 30, scale, scale,&lt;br /&gt;
			0x000000ff, 5);&lt;br /&gt;
		if not tonumber(num_loops) then&lt;br /&gt;
			is_done = nil;&lt;br /&gt;
			lsPrint(10, y+18, z+10, 0.7, 0.7, 0xFF2020ff, &amp;quot;MUST BE A NUMBER&amp;quot;);&lt;br /&gt;
			num_loops = 1;&lt;br /&gt;
		end&lt;br /&gt;
		y = y + 32;&lt;br /&gt;
&lt;br /&gt;
		lsPrint(5, y, z, scale, scale, 0xFFFFFFff, &amp;quot;Grid size:&amp;quot;);&lt;br /&gt;
		is_done, grid_w = lsEditBox(&amp;quot;grid&amp;quot;,&lt;br /&gt;
			100, y, z, 50, 30, scale, scale,&lt;br /&gt;
			0x000000ff, grid_w);&lt;br /&gt;
		if not tonumber(grid_w) then&lt;br /&gt;
			is_done = nil;&lt;br /&gt;
			lsPrint(10, y+18, z+10, 0.7, 0.7, 0xFF2020ff, &amp;quot;MUST BE A NUMBER&amp;quot;);&lt;br /&gt;
			grid_w = 1;&lt;br /&gt;
			grid_h = 1;&lt;br /&gt;
		end&lt;br /&gt;
		grid_w = tonumber(grid_w);&lt;br /&gt;
		grid_h = grid_w;&lt;br /&gt;
		y = y + 32;&lt;br /&gt;
&lt;br /&gt;
		if lsButtonText(170, y-32, z, 100, 0xFFFFFFff, &amp;quot;OK&amp;quot;) then&lt;br /&gt;
			is_done = 1;&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if is_plant then&lt;br /&gt;
			lsPrintWrapped(10, y, z+10, lsScreenX - 20, 0.7, 0.7, 0xD0D0D0ff, &amp;quot;This will plant and harvest a &amp;quot; .. grid_w .. &amp;quot;x&amp;quot; .. grid_w .. &amp;quot; grid of Flax &amp;quot; .. num_loops .. &amp;quot; times, requiring &amp;quot; .. (grid_w * grid_w * num_loops) .. &amp;quot; seeds, doing &amp;quot; .. (grid_w*grid_w*num_loops) .. &amp;quot; flax harvests.&amp;quot;);&lt;br /&gt;
		else&lt;br /&gt;
			lsPrintWrapped(10, y, z+10, lsScreenX - 20, 0.7, 0.7, 0xD0D0D0ff, &amp;quot;This will plant a &amp;quot; .. grid_w .. &amp;quot;x&amp;quot; .. grid_w .. &amp;quot; grid of Flax &amp;quot; .. num_loops .. &amp;quot; times, requiring &amp;quot; .. (grid_w * grid_w) .. &amp;quot; seeds, yielding &amp;quot; .. (grid_w * grid_w * num_loops) .. &amp;quot; seeds.&amp;quot;);&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if is_done and (not num_loops or not grid_w) then&lt;br /&gt;
			error 'Canceled';&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		if lsButtonText(lsScreenX - 110, lsScreenY - 30, z, 100, 0xFFFFFFff, &amp;quot;End script&amp;quot;) then&lt;br /&gt;
			error &amp;quot;Clicked End Script button&amp;quot;;&lt;br /&gt;
		end&lt;br /&gt;
	&lt;br /&gt;
		&lt;br /&gt;
		lsDoFrame();&lt;br /&gt;
		lsSleep(10); -- Sleep just so we don't eat up all the CPU for no reason&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kasiya</name></author>
	</entry>
</feed>