 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
doppleganger
Joined: 26 Sep 2011 Posts: 15
|
Posted: Thu Oct 20, 2011 11:22 pm Post subject: Dungeon Defenders auto-attack enabler |
|
|
I have put this script together to allow people to use auto-attack (aka rapid fire) for some of the heroes attacks.
Since each heroe has its particularities, I have decided to put hotkeys F5 to F8 to tweak the behavior of auto-attacks for each heroe.
F5: Apprentice
[left mouse hold preceded by left mouse doubleclick -> auto-attack]
[t -> Toggle between charged and non charged auto-attacks]
[Right Alt followed by a number (1,2...9,0) -> adjust length of charged auto-attacks]
[left mouse hold -> single shot charged staff attack]
F6: Squire
[left mouse hold -> auto-attack]
F7: Huntress [nothing, she already has auto-attack]
F8: Monk
[left mouse hold -> auto-attack]
[right mouse hold -> auto-attack]
RShift: Suspend Script [toggle or key hold mechanism, see bSuspendToggle in CUSTOMIZE OTHER SETTINGS section]
So you only got to make sure to select the correct setup (F5 to F8 ) for the heroe that is going to go through the Combat Phases.
New Features
1) Script Suspend functionality, either a toggle state or a key hold mechanism, adjustable via variable bSuspendToggle in CUSTOMIZE OTHER SETTINGS section. This functionality has been added mainly to let users hold down the left mouse button in certain situations where rapid fire is not desired, like dropping mana or upgrading equipment.
MOST RECENT VERSION
| Code: |
; Title: Dungeon Defenders Rapid Fire
; AutoHotkey Version Tested: AutoHotkey Basic and AutoHotkey_L Unicode 64 bits
; Language: English
; Platform: WINDOWS
; Author: doppleganger
; Version 1.5 Minor Adjustments, Script Suspend functionality added.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SetTitleMatchMode, 2
; ++++++++++++++++++++ CUSTOMIZE YOUR KEYBINDINGS ++++++++++++++++++++++
; For a list of the keys that can be used, see http://www.autohotkey.com/docs/KeyList.htm
keyUseWeapon:="LButton" ;Left mouse Button by default, change this for the keybinding you use In Game
keyAlternateWeapon:="RButton" ;Right mouse Button by default, change this for the keybinding you use In Game
keyApprentice:="F5" ;Activate auto-attack settings for Apprentice
keySquire:="F6" ;Activate auto-attack settings for Squire
keyHuntress:="F7" ;Activate auto-attack settings for Huntress
keyMonk:="F8" ;Activate auto-attack settings for Monk
keyToggleStaff:="t" ;Toggle between charged versus non charged staff attacks (Apprentice)
keySelectChargeDuration:="RAlt" ;User has 3 seconds to select charge duration by choosing from 1,2,...9,0 (Apprentice)
KeySuspend:="RShift" ;Suspend script hotkeys (script stops responding to keystrokes, excepted the suspend key)
; ++++++++++++++++++++ CUSTOMIZE MOUSE CLICK SPAM RATE +++++++++++++++++
mainMeleeDelay=50 ;Delay between melee attacks, in milliseconds
mainRangedDelay=20 ;Delay between main ranged attacks, , in milliseconds, 10 is around the lower you should put
alternateRangedDelay=75 ;Delay between alternate ranged attacks, in milliseconds, 50 is around the lower you should put
; +++++++++++++++++++++ CUSTOMIZE OTHER SETTINGS +++++++++++++++++++++++
mouseHoldDelay=0.2 ;Delay necessary for a mouse hold to be registered, in seconds
initialRapidfireDelay=200 ;Additional delay necessary before rapidfire kicks in, in milliseconds
bSuspendToggle:=false ;Make the Suspend key work as a toggle (true) or while key is held down (false)
; ++++++++++++++++++++ END OF CUSTOMIZE SECTION ++++++++++++++++++++++++
;Dynamically create the Hotkeys, based on the keybindings
HotKey, IfWinActive, Dungeon Defenders ;Make all Hotkeys work only if Dungeon Defenders is the active window
Hotkey, % "*$" keyUseWeapon, MainWeapon, Off ;Hotkey turned off at first, to force player to choose a setup (F5,F6...)
Hotkey, % "*$" keyAlternateWeapon, AlternateWeapon, Off ;Hotkey turned off at first, to force player to choose a setup (F5,F6...)
Hotkey, % keyApprentice, SetHeroeApprentice
Hotkey, % keySquire, SetHeroeSquire
Hotkey, % keyHuntress, SetHeroeHuntress
Hotkey, % keyMonk, SetHeroeMonk
Hotkey, % "*~" keyToggleStaff, ToggleStaffAttack
Hotkey, % "*" keySelectChargeDuration, SetChargeDuration
Hotkey, % "*" KeySuspend, SuspendHotkeys
;Initialization
bLDoubleClickAutoAttack:=false
bChargedStaff:=false
staffChargeDuration=500 ;Some initial value from the delayValues list
delayValues=50,100,250,500,750,1000,1250,1500,1750,2000
StringSplit, arrayDelays, delayValues, `,
return ; End of Auto-execute section
MainWeapon:
{
send {%keyUseWeapon% Down}
keywait, %keyUseWeapon%, t%mouseHoldDelay% ;Wait to see if mouse is released in the next 200 milliseconds
if errorlevel = 1 ;This registers as a 'press-n-hold' on the mouse button.
{
if (bLDoubleClickAutoAttack = true) ;Do we monitor double-cliks for this heroe?
{
; This detect if a double-click has been done, if so, enter in auto-attack mode
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500)
{
send {%keyUseWeapon% Up}
sleep initialRapidfireDelay ;Delay to prevent auto-attack firing mode from kicking in too fast
While GetKeyState(keyUseWeapon, "P")
{
;Are we doing charged staff attacks?
if(bChargedStaff = true)
{
Send {%keyUseWeapon% Down}
Sleep staffChargeDuration
Send {%keyUseWeapon% Up}
sleep mainRangedDelay
}
else ;We are doing non charged staff attacks
{
Send {%keyUseWeapon%}
sleep mainRangedDelay
}
}
}
else ;Enter in single shot 'charge up' attack mode (mainly for the apprentice staff charge attacks)
{
keywait, %keyUseWeapon%, u
send {%keyUseWeapon% Up}
}
}
else ;We monitor only single clicks for this heroe, this is mainly for melee attacks
{
;Enter in auto-attack mode
send {%keyUseWeapon% Up}
sleep initialRapidfireDelay ;Delay to prevent auto-attack firing mode from kicking in too fast
While GetKeyState(keyUseWeapon, "P")
{
Send {%keyUseWeapon%}
sleep mainMeleeDelay
}
}
}
else ;There was no 'press-n-hold', finish sending a regular mouse click
send {%keyUseWeapon% Up}
return
}
AlternateWeapon:
{
send {%keyAlternateWeapon% Down}
keywait, %keyAlternateWeapon%, t%mouseHoldDelay% ;Wait to see if mouse is released in the next 200 milliseconds
if errorlevel = 1 ;This registers a 'press-n-hold' on the mouse button.
{
;Enter in auto-attack mode
send {%keyAlternateWeapon% Up}
sleep initialRapidfireDelay ;Delay to prevent auto-attack firing mode from kicking in too fast
While GetKeyState(keyAlternateWeapon, "P")
{
Send {%keyAlternateWeapon%}
sleep alternateRangedDelay
}
}
else ;There was no 'press-n-hold', finish sending a regular mouse click
send {%keyAlternateWeapon% Up}
return
}
SuspendHotkeys:
;This suspends the script. It can either work as a toggling state
;or to suspend on key down and reactivate on key up
;User has to modify the bSuspendToggle value in the CUSTOMIZE section
Suspend
if(bSuspendToggle = false)
{
keywait, %KeySuspend%, u ;Wait for the release of suspend key
Suspend
}
return
ToggleStaffAttack:
bChargedStaff:= !bChargedStaff
return
SetChargeDuration:
Input, UserInput, L1 T2, , 1,2,3,4,5,6,7,8,9,0
if ErrorLevel = Match
{
if(UserInput = 0)
UserInput=10
staffChargeDuration = % arrayDelays%UserInput%
}
return
SetHeroeApprentice:
bLDoubleClickAutoAttack:=true
Hotkey, % "*$" keyUseWeapon, On
Hotkey, % "*$" keyAlternateWeapon, Off
return
SetHeroeSquire:
bLDoubleClickAutoAttack:=false
Hotkey, % "*$" keyUseWeapon, On
Hotkey, % "*$" keyAlternateWeapon, Off
return
SetHeroeHuntress:
bLDoubleClickAutoAttack:=false
Hotkey, % "*$" keyUseWeapon, Off
Hotkey, % "*$" keyAlternateWeapon, Off
return
SetHeroeMonk:
bLDoubleClickAutoAttack:=false
Hotkey, % "*$" keyUseWeapon, On
Hotkey, % "*$" keyAlternateWeapon, On
return
|
Last edited by doppleganger on Mon Oct 31, 2011 6:03 pm; edited 6 times in total |
|
| Back to top |
|
 |
Dave84 Guest
|
Posted: Fri Oct 21, 2011 2:26 am Post subject: |
|
|
Awesome script, it's great that it still lets you use the power up attack on the apprentice.
Question: Is there a way to speed up the rate that the script spams left click? There's roughly a 40% drop in damage output compared to manually clicking at the moment.
Thank you the script! |
|
| Back to top |
|
 |
doppleganger
Joined: 26 Sep 2011 Posts: 15
|
Posted: Fri Oct 21, 2011 2:59 am Post subject: |
|
|
| Dave84 wrote: | Awesome script, it's great that it still lets you use the power up attack on the apprentice.
Question: Is there a way to speed up the rate that the script spams left click? There's roughly a 40% drop in damage output compared to manually clicking at the moment.
Thank you the script! |
Im glad you like it.
I must admit I had not tried to emulate the fastest I could click, because I knew I would never play that way anyway (crazy fast)
I tweaked some delays to approximate the faster I can get and updated the script with those new values.
Basically, it is in the spots in the script where you have something like:
While GetKeyState("LButton", "P")
{
Send {LButton}
sleep 75 or 100
}
You just got to modify that 75 or 100 to lower values and see what you get.
The 1st spot (at 75 currently) is in regard to the apprentice spam attack
The 2nd spot (at 100 currently) is in regard to the squire and monk melee attacks. I did not test this case much, I figure it is already at max speed, since the animations for those attacks greatly limit the spamming.
The 3rd spot (at 75 currently) is on regard to the monk chi attack
I moved the code that this post refer to, right here, as I have put a newer version in the original post.
OLD VERSION
| Code: |
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;We disable the hotkeys by default at beginning, to force player to make a selection for his heroe (via Functions keys F5, F6, etc)
bLDoubleClickAutoAttack:=false
Hotkey, $LButton, off
Hotkey, $RButton, off
return ; End of Auto-execute section
F5::Gosub,SetHeroeApprentice
F6::Gosub,SetHeroeKnight
F7::Gosub,SetHeroeHuntress
F8::Gosub,SetHeroeMonk
#ifwinactive Dungeon Defenders
{
$LButton::
{
send {LButton Down}
keywait, Lbutton, t0.2 ;Wait to see if mouse is released in the next 200 milliseconds
if errorlevel = 1 ;This registers as a 'press-n-hold' on the mouse button.
{
if (bLDoubleClickAutoAttack = true) ;Do we monitor double-cliks for this heroe?
{
; This detect if a double-click has been done, if so, enter in auto-attack mode
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500)
{
send {LButton Up}
sleep 200 ;Delay to prevent auto-attack firing mode from kicking in too fast
While GetKeyState("LButton", "P")
{
Send {LButton}
sleep 75
}
}
else ;Enter in 'charge up' attack mode (mainly for the apprentice staff charge attacks)
{
keywait, Lbutton, u
send {LButton Up}
}
}
else ;We monitor only single clicks for this heroe
{
;Enter in auto-attack mode
send {LButton Up}
sleep 200 ;Delay to prevent auto-attack firing mode from kicking in too fast
While GetKeyState("LButton", "P")
{
Send {LButton}
sleep 100
}
}
}
else ;There was no 'press-n-hold', finish sending a regular mouse click
send {LButton Up}
return
}
$RButton::
{
send {RButton Down}
keywait, Rbutton, t0.2 ;Wait to see if mouse is released in the next 200 milliseconds
if errorlevel = 1 ;This registers a 'press-n-hold' on the mouse button.
{
;Enter in auto-attack mode
send {RButton Up}
sleep 200 ;Delay to prevent auto-attack firing mode from kicking in too fast
While GetKeyState("RButton", "P")
{
Send {RButton}
sleep 75
}
}
else ;There was no 'press-n-hold', finish sending a regular mouse click
send {RButton Up}
return
}
}
SetHeroeApprentice:
bLDoubleClickAutoAttack:=true
Hotkey, $LButton, On
Hotkey, $RButton, off
return
SetHeroeKnight:
bLDoubleClickAutoAttack:=false
Hotkey, $LButton, On
Hotkey, $RButton, off
return
SetHeroeHuntress:
bLDoubleClickAutoAttack:=false
Hotkey, $LButton, off
Hotkey, $RButton, off
return
SetHeroeMonk:
bLDoubleClickAutoAttack:=false
Hotkey, $LButton, On
Hotkey, $RButton, On
return
|
|
|
| Back to top |
|
 |
sykosis Guest
|
Posted: Wed Oct 26, 2011 2:07 pm Post subject: |
|
|
| how do i set this up exactly? |
|
| Back to top |
|
 |
doppleganger
Joined: 26 Sep 2011 Posts: 15
|
Posted: Wed Oct 26, 2011 2:14 pm Post subject: |
|
|
you simply got to download/install autohotkey
http://www.autohotkey.com/download/
The Installer for AutoHotkey Basic should be sufficient.
Once the program is installed, one more step: create the script file
Basically copy paste the code in a text editor and save as the name you want, and with .ahk for the type. So, it could be dungeondefender.ahk for example.
Now all got to do is double-click the file, it should launch the script. You will see an icon appear in your taskbar.
Finally, launch Dungeon Defender and have fun.
When you are done, dont forget to close the script. Simply right click on the icon in the taskbar and choose Exit |
|
| Back to top |
|
 |
francisjungle Guest
|
Posted: Fri Oct 28, 2011 3:06 am Post subject: |
|
|
| hmmm the "t" key doesn't seem to work for me when i'm typing in game. |
|
| Back to top |
|
 |
doppleganger
Joined: 26 Sep 2011 Posts: 15
|
Posted: Fri Oct 28, 2011 4:18 am Post subject: |
|
|
| francisjungle wrote: | | hmmm the "t" key doesn't seem to work for me when i'm typing in game. |
I changed a few things in the code that should make the toggling more instantaneous and more robust. So grab the new version in the original post and try it out! |
|
| Back to top |
|
 |
kinth Guest
|
Posted: Sat Oct 29, 2011 12:37 am Post subject: Disable Script |
|
|
First off, awesome job. I was thinking "someone should make a DunDef script that treats each character differently" and I Googled it and found this. Thanks!
I've noticed when doing things like dropping mana or upgrading weapons having a rapid fire enabled makes it impossible to hold down the arrow.
Could you add functionality so that when a key is held down, all functionality is disabled? Like if I set it to Left ALT, I could hold Left ALT and it would suspend the scripts until I release Left ALT.
Can't wait to see any improvements you make! |
|
| Back to top |
|
 |
judas Guest
|
Posted: Sat Oct 29, 2011 5:18 pm Post subject: |
|
|
| How do u do this on xbox360 controller on pc? |
|
| Back to top |
|
 |
doppleganger
Joined: 26 Sep 2011 Posts: 15
|
Posted: Sat Oct 29, 2011 11:17 pm Post subject: Re: Disable Script |
|
|
| kinth wrote: | First off, awesome job. I was thinking "someone should make a DunDef script that treats each character differently" and I Googled it and found this. Thanks!
I've noticed when doing things like dropping mana or upgrading weapons having a rapid fire enabled makes it impossible to hold down the arrow.
Could you add functionality so that when a key is held down, all functionality is disabled? Like if I set it to Left ALT, I could hold Left ALT and it would suspend the scripts until I release Left ALT.
Can't wait to see any improvements you make! |
I see, I must admit I have not played with the game that much up to now, I was dreading discovering a problem of that nature.
I have not made up my mind still on how to best address the problem. Add yet another key to temporarily disable/suspend the script? Or modify the Squire and Monk code so that in their case too, a user would have to double-click the mouse buttons to get in rapid fire mode.
| Judas wrote: |
How do u do this on xbox360 controller on pc?
|
As for the issue with how to get this to work with gamepads, I am afraid I cannot help much here, as I dont even have a gamepad with which to test the script. Your best bet is probably to ask in the Ask for Help section of this forum:
http://www.autohotkey.com/forum/viewforum.php?f=1 |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Oct 30, 2011 5:32 am Post subject: |
|
|
| The simple response for those issues like dropping mana etc, is to use the Apprentice setup for those situations since it has the option for using the power up. |
|
| Back to top |
|
 |
Rice Guest
|
Posted: Sun Oct 30, 2011 12:35 pm Post subject: |
|
|
| I'd just go Huntress to be honest. It's pretty much a disable button in itself... |
|
| Back to top |
|
 |
kinth Guest
|
Posted: Mon Oct 31, 2011 2:28 pm Post subject: |
|
|
| Rice wrote: | | I'd just go Huntress to be honest. It's pretty much a disable button in itself... |
Yeah, I've just been using the Huntress setup to do stuff like that, just would be a nice thing to have a quick fix. |
|
| Back to top |
|
 |
kinth Guest
|
Posted: Mon Oct 31, 2011 2:35 pm Post subject: "t" Key Problem |
|
|
Also, dopple, is there a fix for not being able to press the "t" key when typing? I assume the script is consuming it and not doing anything with it, but I can't find how to fix it.
Is there a way the script can consume the "t" key and still pass it in? |
|
| Back to top |
|
 |
kinth Guest
|
Posted: Mon Oct 31, 2011 2:46 pm Post subject: Re: "t" Key Problem |
|
|
| kinth wrote: | Also, dopple, is there a fix for not being able to press the "t" key when typing? I assume the script is consuming it and not doing anything with it, but I can't find how to fix it.
Is there a way the script can consume the "t" key and still pass it in? |
Went ahead and tried something really quick and it worked!
Just change the ToggleStaffAttack function to this:
| Code: | ToggleStaffAttack:
bChargedStaff:= !bChargedStaff
Send {%keyToggleStaff%}
return |
That will pass in the "t" key if you are typing in chat. *Note that if you are playing an Apprentice he will be toggling his charge every time you type "t" in chat. If you play other classes it doesn't matter. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|