The Wiki for Tale 5 is in read-only mode and is available for archival and reference purposes only. Please visit the current Tale 11 Wiki in the meantime.

If you have any issues with this Wiki, please post in #wiki-editing on Discord or contact Brad in-game.

Difference between revisions of "User:Tribisha/Script Temp"

From ATITD5
Jump to navigationJump to search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
<code>
 +
-- This script has not yet been updated to use the new UI utilties
 +
-- See flax.lua instead
  
-- Edit these first 2 to adjust how much is planted in a pass
+
-- Edit these first 3 to adjust how much is planted in a pass and how many passes
-- May need to adjust walk_time in flax_common.inc if you move too slowly to keep up
+
-- May need to adjust walk_time in flax_common.inc if you move too slowly to keep up
-- grids tested: 2x2, 3x3, 5x5, 6x6 (probably need 3+ dex and 600ms walk time)
+
-- grids tested up to 7x7, can probably do more
grid_w = 5;
+
grid_w = 5;
grid_h = 5;
+
grid_h = 5;
  
loadfile("luaScripts/flax_common.inc")();
+
harvest_seeds_time = 1300;
loadfile("luaScripts/screen_reader_common.inc")();
+
rip_out_time = 150;
loadfile("luaScripts/ui_utils.inc")();
+
rip_out_when_done = 1;
  
-- Just testing spiral algorithm, ignore this...
+
loadfile("luaScripts/flax_common.inc")();
function spiraltest()
+
loadfile("luaScripts/screen_reader_common.inc")();
-- for spiral
+
loadfile("luaScripts/ui_utils.inc")();
local dxi=1;
 
local dt_max=grid_w;
 
local dt=grid_w;
 
local dx={1, 0, -1, 0};
 
local dy={0, -1, 0, 1};
 
local num_at_this_length = 3;
 
 
-- Plant and pin
 
for y=1, grid_h do
 
for x=1, grid_w do
 
lsPrintln('doing ' .. x .. ',' .. y);
 
 
 
-- move to next position
 
if not ((x == grid_w) and (y == grid_h)) then
 
lsPrintln('walking dx=' .. dx[dxi] .. ' dy=' .. dy[dxi]);
 
dt = dt - 1;
 
if dt == 1 then
 
dxi = dxi + 1;
 
num_at_this_length = num_at_this_length - 1;
 
if num_at_this_length == 0 then
 
dt_max = dt_max - 1;
 
num_at_this_length = 2;
 
end
 
if dxi == 5 then
 
dxi = 1;
 
end
 
dt = dt_max;
 
end
 
else
 
lsPrintln('skipping walking, on last leg');
 
end
 
end
 
end
 
end
 
  
 +
-- Harvest seeds
 
function doit()
 
function doit()
-- num_loops = promptNumber("How many " .. grid_w .. "x" .. grid_h .. " passes ?", 5);
+
--num_loops = promptNumber("How many " .. grid_w .. "x" .. grid_h .. " passes ?", 5);
promptFlaxNumbers(1);
+
promptFlaxNumbers(false);
 
 
 
askForWindow("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.");
 
askForWindow("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.");
 
 
initGlobals();
 
initGlobals();
 
local went_to_seeds = 0; -- Don't loop if we lost one, it'll mess us up!
 
 
srReadScreen();
 
srReadScreen();
 
local xyPlantFlax = srFindImage("Flaxkrae12.png");
 
local xyPlantFlax = srFindImage("Flaxkrae12.png");
Line 71: Line 37:
 
xyFlaxMenu[1] = xyCenter[1] + 0;
 
xyFlaxMenu[1] = xyCenter[1] + 0;
 
 
for loop_count=1, num_loops do
+
for outer_loop=1, num_loops do
+
 
-- for spiral
 
-- for spiral
 
local dxi=1;
 
local dxi=1;
Line 86: Line 52:
 
for y=1, grid_h do
 
for y=1, grid_h do
 
for x=1, grid_w do
 
