Warning: using macro programs in ATITD is perfectly legal, but only when attended. Unattended macroing is not allowed and is a bannable offense.
ATITD is a game that not only allows macro programs, but encourages it. As someone that was new to the game, and new to macro programs (but not new to programming), I found that the existing macros writen by other players mostly did not work for me. This is sometimes due to differing screen resolution, or screen sizes, etc. In any case I found that creating my own macros was not only more effecient, but was also more fun! I came to realize that there is no reason that everyone playing ATITD shouldn't be able to create simple macros for things like grass, mining, and other tedious parts of the game. Hence the creation of this guide.
This guide is geared towards non-programmers, and even novice computer users. It assumes that you know how to use your task bar to switch between applications, that you know how to edit a file in wordpad and save it, and right click on a running application in the lower right side of your taskbar. This guide uses AutoHotKey because it is free, well documented, and easy to use. I aim to explain macroing from the step by step process of how to actually go about creating simple macros. This guide is probably too basic for a lot of people, but I wanted a wide audience of players; basically anyone who is playing ATITD and not yet using macros because of the difficulty of it all.
You will need to do the following things before you begin:
First things first. You must understand a few basic things about macros. Every macro program has syntax. Syntax refers to the "language" that the AutoHotKey program uses. The first thing to know is that ";" indicates that all of the text after the ";" is a comment. This means AutoHotKey will skip over this line of text. These are meant for you to document your macro. Here is an example:
; My ATITD macros
Go ahead and copy and paste this line into your "clicker.ahk" file. Your macro program now has a single line of code in it, although it doesn't execute anything since this line is a comment. Let's continue to add a few more comments that explain how to use your macro and what it does. Before we actually make something useful though, we need to put some safefalls into the macro in case you need to stop it:
; My ATITD macros ; The following will reload and pause the macros ; ctrl-alt-p for pausing and ctrl-alt-r for reloading ^!p::Pause ^!r::Reload
Let's take a look at what we've done here. We've added a few more comments to remind yourself what the macro does. Next is actual code that does something. The "^" stands for the ctrl key. The "!" stands for the alt key. The "p" and "r" stands for p and r on the keyboard. The "::" says that whatever follows will be executed when the user holds down the "ctrl-alt-p" or "ctrl-alt-r" respectively. "Pause" and "Reload" are special commands. The "Pause" command simply pauses the macro, where as "Reload" will reload the "clicker.ahk" if you've made changes, as well as reset the macro back to the beginning if it has been running. To apply these initial changes, save the document and then right click the green "H" in your taskbar and select "Reload This Script". Throughout the macro writing process, make a habit of leaving the "clicker.ahk" open in Wordpad, ATITD open, and Window Spy open (minimize Window Spy if you need to get rid of the window). You will find that you will constantly be bringing up your Wordpad window, making a change, saving that change, and then reloading your macro. Now that you have a macro for reloading the macro, you don't have to right click on the green "H" any more, but simply press the ctrl-alt-r keys on your keyboard.
You have your comments in place, and you have your Pause and Reload macros created. It is time to actually make a macro! For this we will choose to macro something that when done manually is very tedious and boring... mining! For mining macros, find a mine that has been repaired at least once. You will see why this is important later.
The first thing you must learn to use is a tool that will soon become your best friend in the macroing world, AutoHotKey's Window Spy. While ATITD is running, right click on the green "H" in your taskbar and select "Window Spy". A small window will apear. This window will always be on top of other windows even when it is not selected. The important piece of information that Window Spy tells us is the mouse coordinates that you will use for your macro's mouse clicks. This is under "Mouse Position", "On Screen" (underlined in red). Click on the ATITD screen and move your mouse; you will see the mouse coordinates change as you move the mouse.Computer lag may prevent you from seeing the coordinates change in Window Spy right away after selecting the ATITD window.
Follow these steps to get the needed mouse coordinates:
We now have the mouse coordinates that the macro needs in order to run, but we also need to figure out how much time the macro should wait inbetween clicks. Eat some mining food and go back to your mine. Pin the mine window as before, and get some sort of timing mechanism with seconds such as a watch or the Windows date/time utility. Work your mine and time how long your end timer is down. Record this time along with the mouse coordinates you recorded earlier. You can now go about writing your macro.
Let's say that Window Spy reported the mouse coordinates as being "200, 110". With good food, your time inbetween pulls should be around 3 or 4 seconds. Select the "clicker.ahk" Wordpad window and append to your code:
; My ATITD macros
; The following will reload and pause the macros
; ctrl-alt-p for pausing and ctrl-alt-r for reloading
^!p::Pause
^!r::Reload
; Mining
; alt-shift-m
!+m::
IfWinExist eGenesis Client
{
WinActivate
Loop, 500
{
MouseClick, Left, 200, 110 ; use the mouse coordinates from Window Spy (200 and 110 in this example)
sleep 3000 ; wait 3 seconds
}
}
Let's explain what we've done here. First we've added a few more comments that explain this new macro. We document that we activate this macro
by pressing "alt-shift-m". The "!+m" tells the macro to start when the user presses "alt-shift-m" keys together ("+" means shift obviously). Once again the "::"
tells the macro to execute whatever follows if these keys are pressed on the keyboard. The code "IfWinExist eGenesis Client" tells the macro to execute whatever
follows if the eGenesis client exists (this is just a safefall).
You now see an open bracket, "{". If you look at the end of the code section, you see a matching closing bracket "}". The code inside of the brackets is a block of code. Blocks of code are executed if an If statement or a Loop is created. For example, the "IfWinExist" command says to execute whatever the block of code following it if the statement is true (if the eGenesis window is open). The command "WinActivate" simply makes sure that the ATITD client is in the foreground. The "Loop, 500" command tells the macro to execute the block of code that follows 500 times (remember that a block of code is the lines of code inside of brackets). The loop we created executes two commands 500 times: "MouseClick, Left, 200, 110", and "sleep 3000". The MouseClick command tells the macro to left click at the mouse coordinate 200, 110 (we got these from Window Spy, remember?). The "sleep 3000" command tells the macro to wait for 3 seconds (3000 milliseconds) before looping.
There are two other pieces of information worthy of mentioning. First, you will notice that I placed comments after the "MouseClick" and "sleep" commands. Remember that you can place comments anywhere you like. AutoHotKey will not interpret them, and treat them as if they were not even there..
The second worthy note is the indentation that I used. I personally am very picky about indentation. It makes your code easier to read. Indents are created by pressing the "tab" button as you would in any word processor. They are not necessary, but it is good form to indent blocks of code that are inside brackets. This keeps your code nice and neat.
Save the "clicker.ahk" file and minimize the window. Press the ctrl-alt-r keys to reload the macro after you have saved your changes. Bring your ATITD game window to the foreground, and pin your mining window as before. Press the alt-shift-m keys at the same time and watch your macro go! If at any time you need to break out of it, press the ctrl-alt-r to completely stop the macro or ctrl-alt-p keys to pause the macro.
The first thing that you will notice while running your macro is that it "takes over" your mouse. This is what a macro essentially does; controls your Windows User Interface (keyboard, mouse, etc.). This is why the Reload and Pause macros were necessary. However, you can still access your chat tabs in ATITD and chat while your macro is running. Use F9 and F10 to cycle through your chat tabs. You can also move your mouse while the macro is sleeping.
Earlier, we got our mouse coordinates by using a mine that has been repaired at least once. That is because a mine that has been repaired has an extra line of text in its window, and thus the mine window is a different size than the mining window of a mine that has not been repaired. If you can, find a mine that has not been repaired and try your macro. The mouse misses the mining button! There is an easy fix for this though. Simply drag your pinned mining window down a little bit so that your macro that you created with a repaired mine also works with a mine that has not been repaired. This is a good example of how small differences in the game can make big differences with a macro. As you create your own macros, you will have to think of clever ways to get around problems like this.
That's it! Its easy! If you can understand these simple concepts, then you can macro some of the more tedious and boring aspects of ATITD, such as limestone, fishing, and even flax. You can add to your existing "clicker.ahk" file and add new mcros any time (the keys that activate the macros have to be different or AutoHotKey will complain). I will try to add more macros and explain their structure as time goes on.
This is just an introduction into macroing. If you look at other people's macros on the wiki, you will see a wide variety of complexity in macros. They can do a lot of things, but they can also be used by just about anyone to do simple tasks. Check out some of my other simple macros to get ideas of your own. If you feel this tutorial has helped you understand macros, or if you have any suggestions or comments, please chat me up in game! ~ Daniels
Special thanks goes to Fengol and his macros; some of his code was used here.
Links:
ATITD Macro Wiki Page
AutoHotKey Documentation
Mortomes's Macros (because he is a cool guy)