AutoHotkey Community

It is currently May 27th, 2012, 9:04 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: October 21st, 2011, 12:22 am 
Offline

Joined: September 27th, 2011, 12:49 am
Posts: 15
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 October 31st, 2011, 7:03 pm, edited 6 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2011, 3:26 am 
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!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2011, 3:59 am 
Offline

Joined: September 27th, 2011, 12:49 am
Posts: 15
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 26th, 2011, 3:07 pm 
how do i set this up exactly?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 26th, 2011, 3:14 pm 
Offline

Joined: September 27th, 2011, 12:49 am
Posts: 15
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 28th, 2011, 4:06 am 
hmmm the "t" key doesn't seem to work for me when i'm typing in game.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 28th, 2011, 5:18 am 
Offline

Joined: September 27th, 2011, 12:49 am
Posts: 15
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Disable Script
PostPosted: October 29th, 2011, 1:37 am 
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!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2011, 6:18 pm 
How do u do this on xbox360 controller on pc?


Report this post
Top
  
Reply with quote  
 Post subject: Re: Disable Script
PostPosted: October 30th, 2011, 12:17 am 
Offline

Joined: September 27th, 2011, 12:49 am
Posts: 15
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 30th, 2011, 6:32 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 30th, 2011, 1:35 pm 
I'd just go Huntress to be honest. It's pretty much a disable button in itself...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 31st, 2011, 3:28 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject: "t" Key Problem
PostPosted: October 31st, 2011, 3:35 pm 
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?


Report this post
Top
  
Reply with quote  
 Post subject: Re: "t" Key Problem
PostPosted: October 31st, 2011, 3:46 pm 
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.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], Rajat and 6 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group