The Wiki for Tale 6 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:Cegaiel/VeggieTales/Onion"
| Line 1: | Line 1: | ||
| − | + | <B>Credits:</b> Note this script is KasumiGhia's Tale 5 onions.lua update, but with a minor adjustment. It will refresh the plant window, after harvesting. This is in case you used all your seeds during planting which makes the plant window to be blank (as there are no more seeds in inventory after you planted your last seed). By refreshing, it will not cause an error (Plant window not found) on 2nd and subsequent passes. | |
| + | |||
| − | |||
| + | Copy/Paste/Overwrite the below into the <b>onions.lua</b> file (using Notepad) in the Veggie Tales /LUASCRIPTS folder. | ||
| − | |||
| Line 11: | Line 11: | ||
<pre> | <pre> | ||
-- Edit these first 2 to adjust how much is planted in a pass | -- Edit these first 2 to adjust how much is planted in a pass | ||
| − | -- Probably not fast enough to do more than | + | -- Probably not fast enough to do more than 4x4 |
| + | -- Just used as the default now. | ||
grid_w = 3; | grid_w = 3; | ||
grid_h = 3; | grid_h = 3; | ||
| Line 40: | Line 41: | ||
search_size = 15; | search_size = 15; | ||
| − | search_dx = {0, -search_size, search_size, -search_size, search_size, -search_size, search_size, 0, 0}; | + | search_size2 = 10; |
| − | search_dy = {0, -search_size, search_size, search_size, -search_size, 0, 0, -search_size, search_size}; | + | search_dx = {0, -search_size, search_size, -search_size, search_size, -search_size, search_size, 0, 0, -search_size2, search_size2, -search_size2, search_size2, -search_size2, search_size2, 0, 0}; |
| + | search_dy = {0, -search_size, search_size, search_size, -search_size, 0, 0, -search_size, search_size, -search_size2, search_size2, search_size2, -search_size2, 0, 0, -search_size2, search_size2}; | ||
| + | |||
function fillWater(required) | function fillWater(required) | ||
| + | if water_needed then | ||
if (aqueduct_mode) then | if (aqueduct_mode) then | ||
aque = srFindImage("Aqueduct.png", 5000); | aque = srFindImage("Aqueduct.png", 5000); | ||
| Line 60: | Line 64: | ||
end | end | ||
else | else | ||
| − | srClickMouseNoMove(xyFillWater[0], xyFillWater[1]); | + | srReadScreen(); |
| − | + | xyFillWater = srFindImage(imgWaterJugs); | |
| − | + | if not xyFillWater then | |
| − | + | error 'CMoved too far for fill jugs with water icon.'; | |
| + | else | ||
| + | -- Use it | ||
| + | srClickMouseNoMove(xyFillWater[0], xyFillWater[1]); | ||
| + | lsSleep(screen_refresh_time); | ||
| + | srClickMouseNoMove(xyCenter[0] + 10, xyCenter[1] + 20); | ||
| + | lsSleep(fill_water_time); | ||
| + | end; | ||
end | end | ||
| − | + | end; | |
| + | num_waters = 0; | ||
end | end | ||
function doit() | function doit() | ||
num_jugs = promptNumber("How many jugs?", 15); | num_jugs = promptNumber("How many jugs?", 15); | ||
| + | grid_w = promptNumber("How many plants across?", grid_w); | ||
| + | grid_h = promptNumber("How many rows of plants?", grid_h); | ||
num_loops = promptNumber("How many " .. grid_w .. "x" .. grid_h .. " passes?", 5); | num_loops = promptNumber("How many " .. grid_w .. "x" .. grid_h .. " passes?", 5); | ||
| − | askForWindow("Make sure the plant Onions window is pinned and you are in F8F8 cam zoomed in. Will plant SE of this | + | askForWindow("Make sure the plant Onions window is pinned and you are in F8F8 cam zoomed in. Will plant SE of this location. 'Plant all crops where you stand' must be ON."); |
| − | |||
| − | location. 'Plant all crops where you stand' must be ON."); | ||
initGlobals(); | initGlobals(); | ||
num_waters = 0; | num_waters = 0; | ||
| + | water_needed = 1; | ||
| + | if num_jugs > (grid_w*grid_h*4*num_loops) then | ||
| + | water_needed = false; | ||
| + | end; | ||
srReadScreen(); | srReadScreen(); | ||
xyCenter = getCenterPos(); | xyCenter = getCenterPos(); | ||
| − | |||
| − | |||
| − | |||
| − | |||
-- Find plant onions window | -- Find plant onions window | ||
local xyPlantOnions = srFindImage(imgOnionSeeds); | local xyPlantOnions = srFindImage(imgOnionSeeds); | ||
if not xyPlantOnions then | if not xyPlantOnions then | ||
error 'Could not find plant window'; | error 'Could not find plant window'; | ||
| − | |||
end | end | ||
| − | |||
| − | |||
| − | |||
xyPlantOnions[0] = xyPlantOnions[0] + 5; | xyPlantOnions[0] = xyPlantOnions[0] + 5; | ||
| − | |||
| − | |||
| − | |||
-- Find aqudeuct or fill water button, use it | -- Find aqudeuct or fill water button, use it | ||
aque = srFindImage("Aqueduct.png", 5000); | aque = srFindImage("Aqueduct.png", 5000); | ||
if not aque then | if not aque then | ||
| + | if water_needed then | ||
aqueduct_mode = nil; | aqueduct_mode = nil; | ||
xyFillWater = srFindImage(imgWaterJugs); | xyFillWater = srFindImage(imgWaterJugs); | ||
| Line 111: | Line 117: | ||
fillWater(nil); | fillWater(nil); | ||
end; | end; | ||
| + | end; | ||
else | else | ||
aqueduct_mode = 1; | aqueduct_mode = 1; | ||
| Line 116: | Line 123: | ||
end | end | ||
| − | |||
| − | |||
for loop_count=1, num_loops do | for loop_count=1, num_loops do | ||
| Line 128: | Line 133: | ||
-- Plant | -- Plant | ||
| − | |||
srClickMouseNoMove(xyPlantOnions[0], xyPlantOnions[1], 0); | srClickMouseNoMove(xyPlantOnions[0], xyPlantOnions[1], 0); | ||
-- lsSleep(delay_time); | -- lsSleep(delay_time); | ||
| Line 144: | Line 148: | ||
end | end | ||
end | end | ||
| − | + | lsPrintln("Moving cntr:" .. xyCenter[0] .. " " .. xyCenter[1] .. " d=" .. walk_dx .. " " .. walk_dy); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | lsPrintln("Moving cntr:" .. xyCenter[0] .. " " .. xyCenter[1] .. " d=" .. walk_dx .. " " .. | ||
| − | |||
| − | walk_dy); | ||
srClickMouseNoMove(xyCenter[0] + walk_dx, xyCenter[1] + walk_dy); | srClickMouseNoMove(xyCenter[0] + walk_dx, xyCenter[1] + walk_dy); | ||
lsSleep(walk_time); | lsSleep(walk_time); | ||
| Line 167: | Line 164: | ||
checkBreak(); | checkBreak(); | ||
srReadScreen(); | srReadScreen(); | ||
| − | xyImagePos = srFindImageInRange(imgOnionBed, click_x - walk_px_x*2, click_y - 42 - | + | xyImagePos = srFindImageInRange(imgOnionBed, click_x - walk_px_x*2, click_y - 42 - walk_px_y*2, window_w+walk_px_x*4, window_h+walk_px_y*4); |
| − | |||
| − | walk_px_y*2, window_w+walk_px_x*4, window_h+walk_px_y*4); | ||
if xyImagePos then | if xyImagePos then | ||
-- found it | -- found it | ||
| Line 186: | Line 181: | ||
-- Pin | -- Pin | ||
srClickMouseNoMove(click_x+5, click_y, 1); | srClickMouseNoMove(click_x+5, click_y, 1); | ||
| + | lsSleep(screen_refresh_time); | ||
-- Move window | -- Move window | ||
| Line 209: | Line 205: | ||
end | end | ||
end | end | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
lsSleep(1000); -- Wait for last window to bring to the foreground before clicking again | lsSleep(1000); -- Wait for last window to bring to the foreground before clicking again | ||
| Line 226: | Line 217: | ||
for x=1, grid_w do | for x=1, grid_w do | ||
if do_harvest then | if do_harvest then | ||
| − | statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Harvesting " .. x | + | statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Harvesting " .. x .. ", " .. y); |
| − | |||
| − | .. ", " .. y); | ||
else | else | ||
| − | statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Watering " .. x .. | + | statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Watering " .. x .. ", " .. y .. " water pass " .. water_pass_count); |
| − | |||
| − | ", " .. y .. " water pass " .. water_pass_count); | ||
end | end | ||
local pp = pinnedPos(x, y); | local pp = pinnedPos(x, y); | ||
| Line 241: | Line 228: | ||
srReadScreen(); | srReadScreen(); | ||
if not do_harvest then | if not do_harvest then | ||
| − | local water = srFindImageInRange(imgWaterThese, pp[0], pp[1] - 25, | + | local water = srFindImageInRange(imgWaterThese, pp[0], pp[1] - 25, window_w, window_h); |
| − | |||
| − | window_w, window_h); | ||
if water then | if water then | ||
srClickMouseNoMove(water[0] + 5, water[1], 0); | srClickMouseNoMove(water[0] + 5, water[1], 0); | ||
| Line 254: | Line 239: | ||
end | end | ||
end | end | ||
| − | local harvest = srFindImageInRange(imgHarvestThese, pp[0], pp[1] - 25, | + | local harvest = srFindImageInRange(imgHarvestThese, pp[0], pp[1] - 25, window_w, window_h); |
| − | |||
| − | window_w, window_h); | ||
if harvest then | if harvest then | ||
if do_harvest then | if do_harvest then | ||
| Line 270: | Line 253: | ||
lsSleep(10); | lsSleep(10); | ||
checkBreak(); | checkBreak(); | ||
| − | -- try again anyway! error ' Expected Onion window to have either harvest | + | -- try again anyway! error ' Expected Onion window to have either harvest or water!'; |
| − | |||
| − | or water!'; | ||
end | end | ||
end | end | ||
| Line 302: | Line 283: | ||
while pass_growth_time - (lsGetTimer() - start_time) > 0 do | while pass_growth_time - (lsGetTimer() - start_time) > 0 do | ||
time_left = pass_growth_time - (lsGetTimer() - start_time); | time_left = pass_growth_time - (lsGetTimer() - start_time); | ||
| − | statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Waiting " .. time_left .. | + | statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Waiting " .. time_left .. "ms before starting next water pass..."); |
| − | |||
| − | "ms before starting next water pass..."); | ||
lsSleep(100); | lsSleep(100); | ||
checkBreak(); | checkBreak(); | ||
| Line 313: | Line 292: | ||
| − | --Click the plant window, to refresh seeds, in case you used your last seed. Prevents fails (can't find onion seed) | + | --Click the plant window, to refresh seeds, in case you used your last seed. Prevents fails (can't find onion seed) on 2nd or higher passes. |
| − | |||
| − | on 2nd or higher passes. | ||
xyPlantOnions[1] = xyPlantOnions[1] + 15; | xyPlantOnions[1] = xyPlantOnions[1] + 15; | ||
srClickMouseNoMove(xyPlantOnions[0], xyPlantOnions[1], 0); | srClickMouseNoMove(xyPlantOnions[0], xyPlantOnions[1], 0); | ||
| Line 321: | Line 298: | ||
| − | lsSleep( | + | |
| − | + | lsSleep(2000); -- wait for harvested plants to disappear | |
| + | |||
-- Move back a bit | -- Move back a bit | ||
| − | if grid_h | + | if grid_h == 1 then |
| − | srClickMouseNoMove(xyCenter[0] - walk_px_x* | + | srClickMouseNoMove(xyCenter[0] - math.floor(walk_px_x*(grid_w - 1.5)), xyCenter[1]); |
| + | elseif grid_w == 1 then | ||
| + | srClickMouseNoMove(xyCenter[0], xyCenter[1] - math.floor(walk_px_y*(grid_h - 1.5))); | ||
else | else | ||
| − | srClickMouseNoMove(xyCenter[0] | + | if grid_h % 2 == 1 then |
| + | -- odd number of rows, ends up near bottom right, so move left and up | ||
| + | srClickMouseNoMove(xyCenter[0] - math.floor(walk_px_x*(grid_w - 1.5)), xyCenter[1] - math.floor(walk_px_y*(grid_h - 1.5))); | ||
| + | else | ||
| + | -- even number of rows, ends up near bottom left, so move mostly up | ||
| + | srClickMouseNoMove(xyCenter[0] - math.floor(walk_px_x*1) , xyCenter[1] - math.floor(walk_px_y*(grid_h - 1.5))); | ||
| + | end | ||
end | end | ||
| − | lsSleep( | + | lsSleep(2000); -- wait to move back |
| + | |||
| + | |||
| + | |||
end | end | ||
lsPlaySound("Complete.wav"); | lsPlaySound("Complete.wav"); | ||
end | end | ||
| + | |||
</pre> | </pre> | ||
Revision as of 03:47, 14 December 2011
Credits: Note this script is KasumiGhia's Tale 5 onions.lua update, but with a minor adjustment. It will refresh the plant window, after harvesting. This is in case you used all your seeds during planting which makes the plant window to be blank (as there are no more seeds in inventory after you planted your last seed). By refreshing, it will not cause an error (Plant window not found) on 2nd and subsequent passes.
Copy/Paste/Overwrite the below into the onions.lua file (using Notepad) in the Veggie Tales /LUASCRIPTS folder.
Onions.lua:
-- Edit these first 2 to adjust how much is planted in a pass
-- Probably not fast enough to do more than 4x4
-- Just used as the default now.
grid_w = 3;
grid_h = 3;
imgOnionBed = "ThisIsAnOnionBed.png";
imgOnionSeeds = "OnionSeeds.png";
imgWaterThese = "WaterThese.png";
imgHarvestThese = "HarvestThese.png";
imgWaterJugs = "IconWaterJugs.png";
loadfile("luaScripts/flax_common.inc")();
loadfile("luaScripts/screen_reader_common.inc")();
loadfile("luaScripts/ui_utils.inc")();
walk_px_x = 112;
walk_px_y = 112;
walk_time = 250;
screen_refresh_time = 300;
water_time = 1200;
harvest_time = 1100;
fill_water_time = 4000;
pass_growth_time = 24000;
-- the onion window
window_w = 191;
window_h = 84;
refresh_down_y_offs = 0;
search_size = 15;
search_size2 = 10;
search_dx = {0, -search_size, search_size, -search_size, search_size, -search_size, search_size, 0, 0, -search_size2, search_size2, -search_size2, search_size2, -search_size2, search_size2, 0, 0};
search_dy = {0, -search_size, search_size, search_size, -search_size, 0, 0, -search_size, search_size, -search_size2, search_size2, search_size2, -search_size2, 0, 0, -search_size2, search_size2};
function fillWater(required)
if water_needed then
if (aqueduct_mode) then
aque = srFindImage("Aqueduct.png", 5000);
if not aque then
error 'Could not find aqueduct window.';
end
srClickMouseNoMove(aque[0], aque[1]);
lsSleep(150);
srReadScreen();
fill = srFindImage("FillWithWater.png", 5000);
if ((not fill) and required) then
error 'Could not find Fill With Wather';
end
if fill then
srClickMouseNoMove(fill[0]+5, fill[1]);
end
else
srReadScreen();
xyFillWater = srFindImage(imgWaterJugs);
if not xyFillWater then
error 'CMoved too far for fill jugs with water icon.';
else
-- Use it
srClickMouseNoMove(xyFillWater[0], xyFillWater[1]);
lsSleep(screen_refresh_time);
srClickMouseNoMove(xyCenter[0] + 10, xyCenter[1] + 20);
lsSleep(fill_water_time);
end;
end
end;
num_waters = 0;
end
function doit()
num_jugs = promptNumber("How many jugs?", 15);
grid_w = promptNumber("How many plants across?", grid_w);
grid_h = promptNumber("How many rows of plants?", grid_h);
num_loops = promptNumber("How many " .. grid_w .. "x" .. grid_h .. " passes?", 5);
askForWindow("Make sure the plant Onions window is pinned and you are in F8F8 cam zoomed in. Will plant SE of this location. 'Plant all crops where you stand' must be ON.");
initGlobals();
num_waters = 0;
water_needed = 1;
if num_jugs > (grid_w*grid_h*4*num_loops) then
water_needed = false;
end;
srReadScreen();
xyCenter = getCenterPos();
-- Find plant onions window
local xyPlantOnions = srFindImage(imgOnionSeeds);
if not xyPlantOnions then
error 'Could not find plant window';
end
xyPlantOnions[0] = xyPlantOnions[0] + 5;
-- Find aqudeuct or fill water button, use it
aque = srFindImage("Aqueduct.png", 5000);
if not aque then
if water_needed then
aqueduct_mode = nil;
xyFillWater = srFindImage(imgWaterJugs);
if not xyFillWater then
error 'Could not find Aqueduct window OR fill jugs with water icon, you may need to empty 1 jug.';
else
-- Use it
fillWater(nil);
end;
end;
else
aqueduct_mode = 1;
fillWater(nil);
end
for loop_count=1, num_loops do
-- Plant and pin
for y=1, grid_h do
for x=1, grid_w do
lsPrintln('doing ' .. x .. ',' .. y);
statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Planting " .. x .. ", " .. y);
-- Plant
srClickMouseNoMove(xyPlantOnions[0], xyPlantOnions[1], 0);
-- lsSleep(delay_time);
-- Move to new location
if x == grid_w then
walk_dy = walk_px_y;
walk_dx = 0;
else
walk_dy = 0;
if y % 2 == 1 then
walk_dx = walk_px_x;
else
walk_dx = -walk_px_x;
end
end
lsPrintln("Moving cntr:" .. xyCenter[0] .. " " .. xyCenter[1] .. " d=" .. walk_dx .. " " .. walk_dy);
srClickMouseNoMove(xyCenter[0] + walk_dx, xyCenter[1] + walk_dy);
lsSleep(walk_time);
-- Search for menu
xyImagePos = nil;
search_idx = 1;
while not xyImagePos and search_idx <= #search_dx do
click_x = xyCenter[0] - walk_dx + math.floor(search_dx[search_idx] * pixel_scale);
click_y = xyCenter[1] - walk_dy + math.floor(search_dy[search_idx] * pixel_scale);
lsPrintln(' clicking ' .. click_x .. ',' .. click_y);
srClickMouse(click_x, click_y, 1); -- Right click!
lsSleep(screen_refresh_time);
checkBreak();
srReadScreen();
xyImagePos = srFindImageInRange(imgOnionBed, click_x - walk_px_x*2, click_y - 42 - walk_px_y*2, window_w+walk_px_x*4, window_h+walk_px_y*4);
if xyImagePos then
-- found it
click_x = xyImagePos[0] - 6;
click_y = xyImagePos[1] + 25;
else
-- No menu came up, try elsewhere?
search_idx = search_idx+1;
end
end
if not xyImagePos then
error ' Failed to bring up onion bed window';
end
-- Pin
srClickMouseNoMove(click_x+5, click_y, 1);
lsSleep(screen_refresh_time);
-- Move window
local pp = pinnedPos(x, y);
drag(click_x, click_y,
pp[0], pp[1], 0);
-- lsSleep(delay_time);
checkBreak();
end
end
srSetMousePos(200, 200);
statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Refocusing windows...");
-- Bring windows to front
for y=grid_h, 1, -1 do
for x=grid_w, 1, -1 do
local rp = refreshPosUp(x, y);
srClickMouseNoMove(rp[0], rp[1], 0);
lsSleep(refocus_click_time);
end
end
lsSleep(1000); -- Wait for last window to bring to the foreground before clicking again
-- Water everything and then harvestable
do_harvest = nil;
water_pass_count=0;
passes_before_harvest = 4;
while 1 do
water_pass_count = water_pass_count+1;
start_time = lsGetTimer();
for y=1, grid_h do
for x=1, grid_w do
if do_harvest then
statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Harvesting " .. x .. ", " .. y);
else
statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Watering " .. x .. ", " .. y .. " water pass " .. water_pass_count);
end
local pp = pinnedPos(x, y);
local rp = refreshPosDown(x, y);
while 1 do
srClickMouseNoMove(rp[0], rp[1], 0);
lsSleep(screen_refresh_time);
srReadScreen();
if not do_harvest then
local water = srFindImageInRange(imgWaterThese, pp[0], pp[1] - 25, window_w, window_h);
if water then
srClickMouseNoMove(water[0] + 5, water[1], 0);
lsSleep(water_time);
num_waters = num_waters + 1;
if num_waters >= num_jugs-1 then
fillWater(1);
end
break;
end
end
local harvest = srFindImageInRange(imgHarvestThese, pp[0], pp[1] - 25, window_w, window_h);
if harvest then
if do_harvest then
-- do the harvest
srClickMouseNoMove(harvest[0] + 5, harvest[1], 0);
-- dismiss window
srClickMouseNoMove(rp[0], rp[1], 1);
lsSleep(harvest_time);
end
-- lsPrintln('Ready for harvest, come back later!');
break;
end
lsSleep(10);
checkBreak();
-- try again anyway! error ' Expected Onion window to have either harvest or water!';
end
end
end
if do_harvest then
break;
end
-- Bring windows to front
for y=grid_h, 1, -1 do
for x=grid_w, 1, -1 do
local rp = refreshPosUp(x, y);
srClickMouseNoMove(rp[0], rp[1], 0);
lsSleep(refocus_click_time);
end
end
lsSleep(1000); -- Wait for last window to bring to the foreground before clicking again
if water_pass_count == passes_before_harvest then
do_harvest = 1;
else
-- Otherwise, wait until 24 seconds has elapsed, and water again
local time_left = pass_growth_time - (lsGetTimer() - start_time);
statusScreen("Waiting " .. time_left .. "ms before starting next pass...");
if (time_left > fill_water_time) and (num_waters > 0) then
fillWater(1);
end
while pass_growth_time - (lsGetTimer() - start_time) > 0 do
time_left = pass_growth_time - (lsGetTimer() - start_time);
statusScreen("(" .. loop_count .. "/" .. num_loops .. ") Waiting " .. time_left .. "ms before starting next water pass...");
lsSleep(100);
checkBreak();
end
end
end
--Click the plant window, to refresh seeds, in case you used your last seed. Prevents fails (can't find onion seed) on 2nd or higher passes.
xyPlantOnions[1] = xyPlantOnions[1] + 15;
srClickMouseNoMove(xyPlantOnions[0], xyPlantOnions[1], 0);
xyPlantOnions[1] = xyPlantOnions[1] - 15;
lsSleep(2000); -- wait for harvested plants to disappear
-- Move back a bit
if grid_h == 1 then
srClickMouseNoMove(xyCenter[0] - math.floor(walk_px_x*(grid_w - 1.5)), xyCenter[1]);
elseif grid_w == 1 then
srClickMouseNoMove(xyCenter[0], xyCenter[1] - math.floor(walk_px_y*(grid_h - 1.5)));
else
if grid_h % 2 == 1 then
-- odd number of rows, ends up near bottom right, so move left and up
srClickMouseNoMove(xyCenter[0] - math.floor(walk_px_x*(grid_w - 1.5)), xyCenter[1] - math.floor(walk_px_y*(grid_h - 1.5)));
else
-- even number of rows, ends up near bottom left, so move mostly up
srClickMouseNoMove(xyCenter[0] - math.floor(walk_px_x*1) , xyCenter[1] - math.floor(walk_px_y*(grid_h - 1.5)));
end
end
lsSleep(2000); -- wait to move back
end
lsPlaySound("Complete.wav");
end