Defend Your Life

Defend Your Life

Not enough ratings
[Script] Super hero (Hero Leveling) Script
By aquatorrent
AutoHotKey script to level your hero to 50.
   
Award
Favorite
Favorited
Unfavorite
Introduction
I feel like wanting to make a script after I read this guide. Sure, you also can level your hero manually (I find it easier to do it in Brain level since it'll be too boring to do it in level 1), but I just like to automate grindy things whenever possible.

This script requires you to install AutoHotkey[autohotkey.com].

Based on the AutoHotkey website,
AutoHotkey is a free, open-source scripting language for Windows that allows users to easily create small to complex scripts for all kinds of tasks such as: form fillers, auto-clicking, macros, etc.

This script might or might not require some configuration on your end so you have to install AutoHotkey to use this script.

Lastly, use it at your own risk.
Prerequisities
You might need to check your own coordinates and replace the one in the script based on your screen. Install this script by copying and paste-ing this code in a notepad and save it with an .ahk extension (ex: getcoordinates.ahk). Make sure that it has .ahk extension instead of .txt. You can change the setting in Windows here[support.microsoft.com].

CoordMode, Mouse, Window SetTimer, Check, 20 return Check: MouseGetPos, xx, yy PixelGetColor, color, %xx%, %yy% Tooltip %color% %xx% %yy% return ~^c:: Clipboard = %color% %xx% %yy% ClipWait return Esc::ExitApp

This code will basically retrieve your cursor's screen coordinates and pixel color based on your active window and show it in your cursor's tooltip. You can copy the information to your clipboard by pressing CTRL+C to paste it somewhere else (in a notepad, for example) by pressing CTRL+V. Lastly, the app will close if you press Escape button or you can right click the 'H' icon in your right taskbar tray and click Close. The second option works for all AHK script so you can also use it to close the actual script below.
The Script
SetMouseDelay, 1 Pause Loop{ ; click reload button PixelGetColor, color, 601, 506 if (color == 0x2BB7F9){ Click down, 601, 506 Sleep 5 Click up {ClickUp} Sleep 5 } PixelGetColor, color, 693, 694 if(color == 0x63DE7B){ ; click play button after loading Click down, 693, 694 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 1000 ; click hero Click down, 433, 72 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 ; move to position Click down, 407, 354 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 ; start wave Click down, 263, 346 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 ; click fast forward button Click down, 893, 76 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 ; place first tower Click down, 1015, 550 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 Click down, 1003, 428 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 ; place second tower Click down, 933, 530 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 Click down, 935, 416 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 ; place third tower Click down, 853, 514 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 Click down, 841, 406 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 } } F8::Pause Esc::ExitApp

In summary, the script will press play button (that will show up after it loads the level), move the hero near the "wave entrance", start the wave, click the fast forward button once, and place 3 towers. The script will also click the reload button after it finishes a level so you just need to run it once and leave the game runs until your hero is leveled to 50.

I'll explain the code bit by bit as you configure the coordinates yourself. Run the script in the prerequisites section, make sure that the Defend Your Life game is the active window (just click anywhere on the game just to make sure), and replace the coordinates and/or the color hex that I will mention below.

Note that I took the picture after I finished with the script so the coordinate might be different. However, you don't need to follow my coordinate; anywhere is fine as long as your cursor is pointing to what I'm talking about.

; click reload button PixelGetColor, color, 601, 506 if (color == 0x2BB7F9){ Click down, 601, 506 Sleep 5 Click up {ClickUp} Sleep 5 }
This will check if the coordinate 601, 506 has the same color hex as the reload button (0x2BB7F9). If it is the reload button, the script will click the button. Move your cursor to the yellow part of the reload button and replace 601, 506 with the coordinate and 0x2BB7F9 with the color hex.




PixelGetColor, color, 693, 694 if(color == 0x63DE7B){ ; click play button after loading Click down, 693, 694 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 1000
This will check if the coordinate 693, 694 has the same color hex as the play button (0x63DE7B). If it is the play button, the script will click the button. Move your cursor to the green part of the play button and replace 693, 694 with the coordinate and 0x63DE7B with the color hex.




; click hero Click down, 433, 72 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500
This script will select the hero by clicking the hero button. Move your cursor to anywhere on the button and replace 433, 72 with the coordinate.




; move to position Click down, 407, 354 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500
This script will move the hero to the starting position, near the "wave entrance". Move your cursor to anywhere near the "wave entrance" and replace 407, 354 with the coordinate.




; start wave Click down, 263, 346 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500
This script will start the wave. Move your cursor to the "start the next wave" button and replace 263, 346 with the coordinate.




; click fast forward button Click down, 893, 76 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500
This script will click the fast forward button, making the game runs at x4. Move your cursor to the fast forward button and replace 893, 76 with the coordinate.




; place first tower Click down, 1015, 550 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 Click down, 1003, 428 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500
This script will build a tower on the far back. Move your cursor to last empty spot to build a tower and replace 1015, 550 with the coordinate. Click the empty spot afterward to bring up the "buy tower" button and move your cursor to the "build tower" button and replace 1003, 428 with the coordinate.




; place second tower Click down, 933, 530 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 Click down, 935, 416 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500
This script will build a tower next to the previous tower. Move your cursor to empty spot to build a tower beside your previous tower and replace 933, 530 with the coordinate. Click the empty spot afterward to bring up the "buy tower" button and move your cursor to the "build tower" button and replace 935, 416 with the coordinate.




; place third tower Click down, 853, 514 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500 Click down, 841, 406 Sleep 5 Click up {ClickUp} Sleep 5 Sleep 500
This script will build a tower next to the previous tower. Move your cursor to empty spot to build a tower beside your previous tower and replace 853, 514 with the coordinate. Click the empty spot afterward to bring up the "buy tower" button and move your cursor to the "build tower" button and replace 841, 406 with the coordinate.

Utilizing the Script
Press F8 to start and/or pause the script and press Escape to exit the script. You can also close the script by doing right click on the 'H' icon in your taskbar tray and choose exit.

Note that this script will only start clicking automatically if you run the script before pressing the play button. If you run the script after pressing it, you can set up the first run yourself and run the script after you finish setting it up. The script will start clicking on the next run.

If you think that the script is clicking too fast, you can try changing the Sleep 500 and/or Sleep 1000 to a higher amount. I recommend to increase it by 500 and see if it's still clicking too fast for you.
Afterwords
Actually, I did try to auto click the "calling the waves early" button too but the script became buggy somehow. I ended up scrapping it since I only needed a few more levels before I got my hero to level 50. Hope it's still useful to you though!
References
2 Comments
aquatorrent  [author] 5 Sep, 2022 @ 10:18pm 
@rumbadebu: you're welcome! glad it helps :)
rumbadebu 5 Sep, 2022 @ 5:14pm 
Thanks! Great script. Can be used as is with 1366x768 resolution windowed mode