The Wiki for Tale 7 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:Silden/Macro/Flax.lua"

From ATITD7
Jump to navigationJump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
* Designed to work on a very big screen (1920 width)
+
I've designed this macro for my own setup, but as a few people asked, I've now posted this here. It's not been designed for "mainstream" so there's some things I should point out.
* Requires cursor movements switched on, F8 F8 mode (zoom in a bit for the bed to show at least an inch in size, but it's not needed to zoom all the way in)
+
 
* 15 beds (5 across, 3 up, from right to left to start with)
+
* It's designed to work on a very big screen (1920 width), as it will put five windows across, three windows down, and the planting area needs to be outside there (because it clicks to open the beds) It may work on smaller screens - see the screenshot below to see what the output during the macro is.
 +
* 15 beds are planted (5 across, 3 up, from right to left to start with)
 
* Change the repeat times value depending on your seed
 
* Change the repeat times value depending on your seed
 
* Works with guilded beds.  
 
* Works with guilded beds.  
  
You will also need to save this image file and put it into the ATITD\images folder: [[File:nothing.png]] (Right click the image, and save it into that part of Automato)
+
You will also need two new images: [[File:nothing.png]] and [[File:Weed.png]]  (Right click the images, "Save Image As" and save them both into into \Automato\games\ATITD\images folder)
 +
 
 +
[[File:Flax Macro in use.jpg]]
 +
 
 +
*Pin the seed menu (I pin it to the left of the clock, but you could pretty much put it anywhere outside the window placement area).
 +
*Requires cursor movements switched on, F8 F8 mode (zoom in a bit for the bed to show at least an inch in size, but it's not needed to zoom all the way in)
 +
*When you run the macro, press shift over the seed you want to plant.
 +
 
 +
The macro will use the cursor keys to plant the beds, and when planting the beds, open and pin the window using right click. It will then tend to the beds by checking for the Weed/Harvest options. Due to timings, it can't do both seeds and normal flax (it will all end up being seeds)
 +
 
 +
 
  
 
  dofile("screen_reader_common.inc");
 
  dofile("screen_reader_common.inc");
Line 88: Line 99:
 
                                         if foundWeed then
 
                                         if foundWeed then
 
                                                 windowstate=2;
 
                                                 windowstate=2;
                                                 srClickMouse(foundWeed[0]+10,foundWeed[1]+5);
+
                                                 srClickMouse(foundWeed[0]+10,foundWeed[1]+5);  
 
                                                 sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nWeeding\n" .. EndMessage);
 
                                                 sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nWeeding\n" .. EndMessage);
 
                                         end
 
                                         end
Line 173: Line 184:
 
         srSetMousePos(x0, y0);
 
         srSetMousePos(x0, y0);
 
  end
 
  end
 +
 +
 +
[[Category:Macro]]

Latest revision as of 23:11, 29 September 2015

I've designed this macro for my own setup, but as a few people asked, I've now posted this here. It's not been designed for "mainstream" so there's some things I should point out.

  • It's designed to work on a very big screen (1920 width), as it will put five windows across, three windows down, and the planting area needs to be outside there (because it clicks to open the beds) It may work on smaller screens - see the screenshot below to see what the output during the macro is.
  • 15 beds are planted (5 across, 3 up, from right to left to start with)
  • Change the repeat times value depending on your seed
  • Works with guilded beds.

You will also need two new images: Nothing.png and Weed.png (Right click the images, "Save Image As" and save them both into into \Automato\games\ATITD\images folder)

Flax Macro in use.jpg

  • Pin the seed menu (I pin it to the left of the clock, but you could pretty much put it anywhere outside the window placement area).
  • Requires cursor movements switched on, F8 F8 mode (zoom in a bit for the bed to show at least an inch in size, but it's not needed to zoom all the way in)
  • When you run the macro, press shift over the seed you want to plant.

The macro will use the cursor keys to plant the beds, and when planting the beds, open and pin the window using right click. It will then tend to the beds by checking for the Weed/Harvest options. Due to timings, it can't do both seeds and normal flax (it will all end up being seeds)


dofile("screen_reader_common.inc");
dofile("ui_utils.inc");
dofile("common.inc");
dofile("serialize.inc");
dofile("settings.inc");
dofile("constants.inc");

local GridAcross = 5;
local DelayBeforePlanting = 100;
local DelayMoving = 300;
local DelayAfterPlanting = 500;
local WindowAcross = 200; --How far across for each window
local WindowDown = 125; --How far down for each window
local MousePos
xyCenter = {};
local EndMessage = " \n\nTo stop the macro, press Ctrl + Shift. To pause the macro, press Alt + Shift.";

askText = singleLine([[
 Pin open the window with the desired seed, hover the mouse over the button, then press Shift to start the Macro.
]]);


function doit()
 -- mousePos is location of Seed Plant, obtained when you start the macro
 mousePos = askForWindow(askText);
 initGlobals();
 MainPlanter();
 
 local RepeatTimes = 6 
 -- Sinai Sage(w), Sunset Pond(w), Old Egypt, Nile Green(w) = 2
 -- Old Dog(w2), Symphony Ridge = 3
 -- Constitution Peak(w) = 4
 -- Jacob's Field = 6
 
 for i = 1, (RepeatTimes+1) do
    BedWatch2();
 end
end  
 
function initGlobals()
  srReadScreen();
  xyWindowSize = srGetWindowSize();
 
  xyCenter[0] = xyWindowSize[0] / 2 - 14;
  xyCenter[1] = xyWindowSize[1] / 2 + 18;
 end
 
 function BedWatch2()
   local WindowCount = clickAllImages("ThisIs.png");
   local WeedProgress = "Found " .. WindowCount .. " Flax Beds to tender. \n\n ";
   
       local intDown = 0;
       for intDown= 1, 3 do
               local intAcross = 0;
               for intAcross=1, GridAcross do
                       local windowstate=0;
                       while windowstate < 2 do
                               srReadScreen();
                               
                               local AcrossStart = (intAcross - 1) * WindowAcross;
                               local AcrossEnd = (intAcross * WindowAcross)- 50;
                               local DownStart = (intDown * WindowDown) - 75;
                               local DownEnd = (intDown * WindowDown) + 50;
                               
                               foundwindow = srFindImageInRange("ThisIs.png",AcrossStart,DownStart,AcrossEnd,DownEnd)
                               if foundwindow then
                                       --found window, now find state:
                                       srClickMouse(foundwindow[0],foundwindow[1]);
                                       sleepWithStatus(250, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nWait Window\n" .. EndMessage);
                                       srReadScreen();
                                       
                                       foundWait = srFindImageInRange("Nothing.png",AcrossStart,DownStart,AcrossEnd,DownEnd)
                                       foundWeed = srFindImageInRange("Weed.png",AcrossStart,DownStart,AcrossEnd,DownEnd)
                                       foundSeeds = srFindImageInRange("HarvestSeeds.png",AcrossStart,DownStart,AcrossEnd,DownEnd)
                                       foundHarvest = srFindImageInRange("HarvestThisFlax.png",AcrossStart,DownStart,AcrossEnd,DownEnd)
                                       if foundWait then
                                               windowstate=1;
                                               sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nWait Window\n" .. EndMessage);
                                       end
                                       if foundWeed then
                                               windowstate=2;
                                               srClickMouse(foundWeed[0]+10,foundWeed[1]+5); 
                                               sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nWeeding\n" .. EndMessage);
                                       end
                                       if foundSeeds then
                                               windowstate=2;
                                               srClickMouse(foundSeeds[0]+10,foundSeeds[1]+5);
                                               sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nDeseeding\n" .. EndMessage);
                                       end
                                       if foundHarvest then
                                               windowstate=2;
                                               srClickMouse(foundHarvest[0]+10,foundHarvest[1]+5);  --Harvest
                                               sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nHarvesting\n" .. EndMessage);
                                               srClickMouse(foundwindow[0],foundwindow[1],1); --Right click to Close window
                                               sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nHarvesting\n" .. EndMessage);
                                       end
                               else
                                       error("Could not find window (" .. intAcross .. ", " .. intDown .. ") therefore aborting program.");
                               end
                       end
               end
       
           local WindowCount = clickAllImages("ThisIs.png");

       end
end

function MainPlanter()
       for i=1, (GridAcross - 1) do
               PlantSeed(i,1);
               Move(VK_LEFT);
       end

       PlantSeed(GridAcross,1);
       Move(VK_UP);

       for i=1, (GridAcross - 1) do
               PlantSeed(i,2);
               Move(VK_RIGHT);
       end

       PlantSeed(GridAcross,2);
       Move(VK_UP);

       for i=1, (GridAcross - 1) do
               PlantSeed(i,3);
               Move(VK_LEFT);
       end

       PlantSeed(GridAcross,3); 
end

function PlantSeed(intAcross, intDown)
 safeClick(mousePos[0], mousePos[1]);
 PinAt((intAcross-1)*WindowAcross,intDown*WindowDown);
end

function Move(MoveDirection)
 sleepWithStatus(DelayBeforePlanting, "Moving." .. EndMessage);
 srKeyDown(MoveDirection);
 sleepWithStatus(DelayMoving, "Moving." .. EndMessage);
 srKeyUp(VK_ALL);
 sleepWithStatus(DelayAfterPlanting, "Moving." .. EndMessage);
end

function PinAt(incX,incY)
 local deviationAcross = 60
 local deviationDown = -60
 
 srClickMouse(xyCenter[0]+deviationAcross, xyCenter[1]-deviationDown,0);
 sleepWithStatus(50, "Pinning Window." .. EndMessage);
 srClickMouse(xyCenter[0]+deviationAcross+5, xyCenter[1]-deviationDown-5,1);
 sleepWithStatus(50, "Pinning Window." .. EndMessage);
 dragWaitSource(xyCenter[0]+deviationAcross, xyCenter[1]-deviationDown,incX,incY)
 sleepWithStatus(50, "Pinning Window." .. EndMessage);
end

function dragWaitSource(x0, y0, x1, y1)
       srMouseDown(x0, y0, 0);
       sleepWithStatus(50, "Dragging Window." .. EndMessage);
       srSetMousePos(x1, y1);
       sleepWithStatus(50, "Dragging Window." .. EndMessage);
       srMouseUp(x1, y1, 0);
       sleepWithStatus(50, "Dragging Window." .. EndMessage);
       srSetMousePos(x0, y0);
end