Sei sulla pagina 1di 13

For Sutherland. OOHRA!

How to Automate Troop and Tool Recruitment


Version 1.0
Hi guys, I really hope at least some of you will be able to use to this. I know that this might be a mildly steep
learning curve for some, but Ill try my best to be as descriptive as possible. fucoidan
This is a tutorial on how to automate troop and tool recruitment on a Windows PC using an android emulator
(Genymotion) with AutoHotkey for the scripts involved. Because I havent been able to mainstream the process,
you will need to do each step manually for your own computer. This will require you to collect your own mouse
movements specific to your screen and also screen capture images from the game to let the scripts search for that
image to perform a set task. As these mouse movements and image searches are sensitive to the size of the screen,
you must ensure that your window is always the same size. You can either not change the window size when you
have launched the virtual machine (VM) or you can maximize it to full screen. As Ive made this script on my
laptop with my max resolution of 1366x768 whereas the VM is 400x800, it will automatically resize the VM to
be smaller than it should be compared to larger monitor, which will open the game at 400x800. I hope that makes
sense!

Things to Download:
-

Genymotion: https://cloud.genymotion.com/page/launchpad/download/ (you will need to register for free


first to download)
o ARM Translation Installer v1.1: http://goo.gl/tfjjMt or for mirrors http://goo.gl/ZLKeKj
o Google Apps for Android 4.1: http://goo.im/gapps/gapps-jb-20121011-signed.zip
AutoHotkey: http://www.autohotkey.com/

Instructions:
Install both Genymotion and Autohotkey to your computer first.
Setting up Genymotion to install Empire Four Kingdoms
1. Once you have installed Genymotion on your computer.
2. In Genymotion click the Add button to Create a new virtual device.
3. Select Android version: 4.1.1, then choose any of the devices and follow with the installation prompts. (I
use Google Nexus S - 4.1.1 - API 16 - 480x800 & Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800, this is
because I find that the smaller the screen, the less power intensive it will be to run on the PC).
4. Once you have your virtual device (virtual machine: VM) open, you need to install the ARM Translation
Installer v1.1 and Google Apps for Andriod 4.1:
a. Instructions were from: http://forum.xda-developers.com/showthread.php?t=2528952
b. Open your Genymotion VM and go to the Homescreen
c. Now Drag&Drop the Genymotion-ARM-Translation.zip onto the Genymotion VM window.
d. It should say "File transfer in progress", once it asks you to flash it click 'OK'
e. Now Reboot your VM using (You can simply close the VM window)
f. Once you're on the Homescreen again Drag&Drop the gapps-jb-20130813-signed.zip(or whatever
version you got) onto your VM, and click 'OK' when asked
g. Once it finishes, again Reboot your VM and open the Google Play Store.
h. Sign in using your Google account
i. Download Goodgame Empire Four Kingdoms.
Now the easy bit is done. Phew. Now to the not so easy, quite difficult bit.
Setting up Autohotkey writing Scripts to do things for you
The Autohotkey package comes with a few different sub programs, the most useful will be AutoScriptWriter
(recorder) to record your mouse movements so you can put it in a script and activate it when you want. The
script I have always starts off with collecting tax, followed by going to my main castle to recruit troops and tools

(which are all different little scripts), then to my next OP and so on until it is done, then it will wait until 10 mins
is up, and continue until I stop the script. Sometimes this doesnt work, i.e. the internet cuts out, and the script
wont know that so it will continue doing its thing, but youre left with the connection failure screen until you log
back in. Im sure there are many other ways to make the script do what you want, what I have here is just how Ive
done it. If youre interested in getting more out of it, I recommend reading the AutoHotkey tutorials so you can
write your own script and make it do even better things.
How to Make a Script
1. Create a folder somewhere to store your script and images (that you will collect later)
2. Right click, and choose New Autohotkey Script

3. That will create a .ahk file.


4. Right-click that newly created file and select Edit Script.
5. Delete everything inside.
Using AutoScriptWriter (recorder) to Record your Mouse Movements to Collect Tax
1. Open your VM with Empire opened.
2. Open the software AutoScriptWriter (recorder)

3. When it is open, it will look like this:

4. Press the Red Record button, then on your VM: Collect taxes, End collecting early, Click the Tick, Collect
taxes for 10 minutes, Close the taxes window