for x=1, grid_w do
lsPrintln('doing ' .. x .. ',' .. y .. ' of ' .. grid_w .. ',' .. grid_h);
+
lsPrintln('doing ' .. x .. ',' .. y);
+
statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Planting " .. x .. ", " .. y);
+
statusScreen("Planting...");
+
 
 
-- Plant
 
-- Plant
 
lsPrintln('planting ' .. xyPlantFlax[0] .. ',' .. xyPlantFlax[1]);
 
lsPrintln('planting ' .. xyPlantFlax[0] .. ',' .. xyPlantFlax[1]);
Line 104: Line 70:
 
waitForChange();
 
waitForChange();
 
-- lsSleep(delay_time);
 
-- lsSleep(delay_time);
 
-- Check for window size
 
checkWindowSize(xyFlaxMenu[0], xyFlaxMenu[1]);
 
 
 
 
-- Pin
 
-- Pin
Line 112: Line 75:
 
srClickMouseNoMove(xyFlaxMenu[0]+5, xyFlaxMenu[1]+0, 1);
 
srClickMouseNoMove(xyFlaxMenu[0]+5, xyFlaxMenu[1]+0, 1);
 
-- lsSleep(delay_time);
 
-- lsSleep(delay_time);
 +
 +
-- Check for window size
 +
checkWindowSize(xyFlaxMenu[0], xyFlaxMenu[1]);
 
 
 
-- Move window
 
-- Move window
Line 144: Line 110:
 
end
 
end
 
end
 
end
checkBreak();
+
if (lsShiftHeld() and lsControlHeld()) then
 +
error 'broke out of loop from Shift+Ctrl';
 +
end
 
end
 
end
 +
 +
for loop_count=1, seeds_per_pass do
 +
 +
loop_label = "(" .. outer_loop .. "/" .. num_loops .. ", " .. loop_count .. "/" .. seeds_per_pass .. ")";
 +
statusScreen(loop_label .. " Refocusing");
  
statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Refocusing windows...");
+
refocusWindows()
 +
 +
lsSleep(refocus_time); -- Wait for last window to bring to the foreground before continuing
 
 
refocusWindows();
+
-- And harvest
 
local did_harvest=false;
 
local water_step = 0;
 
while not did_harvest do
 
-- Monitor for Weed This/etc
 
water_step = water_step + 1;
 
 
for y=1, grid_h do
 
for y=1, grid_h do
 
for x=1, grid_w do  
 
for x=1, grid_w do  
statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Weeding/Harvest step " .. water_step);
+
 
 
local pp = pinnedPos(x, y);
 
local pp = pinnedPos(x, y);
 
local rp = refreshPosDown(x, y);
 
local rp = refreshPosDown(x, y);
local seeds_retry=3;
 
 
while 1 do
 
while 1 do
 +
statusScreen(loop_label .. " Harvesting " .. x .. ", " .. y);
 
srClickMouseNoMove(rp[0], rp[1], 0);
 
srClickMouseNoMove(rp[0], rp[1], 0);
 
lsSleep(screen_refresh_time);
 
lsSleep(screen_refresh_time);
 
srReadScreen();
 
srReadScreen();
local weed = srFindImageInRange(imgWeed, pp[0], pp[1] - 50, 120, 100);
+
local seeds = srFindImageInRange(imgSeeds, pp[0], pp[1] - 50, 160, 100);
if weed then
+
if seeds then
srClickMouseNoMove(weed[0] + 5, weed[1], 0);
+
srClickMouseNoMove(seeds[0] + 5, seeds[1], 0);
 +
lsSleep(harvest_seeds_time);
 
break;
 
break;
 
end
 
end
local weed = srFindImageInRange(imgWeedAndWater, pp[0], pp[1] - 50, 120, 100);
+
checkBreak();
if weed then
+
end
srClickMouseNoMove(weed[0] + 5, weed[1], 0);
+
end
break;
+
end
end
+
end
local harvest = srFindImageInRange(imgHarvest, pp[0], pp[1] - 50, 110, 100);
+
 
