Dungeon Defenders

Dungeon Defenders

33 ratings
Automate Tasks in DD
By Acen
This guide is to show what a little scripting can do to save time within DD specifically but can be applied to other games.
2
   
Award
Favorite
Favorited
Unfavorite
Introduction
There are some monotonous things in DD that can get on one's nerves. Dropping a bunch of lab loot or assigning mana values in your AFK shop are just a couple of examples. Thus I decided to automate some of those tasks to make things go a little quicker for myself. Although we should give a big thanks to Crispybucket because he created the drop script and made it available for everyone when lab came out. He was nice enough to provide the code to me which then got me started on writing for other things.

Listed below are some ways you can use scripting to your advantage in DD or really in any other game. I am including links to script files containing all the code below and the corresponding executables in case you dont want to do any copy and pasting.

Scripts and EXE Files
The Program
Autohotkey[www.autohotkey.com] is the tool I used to create the script and eventually create an exe to easily give to others. Some may not want to use an exe file since you never know what someone has put into it, so I am providing code below where you can make your own if you wish. Just start a new script and then copy and paste the code into the script file.

Note: Parts of the scripts do not work for controller users since they use the mouse and keyboard. If you want to use these scripts, make sure you are logged in with the mouse and keyboard.
The Drop
First off is the script that started it all. Here is the drop script code provided by Crispybucket.

Directions
  • Select an item to start with
  • Place cursor over Drop Item
  • Hit F7 to start
  • Hit F8 to stop

; CrispyBucket's Drop Script code runAutoClick := false autoClick: if (runAutoClick == true) { sleep 50 click left sleep 50 send l goto autoClick } return F7:: runAutoClick := true soundbeep, 1500, 400 goto autoClick return F8:: runAutoClick := false soundbeep, 1000, 400 return
The Shop
AFK shops are great for players both buying and selling. New players can find gear they need rather easily to help gear up for some harder challenges. Sellers can get mana for those all important upgrades. However assigning values was tiresome to me. So I decided to automate it some of it. This script is used to assign mana values within your AFK shop. I have used F2-F6 to assign different mana values from 20 million up to 600 million.

Note: The script uses x and y coordinates for the mouse position which changes based on resolution used. There is a script that can help you find mouse positions if you need it.

This code is based on a Resolution of 1920x1080

Directions
  • Highlight an Item
  • Press F2 - F6 to assign desired value

F2:: MouseMove, 1432, 291, sleep 200 MouseClick, left sleep 200 Send, 20000000 sleep 200 MouseMove, 964, 646, MouseClick, left Return F3:: MouseMove, 1432, 291, sleep 200 MouseClick, left sleep 200 Send, 50000000 sleep 200 MouseMove, 964, 646, MouseClick, left Return F4:: MouseMove, 1432, 291, sleep 200 MouseClick, left sleep 200 Send, 100000000 sleep 200 MouseMove, 964, 646, MouseClick, left Return F5:: MouseMove, 1432, 291, sleep 200 MouseClick, left sleep 200 Send, 300000000 sleep 200 MouseMove, 964, 646, MouseClick, left Return F6:: MouseMove, 1432, 291, sleep 200 MouseClick, left sleep 200 Send, 600000000 sleep 200 MouseMove, 964, 646, MouseClick, left Return
The Upgrades
Upgrading can be troublesome. Finding the right gear and finding all the mana you need to upgrade can be difficult itself sometimes. Last thing I want to do is wear my finger out click 300 times to upgrade a piece or two.

Note: Make sure not to move the mouse while it is clicking. You can upgrade something you really dont want to. Also, the clicks do go fast so it may miss one here and there, especially if you arent in your tavern.

Directions for 100 Clicks
  • Hover mouse of desired stat to upgrade or over Next Page button
  • Hit the Windows key+Z to start
; 100 Mouse Clicks when upgrading #z:: Loop, 100 { MouseClick, left }

Directions for 9 Clicks
  • Hover mouse of desired stat to upgrade
  • Hit F9 to start
F9:: Loop, 9 { MouseClick, left }
Autoclicker and Autofire Loops
Automatic Left Clicking
This is an extension of the above autoclicker script, but for more general use. When you're playing the game, it's tiring to mash the mouse button.

This script is a toggle script, which means rather than two buttons to handle the script - one on, one off - it's all on one button. In this case, the F10 key.

We do this by using a while loop and by having our button press invert whatever the current state of our boolean is. The While loop only runs the script in the braces when the boolean is true, but it will not get to the block after the closing brace until the boolean is false.

#MaxThreadsPerHotkey 2 ; ; AUTOMATIC LEFT CLICK runLeftMouseAuto := false F10:: runLeftMouseAuto := !runLeftMouseAuto While runLeftMouseAuto { Click Sleep 50 } return

Let's break this down:

#MaxThreadsPerHotkey 2

By default, AutoHotKey handles only one instance of a hotkey at any given time. Our toggle runs the script again, even if the script is already running.

runLeftMouseAuto := !runLeftMouseAuto