5. Then press the Stop button on your AutoScriptWriter


6. Your AutoscriptWriter should now look something like this:

7. If you havent done so already. Create a new Autohotkey script, as described above and rename the file to
tax.ahk (then right-click Edit and delete the contents inside).
8. Copy all the contents from the AutoScriptWriter window into the tax.ahk file.
9. In your tax.ahk file, you will need to specify a hotkey to activate this script, and also make the script stop:
!F1::
WinWait, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi) 192.168.56.102,
IfWinNotActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.102, , WinActivate, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800
(480x800`, 240dpi) - 192.168.56.102,
WinWaitActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.102,
MouseClick, left, 76, 417
Sleep, 500
MouseClick, left, 206, 417
Sleep, 500
MouseClick, left, 261, 461
Sleep, 500
MouseClick, left, 377, 77
Sleep, 500
Return

10. !F1:: - it is essential to put the double colon at the end of the key to specify that it is a hotkey. This means
it is Alt+F1. You will also notice that I changed the Sleep, 100 between each step to 500. 100 milliseconds
is too fast for the software because sometimes it lags, so it is better to be safe and delay it for longer.
11. Go ahead and Save this file. Double Click it. And a little green icon with a white H should appear in your
task bar.

12. Now, press Alt+F1 and watch as your mouse moves to collect tax for you. As we included the Return at
the end of the script, it will stop and only perform the same actions if you press Alt+F1.
13. You can also include a hotkey to Pause your script (this is important when your script gets more
complicated, as it will later on!)
14. To do that, right-click the H button and select Edit Script. And make a hotkey by adding the following
under the previous Return with
!p::
Pause
Return

15. And now Save and right-click the H button again and select Reload this Script. (It will not update the script
until you reload it. So that is important to know!)
16. You can test your hotkeys now, but going Alt+F1 and quickly pressing Alt+p. And you will see that the H
icon is now red with a white H.
17. If that worked, you can Edit the script again and remove both hotkeys, just delete the !F1:: and
!p::
Pause
Return

18. from the script and Save it again. We will use this script again later. (You can also Right click the H icon
and exit this script)
Congratulations, you have now made your first simple script!
How to Navigate to Your Main Castle
This is very simple. It will just be a series of mouse clicks.
1. Create a new .ahk file and call it main.ahk
2. Right click, Edit script and delete the contents
3. Open AutoScriptWriter, and have your VM with empire open (make sure everything inside the
AutoScriptWriter is deleted if you had anything in there previously)
4. Press the red Record button and in your VM go to Navigation Choose Location Your Main Castle
X to close button (if you are not currently your main you still should press the X button in the top right
corner even if its loading your main castle, its a precautionary step) [Press Stop on the AutoScriptWriter]
5. This is what it should be inside the AutoScriptWriter screen:
WinWait, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi) 192.168.56.101,
IfWinNotActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101, , WinActivate, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800
(480x800`, 240dpi) - 192.168.56.101,
WinWaitActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101,
MouseClick, left, 68, 622
Sleep, 100
MouseClick, left, 78, 462
Sleep, 100
MouseClick, left, 341, 246
Sleep, 100
MouseClick, left, 384, 75
Sleep, 100