if harvest then
+
statusScreen("Refocusing");
srClickMouseNoMove(harvest[0] + 5, harvest[1], 0);
+
-- Bring windows to front
srClickMouseNoMove(pp[0], pp[1], 1); -- unpin
+
refocusWindows()
did_harvest = true;
+
lsSleep(refocus_time); -- Wait for last window to bring to the foreground before continuing
break;
+
end
+
-- and clean up!
local seeds = srFindImageInRange(imgSeeds, pp[0], pp[1] - 50, 120, 100);
+
for y=1, grid_h do
if seeds then
+
for x=1, grid_w do
seeds_retry = seeds_retry - 1;
+
local rp = refreshPosDown(x, y);
if (seeds_retry == 0) then
+
if (rip_out_when_done) then
if nil then -- Don't do this, it causes us to walk out of range of the rest!
+
local pp = pinnedPos(x, y);
lsPrintln('Went to seed, grabbing the seeds and ignoring.');
+
local rp = refreshPosDown(x, y);
srClickMouseNoMove(seeds[0] + 5, seeds[1], 0);
+
while 1 do
end
+
statusScreen(loop_label .. " Ripping out " .. x .. ", " .. y);
srSetMousePos(pp[0]+5, pp[1]+37);
+
-- srClickMouseNoMove(rp[0], rp[1], 0);
lsSleep(100);
+
lsSleep(screen_refresh_time);
srClickMouseNoMove(pp[0]+5, pp[1]+37, 0); -- Utility
+
srReadScreen();
lsSleep(100);
+
local util_menu = srFindImageInRange("Utility.png", pp[0], pp[1] - 50, 160, 100);
 +
if util_menu then
 +
srClickMouseNoMove(util_menu[0] + 5, util_menu[1], 0);
 +
while 1 do
 +
lsSleep(screen_refresh_time);
 
srReadScreen();
 
srReadScreen();
local rip = srFindImage("FlaxRipOut.png");
+
local rip_out = srFindImage("RipOut.png");
if rip then
+
if rip_out then
srClickMouseNoMove(rip[0] + 5, rip[1] + 2, 0); -- Rip out
+
srClickMouseNoMove(rip_out[0] + 5, rip_out[1], 0);
else
+
lsSleep(refocus_click_time);
error 'Flax went to seed, but failed to find rip out option';
+
srClickMouseNoMove(rp[0], rp[1], 1); -- unpin
 +
lsSleep(rip_out_time);
 +
break;
 
end
 
end
lsSleep(100);
+
checkBreak();
 
srClickMouseNoMove(pp[0]-3, pp[1], 1); -- unpin
 
went_to_seeds = 1;
 
did_harvest = true;
 
break;
 
 
end
 
end
 +
break;
 
end
 
end
 
checkBreak();
 
checkBreak();
 
end
 
end
 +
else
 +
srClickMouseNoMove(rp[0], rp[1], 1); -- unpin
 +
lsSleep(refocus_click_time);
 
end
 
end
end
+
checkBreak();
 
-- Bring windows to front
 
if not did_harvest then
 
statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Refocusing windows...");
 
 
refocusWindows();
 
 
end
 
end
 
end
 
end
 
 
lsSleep(2500); -- Wait for last flax bed to disappear before accidentally clicking on it!
+
if rip_out_when_done then
statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Walking...");
+
-- wait for beds to disappear
 
+
lsSleep(1500);
if went_to_seeds == 0 then
+
-- Walk back
+
statusScreen(loop_label .. " Walking back");
for x=1, x_pos do
+
-- move back!
srClickMouseNoMove(xyCenter[0] + walk_px_x*-1, xyCenter[1], 0);
+
srClickMouseNoMove(xyCenter[0] + walk_px_x*0, xyCenter[1] + walk_px_y*1, 0);
 +
lsSleep(walk_time);
 +
if (grid_w > 3) then
 +
srClickMouseNoMove(xyCenter[0] + walk_px_x*-1, xyCenter[1] + walk_px_y*0, 0);
 