This inverts the current state of the boolean. At the start of the block, we instantiated and declated runLeftMouseAuto in a false state. So, when you press F10, the first thing the script does is flip runLeftMouseAuto into a true state. Then, it goes into the While loop.

While runLeftMouseAuto { Click Sleep 50 }

This is a while loop, which means the script will only run what's in the loop while runLeftMouseAuto is true. It will not escape the loop until the condition is made false. When we hit F10 again, we're running a second instance of the script that inverts the boolean again and lets the script get to what is after the closing brace.

The Sleep command is timed in miliseconds. At Sleep 50, you click 20 times a second! You can increase or decrease the number of clicks per second as you like. Note that, while auto left or right clicking, your mouse movement will stutter when the game's framerate drops. Jump over to the Prerequisite UDKInput.ini editing section to see the workaround for this.

return

This ends the instance of the hotkey's script.
Prequesite UDKInput.ini editing
The following scripts were written using a minor modifcation to the game's UDKInput.ini. Because of the mouse stuttering that's caused in the laggier parts of the game, it's actually better *not* to use an autoclicker that uses your mouse keys. The following scripts use the [ and ] keys as left and right mouse buttons respectively, but without replacing the functionality of the actual buttons or of the controller.

To do this, we're going to go to the UDKInput.ini file in our Dungeon Defender's configuration. It is located like so:

C:\Program Files (x86)\Steam\SteamApps\common\Dungeon Defenders\UDKGame\Config\UDKInput.ini

You know you're in the right file when the first line of text is "[Engine.PlayerInput]" followed by a long list of "Bindings=..." Scroll to the bottom of those bindings and add these two lines to the file:

Bindings=(Name="LeftBracket",Command="PrimaryFire") Bindings=(Name="RightBracket",Command="AltFire")

With this method, you can actually add a second or even third alternative set of keys without overtaking your controller's bindings. Interestingly, this does not make it to where you can use the [ key in the game's menus, which, alas, includes upgrades. Mainly, this consideration is for emulator users, but it also helps me because I swap back and forth between controller and mouse/keyboard a lot lately.

The Perfect Charge Shot
So, you know when you have that great staff that does great damage and has a good charge? To get real work out of it, you don't just hold down left click and then right click for autofire. You have to hold down left click and time those presses accordingly so some of that good charge gets used. That's a hassle, and a lot of people just default to the ol' faithful hold-left-n'-then-right method.

This script will work around the tapping you'll have to do. All you have to do is point, and the script will do the rest. This script works on the same toggling premise as the Autoclicker script before. This time around, I also broke down the script within the script itself using comments, denoted by semi-colons ( ; ).

The code in hastebin.[hastebin.com] (Steam did not like the way this was written, due to the use of brackets.)

The all-caps comment after "sleep 147" should have jumped out to you. The three things to keep in mind about this are lag, framerate, and the charge speed on the staff. This is one of those scripts you'll want sitting open in notepad so you can adjust it and reload it accordingly as you play.

...Or, you could have multiple versions of this script that handle different charge, lag, or framerate amounts. If you do that, you could also remember to kill other firing scripts when you toggle them, so that only one type of firing script runs at a time. It'd look something like:

Sample code.[hastebin.com] (Steam still doesn't like brackets.)
Automating Building
Alright, so let's get to the fun stuff. Let's automate the building process.

Auras and Traps
We'll start the easy way.

; AURA STACK DROPPER ~ NIGHTMARE Numpad1:: Send 6 ; Default Ensnare Aura Key sleep 250 ; MouseClick, left sleep 600 Send 7 ; Default Electric Aura Key sleep 250 MouseClick, left sleep 600 Send 9 ; Default Stength Drain Aura Key sleep 250 MouseClick, left return

This is an aura stack dropper. Auras and traps, unlike our friends the towers, do not have a second click where you have to face their positioning. Sleep 250 is spacing out the clicks so the game doesn't miss your inputs on account of pressing too quickly. Sleep 600 combines the actual summoning time - based on a 1.5k cast rate on a Monk - and a small rest period so that the game can receive your inputs again without skipping them.

It goes without saying, you can add a Heal Aura or an Enrage Aura in your stack script, and it'd look much the same as this. A new Send-Sleep-Click-Sleep block that stats the send with the relevant ingame hotkey.

Tower and Minion Lines
Minion lines, what? Chill out, I wrote the minion line scripts inside and outside of Overlord mode. This example will use a minion line script that uses your movement outside of Overlord mode to place a 5 minion-wide line that fits on a 4 DU buff beam.

; 5 WIDE MINION LINE NO OVERLORD (START AT THE RIGHT) Numpad5:: Send 1 ; Archer Minion sleep 250 MouseClick, left sleep 250 MouseClick, left sleep 1000 ; Archer Summoning Length Send {a down} Sleep 366 Send {a up} Send 1 ; Archer Minion sleep 250 MouseClick, left sleep 250 MouseClick, left sleep 1000 ; Archer Summoning Length Send {a down} Sleep 366 Send {a up} Send 3 ; Spider Minion sleep 250 MouseClick, left sleep 250 MouseClick, left sleep 1500 ; Spider Summoning Length Send 2 ; Mage Minion sleep 250 MouseClick, left sleep 250 MouseClick, left sleep 2250 ; Mage Summoning Length Send {a down} Sleep 388 Send {a up} Send 1 ; Archer Minion sleep 250 MouseClick, left sleep 250 MouseClick, left sleep 1000 ; Archer Summoning Length Send {a down} Sleep 366 Send {a up} Send 1 ; Archer Minion sleep 250 MouseClick, left sleep 250 MouseClick, left sleep 1000 ; Archer Summoning Length return

Alright, so let's zero in on this block of repeating code:

Send {a down} Sleep 366 Send {a up}

This code is essentially saying to press and hold the 'a' (strafe left) key for 366 milliseconds to move your character to the left. It does this to move in a perfect horizontal line, to a spot that isn't "occupied" by another minion or tower.

This script has you start at the right, but you can alter the direction you move simply by changing the Send {a down} and Send {a up} code to the directional keypress you want. So, going backwards would look like:

Send {s down} Sleep 366 Send {s up}

I chose this example because a Summoner's minion summoning speed is consistent, no matter what Hero Casting Rate you have. If you decide to make a similar script for placing harpoons in a line, you adjust the sleep times where the Minions' Summoning length in. You might have to adjust the sleep on the movement as well, depending on how much wider or skinnier the tower is compared to the minions.
Automatic Overlording
Okay, the big one. This is the reason you want scripting, full-stop.

Stacks
Here[hastebin.com] is your generic stacked minion summoning script. It summons a Mage, a Spider, and then four archers on the same spot in Overlord mode. It uses the same Sleep periods as the non-overlord Minion line scripts above.

Bear in mind, this doesn't take advantage of Overlord mode's ability to be summoning multiple minions of different types at the same time. None of the scripts following this will do so either. So this *can* be optimized further.

Lines and Lines that use Stacks
Here[hastebin.com] are four scripts for use in Overlord mode. These scripts are written based on a 1280x720 screen and having your player FOV pulled all the way back. However, it never actually moves your Mouse to a spot on the screen, rather, it moves your mouse relative to the initial position it was at when you initiated the script.

Here's the breakdown:

Numpad2:: ^Numpad2:: Numpad3:: ^Numpad3::

Just pressing Numpad 2 or 3 will give you will give you a generic line.[i.gyazo.com] 2 will be a horizontal line, and 3 will be a vertical line. Prefixing the key with ^ means to hold Ctrl and then press the key. So Ctrl + Numpad 3 will give you a vertical line[i.gyazo.com] with 3 archers on one end, a mage and spider in the middle, and another 3 archers on the other end, in the space of a 4 DU Buff Beam.

MouseMove [horizontal], [vertical], [speed], [relative]

MouseMove takes your mouse and moves it to a spot on the screen, like your typical X/Y coordinate grid. The original point, 0,0 is at the top left corner of your screen. Speed is how quickly the mouse moves over, and having it at 0 means movement is instantaneous. There is quite literally no reason not to have your speed at 0 during MouseMove commands.

Relative, or R, is the backbone of the minion scripts. As it says, it changes the MouseMove command so that the origin point of the X/Y coordinate becomes your mouse's position.

Also, worth noting is that Mouse move is affected by how much you are zoomed in or out in Overlord mode. Your lines won't be as tight or will be tighter, depending on the zoom. For reference, these scripts were written at the default zoom, summoning minions on on the same height of floor as the player was standing on when he went into Overlord.
13 Comments
Camera Jun 12, 2018 @ 3:45pm 
Broken hastebin links :(
Jackenmen Feb 26, 2018 @ 7:45am 
Yay, pls comment, if you update links, so I will get a notification :)
Acen  [author] Feb 25, 2018 @ 7:37pm 
thanks for letting me know. I will check on it
Jackenmen Feb 25, 2018 @ 6:44am 
Any chance for update of scripts, because they're no longer there? :(
✪ KenjizzN Jan 26, 2016 @ 3:37pm 
thanks pai
communist daughter Dec 1, 2015 @ 2:37pm 
k thanks man.
Acen is my 12th senpai
Acen  [author] Dec 1, 2015 @ 1:40pm 
What script are you trying to use? If you are using an emulator that uses the Function keys (F1-F4) then make sure you don't create or use a script that uses those keys. The script will take priority over the emulator.

To unload, look for it in the system tray on the bottom right side of your screen and just right click on it and select exit.
communist daughter Dec 1, 2015 @ 12:54pm 
This fucked up my game, My emulator doesnt work anymore, i almost sold 3 charcters because of what it does, i cant uninstall it
awesome Sep 5, 2015 @ 12:34pm 
i have looked at it... wont halp
Acen  [author] Sep 5, 2015 @ 6:36am 
You should look at pew pew pew's troubleshooting guide . Typically it is hamachi, -tcp or firewall that is causing the issue. Sometimes if you steam name has weird characters in it as well.