6. Now you should paste all of that inside your blank main.ahk file but change the sleep time to match the
following:
WinWait, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi) 192.168.56.101,
IfWinNotActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101, , WinActivate, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800
(480x800`, 240dpi) - 192.168.56.101,
WinWaitActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101,
MouseClick, left, 68, 622
Sleep, 500

MouseClick, left, 78, 462


Sleep, 1500
MouseClick, left, 341, 246
Sleep, 500
MouseClick, left, 384, 75
Sleep, 12000

And thats all you need to navigate to your main castle. You dont need to test this script as it is very basic. You
can leave it now and continue to the next part.
How to make a Script to check to do a quick check for offers and close it
This is important. Sometimes, at random hours a popup for some offer or events like the merchant or whatever
will pop up on your screen. You will need to tell the script to close it so it can proceed with the rest of the script.
The way I do this is very simple. By just pressing the Escape button, it will close any windows, but if no windows
are open, it will ask if you want to quit the game. The way this little script works is, it requires an Image Search
for a part of the window that pops up that prompts if you would like to close the game. This means you will need
to perform a screen capture to crop a part of the window that pops up. You can also use the Snipping Tool if you
are using Windows 7).
1. In the VM with Empire open without any windows open inside the game, press the Esc button
2. The Attention! window should pop up

3. Now you need to only crop a small part of that window, like the following:

4.
5.
6.
7.
8.
9.

You can save your image in the folder where you have your scripts, and save it as check.png
Now make a new script in your folder, call it check.ahk.
Right click on check.ahk and select Edit Script.
Delete the content inside.
For testing purposes, we are going to set a hotkey to this script (but we wont need the hotkey later).
Type the following in your check.ahk file:
!F1::
Send {Esc}
Sleep, 500
ImageSearch, FoundX, FoundY, 0, 0, A_Screenwidth, A_ScreenHeight, *5 %A_ScriptDir%\check.png
{
If ErrorLevel = 2
MsgBox Error
Else If ErrorLevel = 1
{
}
Else
{
Send {Esc}
}

}
Return

10. You really dont need to change anything, only if you had saved that picture as something else.
11. Now Save the Script. Double Click to load it, and press Alt+F1 to see if it works.
12. If it works, you can delete the !F1:: part at the start, and Save the file again. We will leave it for now. (You
can also Right click the H icon and exit this script)
That was pretty easy wasnt it? Now to something a bit more complicated!
How to make a Script to produce Battling Rams
This will show how to scroll down and find the battling ram to produce it. This is the basis of troop recruitment
and tool production. You will just need to copy the instructions here and change a few things recruit/ produce
different things.
1. You now need to make 2 screen captures (either using the printscreen function, then opening it in paint and
cropping the file and save it OR if you have Windows 7, you can use the Snipping Tool to perform the
same function). Shown highlighted in the following (you only need to crop the section in the red rectangle).

2. So then you will have two files that look almost the same like these:
3. But the catch is, they are not the same because theres a very slight shading at the top and bottom and it
changes if its on top or bottom (this is hard to explain, but just trust me that you need both files!)
4. Name the one from the first image where the battering ram is at the bottom to br-bottom.png and the other
one br-top.png.
5. Now you can create a new script and call it br.ahk
6. Right click, Edit Script and delete the contents in that script, and leave it for now.
7. Like before, open up both AutoScriptWriter and your VM with Empire open.
8. In Empire go into one of your castles (the one you would like to produce battling rams).
9. Like before, we will record the mouse movements (but if you had anything in the AutoScriptWriter from
before, make sure you delete it before you start recording so you dont confuse yourself).
Also, if you are like me and dont like to waste rubies to open new slots, before you start recording make sure you
have already started producing rams (or anything else) in the empty slots first, so when you click on the production
button, the window that prompts if you would like to pay for rubies pop up (so you can close it, of course).

10. Press the Red Start button and press on Military Produce tools Scroll down to find the battling ram
Click on the produce button (then click on the close the prompt from above if you dont want to buy an
extra slot) X button on the top to return back to the main screen.
11. If you have successfully done that, this is what your script window in AutoScriptWriter should look like:
WinWait, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi) 192.168.56.101,
IfWinNotActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101, , WinActivate, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800
(480x800`, 240dpi) - 192.168.56.101,
WinWaitActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101,
MouseClick, left, 389, 613
Sleep, 100
MouseClick, left, 378, 477
Sleep, 100
MouseClick, left, 227, 582
Sleep, 100
MouseClick, left, 332, 434
Sleep, 100
MouseClick, left, 382, 174
Sleep, 100
MouseClick, left, 381, 76
Sleep, 100

12. So this is good, but 100 milliseconds between each click is way too fast for Empire, as it likes to lag quite
a lot, so we will need to change it (we will do that later).
13. Breaking it down: MouseClick, left, 389, 613 opens the Military menu, MouseClick, left, 378, 477 opens the
Produce tools menu, MouseClick, left, 227, 582 wont actually do anything productive, as it is only a mouse
click, but it should be a mouse click and drag the in order to find the battling ram. So we will need to
change the command to MouseClickDrag and also in order for the script to do itself, it needs to perform an
Image Search (like we did earlier on with the check.ahk). The next MouseClick, left, 332, 434 clicks on the
to produce the tools, MouseClick, left, 382, 174 closes the window that pops up to rent a slot, and finally
MouseClick, left, 381, 76 clicks on the X button to return to the main screen.
14. As before, we will need to include a hotkey so we can test it (then we will remove the hotkey when we are
satisfied that it works). This is how your script should look like:
!F1::
WinWait, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi) 192.168.56.101,

IfWinNotActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101, , WinActivate, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800
(480x800`, 240dpi) - 192.168.56.101,
WinWaitActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101,
MouseClick, left, 377, 617
Sleep, 500
MouseClick, left, 369, 460
Sleep, 4000
Loop, 4
{
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *3 %A_ScriptDir%\br-top.PNG
{
If errorlevel = 2
Msgbox erorr
Else If errorlevel = 1
{
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *3 %A_ScriptDir%\br-bottom.PNG
{
If errorlevel = 2
Msgbox errorrr
Else if errorlevel = 1
{MouseClickDrag, L, 214, 587, 220, 463, 20
Sleep, 2000
}
Else
{
MouseClick, L, FoundX+270, FoundY
break
}
}
}
Else
{
MouseClick, L, FoundX+270, FoundY
break
}
}
}
Sleep, 500
MouseClick, left, 377, 160
Sleep, 500
MouseClick, left, 375, 66
Sleep, 4000
Return

This will be the most complicated script type of them all. This loops an Image Search for the br-top.png file, and
if it doesnt see it, it goes on to the second Image Search to find the br-bottom.png file. If it doesnt find either
images, it will perform the MouseClickDrag from position X=214, Y=587 to X=220, Y=463 at the speed of 20.
This repeats for 4 times (you can set this for greater values when you want to make the script for other tools like
sticks for example). If it doesnt find anything it will continue on to close that window. If it does find the image, it
will perform a Mouse Click at the position where it was found with X+270 pixels. You can also change this value
to suit your size. Remember to delete the assigned hotkey !F1:: and Save the file again when you are happy that
it works.
How to Recruit Veteran bowman
This is much simpler than the last script as you dont need to scroll.
1.
2.
3.
4.

Create a new .ahk file. Rename it to range-def.ahk


Right-click, Edit Script and delete the contents
Like before, have both AutoScriptWriter and your VM with Empire open
Press the red Record button and in your VM go to Military Recruit The range tab Click on the
button to recruit veteran bowman.

5. Press the stop button on AutoScriptWriter.


6. But like before, if youre like me and dont want to spend rubies on extra slots, you can fill in the
recruitment slots first, so that when you click on the
button, the window to prompt you will pop up.
That is what I have done, and this is what it looks like in the AutoScriptWriter:
WinWait, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi) 192.168.56.101,
IfWinNotActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101, , WinActivate, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800
(480x800`, 240dpi) - 192.168.56.101,
WinWaitActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101,
MouseClick, left, 369, 631
Sleep, 100
MouseClick, left, 382, 534
Sleep, 100
MouseClick, left, 123, 163
Sleep, 100
MouseClick, left, 339, 557
Sleep, 100
MouseClick, left, 382, 160
Sleep, 100
MouseClick, left, 391, 77
Sleep, 100

7. Again you will need to change the Sleep time to the following (you might want to play with this yourself
to suit you better though, this is just what I use):
WinWait, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi) 192.168.56.101,
IfWinNotActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101, , WinActivate, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800
(480x800`, 240dpi) - 192.168.56.101,
WinWaitActive, Genymotion for personal use - Samsung Galaxy S2 - 4.1.1 - API 16 - 480x800 (480x800`, 240dpi)
- 192.168.56.101,
MouseClick, left, 369, 631
Sleep, 500
MouseClick, left, 382, 534
Sleep, 1500
MouseClick, left, 123, 163
Sleep, 1500
MouseClick, left, 340, 555
Sleep, 500
MouseClick, left, 382, 160
Sleep, 500
MouseClick, left, 391, 77
Sleep, 500