lsSleep(walk_time);
 
lsSleep(walk_time);
end
+
srClickMouseNoMove(xyCenter[0] + walk_px_x*0, xyCenter[1] + walk_px_y*1, 0);
for x=1, -y_pos do
 
srClickMouseNoMove(xyCenter[0], xyCenter[1] + walk_px_y, 0);
 
 
lsSleep(walk_time);
 
lsSleep(walk_time);
 
end
 
end
end
 
 
if went_to_seeds and not loop_count == num_loops then
 
error 'Some of the plants went to seeds, stopping loop'
 
 
end
 
end
 
end
 
end
+
 
 
lsPlaySound("Complete.wav");
 
lsPlaySound("Complete.wav");
end
+
end
 +
</code>

Latest revision as of 14:27, 27 November 2010

-- This script has not yet been updated to use the new UI utilties -- See flax.lua instead

-- Edit these first 3 to adjust how much is planted in a pass and how many passes -- May need to adjust walk_time in flax_common.inc if you move too slowly to keep up -- grids tested up to 7x7, can probably do more grid_w = 5; grid_h = 5;

harvest_seeds_time = 1300; rip_out_time = 150; rip_out_when_done = 1;

loadfile("luaScripts/flax_common.inc")(); loadfile("luaScripts/screen_reader_common.inc")(); loadfile("luaScripts/ui_utils.inc")();

-- Harvest seeds function doit() --num_loops = promptNumber("How many " .. grid_w .. "x" .. grid_h .. " passes ?", 5); promptFlaxNumbers(false); askForWindow("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."); initGlobals(); srReadScreen(); local xyPlantFlax = srFindImage("Flaxkrae12.png"); if not xyPlantFlax then xyPlantFlax = srFindImage(imgFlax2); if not xyPlantFlax then error 'Could not find plant window'; end end xyPlantFlax[0] = xyPlantFlax[0] + 5; local xyCenter = getCenterPos(); local xyFlaxMenu = {}; xyFlaxMenu[0] = xyCenter[0] - 43*pixel_scale; xyFlaxMenu[1] = xyCenter[1] + 0;

for outer_loop=1, num_loops do

-- for spiral local dxi=1; local dt_max=grid_w; local dt=grid_w; local dx={1, 0, -1, 0}; local dy={0, -1, 0, 1}; local num_at_this_length = 3; local x_pos = 0; local y_pos = 0;

-- Plant and pin for y=1, grid_h do for x=1, grid_w do lsPrintln('doing ' .. x .. ',' .. y);

statusScreen("Planting...");

-- Plant lsPrintln('planting ' .. xyPlantFlax[0] .. ',' .. xyPlantFlax[1]); setWaitSpot(xyFlaxMenu[0], xyFlaxMenu[1]); srClickMouseNoMove(xyPlantFlax[0], xyPlantFlax[1], 0); srSetMousePos(xyFlaxMenu[0], xyFlaxMenu[1]); waitForChange(); -- lsSleep(delay_time);

-- Bring up menu lsPrintln('menu ' .. xyFlaxMenu[0] .. ',' .. xyFlaxMenu[1]); setWaitSpot(xyFlaxMenu[0]+5, xyFlaxMenu[1]); srClickMouse(xyFlaxMenu[0], xyFlaxMenu[1], 0); waitForChange(); -- lsSleep(delay_time);

-- Pin lsPrintln('pin ' .. (xyFlaxMenu[0]+5) .. ',' .. xyFlaxMenu[1]); srClickMouseNoMove(xyFlaxMenu[0]+5, xyFlaxMenu[1]+0, 1); -- lsSleep(delay_time);

-- Check for window size checkWindowSize(xyFlaxMenu[0], xyFlaxMenu[1]);

-- Move window local pp = pinnedPos(x, y); lsPrintln('move ' .. (xyFlaxMenu[0]+5) .. ',' .. xyFlaxMenu[1] .. ' to ' .. pp[0] .. ',' .. pp[1]); drag(xyFlaxMenu[0] + 5, xyFlaxMenu[1], pp[0], pp[1], 0); -- lsSleep(delay_time);