And you can save this file. You wont need to test. But if you want to, you should be able to by now, assigning a
hotkey etc.
Checklist of the Scripts you have made
1. tax.ahk to collect tax
2. check.ahk to check for popups
3. main.ahk to navigate to your main castle. You can copy the contents of this file to make a script to
navigate to your next OP and you will only need to change the Y by a few pixels or so. To find what the
value you need you can use the program called AutoIt3 Window Spy that also comes with the AutoHotkey
install. If you click on your screen it will give you the pixels. The red square is where my mouse was and
in AutoIt3 Window Spy, it gives you the coordinates of the active window, that is the value you want to
change.

4. br.ahk to make battling rams. You can use to script to make any tool and also recruit troops, you will
just need to take the correct screenshots and adjust your scripts to reflect the correct coordinates.
5. range-def.ahk to make Veteran bowman. Just like the br.ahk, you can use this as your basis to recruit
other troops or produce ladders for example.
Putting it all together
Now it is time to make a master script to call up all these scripts for you. This is very simple.
1. Create a new .ahk file. Call you anything you want.
2. Right click, Edit Script, delete the contents
For example, I want the script to Collect Tax, Go to my Main Castle, Recruit Veteran Bowman and then Produce
Battling Rams every 10 minutes and 2 seconds. It will look like this:
!F1::
SetTimer, MyScript, 60200
MyScript:
#Include %A_ScriptDir%\check.ahk
#Include %A_ScriptDir%\tax.ahk
#Include %A_ScriptDir%\main.ahk
#Include %A_ScriptDir%\range-def.ahk

#Include %A_ScriptDir%\br.ahk
Return
!p::
Pause
Return

As you can see, its fairly straightforward. SetTimer sets a timer for the label called MyScript for 60200
milliseconds = 10mins 2 secs. And then I just use the command #Include to call up my other scripts.
However, when you have made all the necessary files, i.e. your other navigation files for all your OPs, and other
troops/tools. Itll look something like the following (to recruit range def and br at op1, and melee-def and mantlet
at op2:
!F1::
SetTimer, MyScript, 60200
MyScript:
#Include %A_ScriptDir%\check.ahk
#Include %A_ScriptDir%\tax.ahk
#Include %A_ScriptDir%\main.ahk
#Include %A_ScriptDir%\range-def.ahk
#Include %A_ScriptDir%\br.ahk
#Include %A_ScriptDir%\op1.ahk
#IncludeAgain %A_ScriptDir%\range-def.ahk
#IncludeAgain %A_ScriptDir%\br.ahk
#Include %A_ScriptDir%\op2.ahk
%Include %A_ScriptDir%\melee-def.ahk
%Include %A_ScriptDir%\mantlet.ahk
Return
!p::
Pause

You will notice that you need to have #IncludeAgain if you are opening the same script twice. This is important, so
remember!
Also to note, you can turn things off if you dont want to delete it from the script completely by simply putting a
semicolon ; in front of the script line. i.e.
;#Include %A_ScriptDir%\range-def.ahk

This means that AutoHotkey will not see that line and not execute it.
And thats basically all you need to know! Remember to Reload the script every time you make any changes or
else it will not register. Goodluck! - fucoidan

Troubleshooting
If you have any issues later on with the scripts that require images, you might need to re-crop and save them. I
have had to do that, I dont even know why.
Commands that you need to know
You can find the detailed explanations of each command from the list of commands here:
http://www.autohotkey.com/docs/commands.htm
But these are the ones that I use in my scripts with my basic explanations.
MouseClick
MouseClick, left, 78, 418

Performing a left mouse click at the position of X=78, Y=418 in the active window.

MouseClickDrag
MouseClickDrag, L, 214, 587, 220, 463, 20

Performing a mouse click and drag. This is an example of a left mouse click at X=214, Y=587 followed
by a mouse drag to X=220, Y=463, with a speed of 20.

Sleep
Sleep, 1500

This command tells the script to wait before proceeding to the next action, wait for 1500=1.5 sec.

ImageSearch
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *5 %A_ScriptDir%\br-bottom.png

This is rather complicated to explain, but all you really need to do is change the picture file name and it
should work without any issues. This basically just does an image search in the window for that particular
image file.

Return
Return

This tells the script to stop running and go back to the beginning until reactivated.

SetTimer
SetTimer, MyScript, 602000
MyScript:

This is setting a timer for the script with the label MyScript (you can change this to anything you like but
you must also change the one underneath to match), set to repeat from beginning after 10 minutes and 2
seconds.

Potrebbero piacerti anche