-- move to next position if not ((x == grid_w) and (y == grid_h)) then lsPrintln('walking dx=' .. dx[dxi] .. ' dy=' .. dy[dxi]); x_pos = x_pos + dx[dxi]; y_pos = y_pos + dy[dxi]; srClickMouseNoMove(xyCenter[0] + walk_px_x*dx[dxi], xyCenter[1] + walk_px_y*dy[dxi], 0); lsSleep(walk_time); dt = dt - 1; if dt == 1 then dxi = dxi + 1; num_at_this_length = num_at_this_length - 1; if num_at_this_length == 0 then dt_max = dt_max - 1; num_at_this_length = 2; end if dxi == 5 then dxi = 1; end dt = dt_max; end else lsPrintln('skipping walking, on last leg'); end end if (lsShiftHeld() and lsControlHeld()) then error 'broke out of loop from Shift+Ctrl'; end end

for loop_count=1, seeds_per_pass do

loop_label = "(" .. outer_loop .. "/" .. num_loops .. ", " .. loop_count .. "/" .. seeds_per_pass .. ")"; statusScreen(loop_label .. " Refocusing");

refocusWindows()

lsSleep(refocus_time); -- Wait for last window to bring to the foreground before continuing

-- And harvest for y=1, grid_h do for x=1, grid_w do

local pp = pinnedPos(x, y); local rp = refreshPosDown(x, y); while 1 do statusScreen(loop_label .. " Harvesting " .. x .. ", " .. y); srClickMouseNoMove(rp[0], rp[1], 0); lsSleep(screen_refresh_time); srReadScreen(); local seeds = srFindImageInRange(imgSeeds, pp[0], pp[1] - 50, 160, 100); if seeds then srClickMouseNoMove(seeds[0] + 5, seeds[1], 0); lsSleep(harvest_seeds_time); break; end checkBreak(); end end end end

statusScreen("Refocusing"); -- Bring windows to front refocusWindows() lsSleep(refocus_time); -- Wait for last window to bring to the foreground before continuing

-- and clean up! for y=1, grid_h do for x=1, grid_w do local rp = refreshPosDown(x, y); if (rip_out_when_done) then local pp = pinnedPos(x, y); local rp = refreshPosDown(x, y); while 1 do statusScreen(loop_label .. " Ripping out " .. x .. ", " .. y); -- srClickMouseNoMove(rp[0], rp[1], 0); lsSleep(screen_refresh_time); srReadScreen(); local util_menu = srFindImageInRange("Utility.png", pp[0], pp[1] - 50, 160, 100); if util_menu then srClickMouseNoMove(util_menu[0] + 5, util_menu[1], 0); while 1 do lsSleep(screen_refresh_time); srReadScreen(); local rip_out = srFindImage("RipOut.png"); if rip_out then srClickMouseNoMove(rip_out[0] + 5, rip_out[1], 0); lsSleep(refocus_click_time); srClickMouseNoMove(rp[0], rp[1], 1); -- unpin lsSleep(rip_out_time); break; end checkBreak(); end break; end checkBreak(); end else srClickMouseNoMove(rp[0], rp[1], 1); -- unpin lsSleep(refocus_click_time); end checkBreak(); end end

if rip_out_when_done then -- wait for beds to disappear lsSleep(1500);

statusScreen(loop_label .. " Walking back"); -- move back! srClickMouseNoMove(xyCenter[0] + walk_px_x*0, xyCenter[1] + walk_px_y*1, 0); lsSleep(walk_time); if (grid_w > 3) then srClickMouseNoMove(xyCenter[0] + walk_px_x*-1, xyCenter[1] + walk_px_y*0, 0); lsSleep(walk_time); srClickMouseNoMove(xyCenter[0] + walk_px_x*0, xyCenter[1] + walk_px_y*1, 0); lsSleep(walk_time); end end end

lsPlaySound("Complete.wav"); end