AutoHotkey Community

It is currently May 27th, 2012, 12:59 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Chat Key Toggle
PostPosted: October 31st, 2011, 3:52 pm 
In addition to the option of suspending the script while holding a certain key, it would be cool to implement a chat toggle for pausing the script as well.

I think it would be best with the Enter key bound to chat in game:

1. Press Enter to open your in game chat.
-AHK script detects "Enter" press
-Pauses AHK script
-Sends "Enter" press to game
2. Type your chat message.
3. Press Enter to send message.
-AHK script detects "Enter" press
-Unpauses AHK script
-Sends "Enter" press to game

Any conceivable way to do this?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 31st, 2011, 5:17 pm 
Offline

Joined: May 16th, 2010, 2:38 pm
Posts: 185
really cool, will look into the script once i have time


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 31st, 2011, 7:06 pm 
Offline

Joined: May 16th, 2010, 2:38 pm
Posts: 185
nice, it works, though i was not able to get "t" and "RAlt" option to work for apprentice
but in whole this script allow you avoid annoying mouse clicking, thou thank you!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 31st, 2011, 7:20 pm 
Offline

Joined: September 27th, 2011, 12:49 am
Posts: 15
A new version is up.

I added a Script Suspend functionality, via key Right Shift, easily changeable as usual. See New features section in OP for more details. The equivalent could already be done using the Huntress setup, but it annoyed me that one would have to use the Huntress setup for the purpose of disabling the script.

I also modified the hotkey for Toggle Rapid fire, so that the script does no longer "eat" the "t" keystrokes.

As for a mechanism to automatically pause the script when users use the chat or console, I thought briefly on this, and while it is feasible, I am not sure yet I want to add that. I would have to filter all the various ways a user can exit those modes (enter, esc, etc). This would add yet more code. Looks to me like it is simply easier to avoid binding alphanumeric keys. I know that the key for Toggling rapid fire "t" does contradict my last sentence, but I merely change a variable state when the key is used, so it is not a big deal.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2011, 2:19 am 
Offline

Joined: September 27th, 2011, 12:49 am
Posts: 15
Deo wrote:
nice, it works, though i was not able to get "t" and "RAlt" option to work for apprentice
but in whole this script allow you avoid annoying mouse clicking, thou thank you!


So, just to be sure, you did use F5 for apprentice, then doubleclicked left mouse button, got rapid fire going, then used "t" and no toggling occurred?

I have noticed you wrote some autohotkey code, so if you feel like doing a few tests with MsgBox to see if code does execute regarding the rapid fire toggling, it would help! Check the ToggleStaffAttack: label, as well as the content of the loop on line 76: While GetKeyState(keyUseWeapon, "P")

Im sorry I cant help more, but since I cannot replicate the problem...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2011, 11:32 am 
Thing is amazing, thanks!

Only question - it pauses to do a more charged attack every few seconds or so, causing me to lose dps. Any clue how to fix this?


Report this post
Top
  
Reply with quote  
 Post subject: inconsistent DPS
PostPosted: December 31st, 2011, 11:41 am 
hello. i love the script, i was using it long before they built auto-fire into the game.

now, i have an apprentice that uses staves that have super high charge values. it is impractical for me to try to rapid fire, because the charge animation kicks in and really lowers my DPS.

problem with this script is, the DPS is very inconsistent, with charged and non-charged attacks. i have been unable to figure out what #s to tweak in the script to get identical damage/DPS every time, just like the in-game auto-fire does.

what settings do i need to tweak so that my damage output is consistent each time? even helping me to figure out how to do this with a non-charged attack will im sure help point me in the right direction. :)

thanks!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2012, 8:05 am 
I'm having a strange problem with this script. I'm using the Apprentice F5 mode and when I jump and move some direction while holding down left mouse button my character will start moving continuously in some direction and he won't stop until I jump and move while firing again. He moves even though I'm not holding down w,a,s, or d.


Report this post
Top
  
Reply with quote  
 Post subject: Re: inconsistent DPS
PostPosted: January 30th, 2012, 12:03 am 
fayde8 wrote:
hello. i love the script, i was using it long before they built auto-fire into the game.

now, i have an apprentice that uses staves that have super high charge values. it is impractical for me to try to rapid fire, because the charge animation kicks in and really lowers my DPS.

problem with this script is, the DPS is very inconsistent, with charged and non-charged attacks. i have been unable to figure out what #s to tweak in the script to get identical damage/DPS every time, just like the in-game auto-fire does.

what settings do i need to tweak so that my damage output is consistent each time? even helping me to figure out how to do this with a non-charged attack will im sure help point me in the right direction. :)

thanks!


I noticed this too. I think I know why it's doing, but really haven't dived deep enough into this scripting language to figure out how to fix it. My thoery:
When we double click and hold the left mouse button it is being captured by dungeon defenders and the autohotkey script as well. The autohotkey script is taking that hold down and turning it into clicks and releases. I think somehow dungeon defenders is capturing both the raw input from the mouse and the input from the script. A way to fix this would be to change the key binding in your dungeon defenders .ini file for auto attack. This would allow the Left click to be interpreted by only the mouse.

Hope this helps and can be fixed. [/i]


Report this post
Top
  
Reply with quote  
 Post subject: Updated script
PostPosted: February 1st, 2012, 11:11 pm 
Offline

Joined: February 1st, 2012, 10:55 pm
Posts: 4
Hi everyone,

I updated this script after I found it a couple of days ago and thought I would post my modified version here. I like being able to just hit a keyboard key once without holding for auto-attack/alternate to occur. Also, it is more user friendly and provides info when you press/click things.

Hope someone finds it useful. Cheers.

Changes as noted in the file are:
Version 1.6: 2012/02/01 - Lots of changes.
*) Toggling charged staff is now done with Numpad *.
*) Suspend script right shift key now defaults to being a toggle. (Holding down keys is a pain.)
*) Numpad is used by default for new features. This should stop problems with hotkeys and chat. If you don't have a numpad or don't want to use it, see "DISABLE NUMPAD" in the CUSTOMIZE YOUR KEYBINDINGS section below.
*) Can now toggle primary auto-attack via a keyboard key. Hit Numlock / to enable. Hit it again to disable. This means you don't have to hold down the mouse or keys!
*) Can now toggle alternate auto-attack via a keyboard key. Hit Numlock Enter to enable. Hit it again to disable. This means you don't have to hold down the mouse or keys!
*) You can decrease and increase your staff charge time easily with Numpad - and +.
*) More user friendly. Many features now give you notifications in the top left to let you know what is going on. Help is also displayed if you have not selected a class.
*) Alternate auto-attack on apprentice keeps firing and does a charge up.
*) Alternate auto-attack on squire just keeps his sword in block position.
*) Use built in auto-attack now if a class has one.


Code:
; Title: Dungeon Defenders Rapid Fire
; AutoHotkey Version Tested: AutoHotkey Basic and AutoHotkey_L Unicode 64 bits
; Language:       English
; Platform:       WINDOWS
; Original based on:
; Author:         doppleganger
; Version 1.5 Minor Adjustments, Script Suspend functionality added.

; Version 1.6: 2012/02/01 - Lots of changes.
; Author: Ordanos
; *) Toggling charged staff is now done with Numpad *.
; *) Suspend script right shift key now defaults to being a toggle. (Holding down keys is a pain.)
; *) Numpad is used by default for new features. This should stop problems with hotkeys and chat.
;    If you don't have a numpad or don't want to use it, see "DISABLE NUMPAD" in the
;    CUSTOMIZE YOUR KEYBINDINGS section below.
; *) Can now toggle primary auto-attack via a keyboard key. Hit Numlock / to enable.
;    Hit it again to disable. This means you don't have to hold down the mouse or keys!
; *) Can now toggle alternate auto-attack via a keyboard key. Hit Numlock Enter to enable.
;    Hit it again to disable. This means you don't have to hold down the mouse or keys!
; *) You can decrease and increase your staff charge time easily with Numpad - and +.
; *) More user friendly. Many features now give you notifications in the top left to
;    let you know what is going on. Help is also displayed if you have not selected a class.
; *) Alternate auto-attack on apprentice keeps firing and does a charge up.
; *) Alternate auto-attack on squire just keeps his sword in block position.
; *) Use built in auto-attack now if a class has one.


#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
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)

keyToggleAutoAttack:="NumpadDiv"   ;Hitting this key will enable primary auto-attack. Hit again to turn off.
keyToggleAutoAlternateAttack:="NumpadEnter" ;Hitting this key will enable alternate auto-attack. Hit again to turn off.
keyToggleChargedStaff:="NumpadMult"       ;Toggle between charged versus non charged staff attacks (Apprentice)
keyLowerStaffCharge:="NumpadSub"   ; Lowers staff charge time.
keyRaiseStaffCharge:="NumpadAdd"   ; Raises staff charge time.
; DISABLE NUMPAD: REMOVE THE BEGINNING SEMI-COLONS ON THE NEXT 5 LINES TO DISABLE USE OF THE NUMPAD. DO NOT REMOVE ON THIS LINE
;keyToggleAutoAttack:="["   ;Hitting this key will enable primary auto-attack. Hit again to turn off.
;keyToggleAutoAlternateAttack:="]" ;Hitting this key will enable alternate auto-attack. Hit again to turn off.
;keyToggleChargedStaff:="\"       ;Toggle between charged versus non charged staff attacks (Apprentice)
;keyLowerStaffCharge:="-"   ; Lowers staff charge time.
;keyRaiseStaffCharge:="="   ; Raises staff charge time.




; ++++++++++++++++++++ CUSTOMIZE MOUSE CLICK SPAM RATE +++++++++++++++++
mainRangedDelay=20         ;Delay between main ranged attacks, in milliseconds, 10 is around the lower you should put
alternateRangedDelay=75    ;Delay between apprentice alternate 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:=true         ;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, On             ;Hotkey turned on at first to force player to choose a setup (F5,F6...)
Hotkey, % "*$" keyAlternateWeapon, AlternateWeapon, On  ;Hotkey turned on at first to force player to choose a setup (F5,F6...)
Hotkey, % keyApprentice, SetHeroApprentice
Hotkey, % keySquire, SetHeroSquire
Hotkey, % keyHuntress, SetHeroHuntress
Hotkey, % keyMonk, SetHeroMonk
Hotkey, % "*~" keyToggleChargedStaff, ToggleStaffAttack
Hotkey, % "*" keySelectChargeDuration, SetChargeDuration
Hotkey, % "*" KeySuspend, SuspendHotkeys
Hotkey, % keyLowerStaffCharge, lowerStaffCharge
Hotkey, % keyRaiseStaffCharge, raiseStaffCharge
Hotkey, % keyToggleAutoAttack, ToggleAutoAttack, "T2" ; allow 2 threads for this hotkey. so we can toggle with same key
Hotkey, % keyToggleAutoAlternateAttack, ToggleAutoAlternateAttack, "T2" ; allow 2 threads for this hotkey. so we can toggle with same key


;Initialization
bChargedStaff:=true
staffChargeDuration=149      ;Some initial value from the delayValues list
delayValues=50,100,149,250,500,750,1000,1250,1500,1750
characterType:=""
doToggleAutoAttack:=false
doToggleAutoAlternateAttack:=false
StringSplit, arrayDelays, delayValues, `,

;Status Variables
inAutoAttack:=false
inAutoAlternateAttack:=false

return   ; End of Auto-execute section




; Only use for apprentice
MainWeapon:
{
  if(characterType=""){
    Send {%keyUseWeapon%}
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack || doToggleAutoAlternateAttack){
    showToolTip("Primary or alternate auto-attack is on. Disable to use mouse attack")
    return
  }

   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.
   {
     ; 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)
     {
       showToolTip("Enabling mouse double click auto-attack")
       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   ;There was no 'press-n-hold', finish sending a regular mouse click
   {
     Send {%keyUseWeapon% Up}
   }

   return
}


; Only use for apprentice
AlternateWeapon:
{
  if(characterType=""){
    Send {%keyAlternateWeapon%}
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack || doToggleAutoAlternateAttack){
    showToolTip("Primary or alternate auto-attack is on. Disable to use mouse attack")
    return
  }

  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% Down}
      Sleep staffChargeDuration
      Send {%keyAlternateWeapon% Up}
      Sleep alternateRangedDelay
    }
  }
  else   ;There was no 'press-n-hold', finish sending a regular mouse click
  {
    Send {%keyAlternateWeapon% Up}
  }

  return
}


ToggleAutoAttack:
{
  if(characterType=""){
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack = true){
    showToolTip("Disabling auto-attack")
    doToggleAutoAttack:=false
    return
  }

  inAutoAttack:=true

  if(doToggleAutoAlternateAttack=true){ ; disable the alternate attack if it is already going
    doToggleAutoAlternateAttack:= false
    return
  }

  ; Was going to attempt to streamline script with these, but didn't see much improvement.
  ;SetBatchLines -1
  ;SetMouseDelay, -1

  doToggleAutoAttack:=true
  showToolTip("Enabling auto-attack")

  if (characterType = "apprentice")
  {
    Send {%keyUseWeapon%}
    Sleep initialRapidfireDelay      ;Delay to prevent auto-attack firing mode from kicking in too fast

    While doToggleAutoAttack
    {
      ;Are we doing charged staff attacks?
      if(bChargedStaff = true)
      {
        Send {%keyUseWeapon% Down}
        Sleep staffChargeDuration
        Send {%keyUseWeapon% Up}
      }
      else   ;We are doing non charged staff attacks
      {
        Send {%keyUseWeapon%}
      }
      Sleep mainRangedDelay
    }
  }
  else   ;We monitor only single clicks for this hero, this is mainly for melee attacks
  {
    ;Enter in auto-attack mode
    Send {%keyUseWeapon% Down}
    While doToggleAutoAttack
    {
      Sleep 50
      if(!GetKeyState(keyUseWeapon) ){ ; User probably clicked alternate mouse button. Disable attack.
        doToggleAutoAttack:=false
        break
      }
    }
    Send {%keyUseWeapon% Up}
  }

  inAutoAttack:=false
  showToolTip("Primary auto-attack disabled")

  ; The alternate auto-attack hotkey disabled us and exited. Running the alternate routine again to continue.
  ; We want to do this in a separate thread, so that it doesn't count against our threads per hotkey.
  if(inAutoAlternateAttack){
    SetTimer, ToggleAutoAlternateAttack, -1000 ; negative value to run once. [v1.0.46.16+]
  }

  return
}





ToggleAutoAlternateAttack:
{
  if(characterType=""){
    displayHelp("Need to select a class.")
    return
  }

  if(characterType="huntress"){
    showToolTip("Huntress does not need auto alternate attack")
    return
  }

  if(doToggleAutoAlternateAttack = true){
    showToolTip("Disabling alternate auto-attack")
    doToggleAutoAlternateAttack:=false
    return
  }

  inAutoAlternateAttack:=true

  if(doToggleAutoAttack){ ; disable primary auto-attack if it is going
    doToggleAutoAttack:= false
    return
  }

  doToggleAutoAlternateAttack:= true

  if( characterType = "apprentice" ){
    showToolTip("Enabling apprentice alternate auto-attack")
    While doToggleAutoAlternateAttack
    {
      Send {%keyAlternateWeapon% Down}
      Sleep staffChargeDuration
      Send {%keyAlternateWeapon% Up}
      Sleep alternateRangedDelay
    }
  }else{
    showToolTip("Enabling alternate auto-attack")
    Send {%keyAlternateWeapon% Down}
    While doToggleAutoAlternateAttack
    {
      Sleep 50
      if(!GetKeyState(keyAlternateWeapon) ){ ; User probably clicked alternate mouse button. Disable attack.
        doToggleAutoAlternateAttack:=false
        break
      }
    }
    Send {%keyAlternateWeapon% Up}
  }

  inAutoAlternateAttack:=false
  showToolTip("Alternate auto-attack disabled")

  ; The primary auto-attack hotkey disabled us and exited. Running the primary routine again to continue.
  ; We want to do this in a separate thread, so that it doesn't count against our threads per hotkey.
  if(inAutoAttack){
    SetTimer, ToggleAutoAttack, -1000 ; negative value to run once. [v1.0.46.16+]
  }

  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:
{
  if(bChargedStaff){
    showToolTip("Disabling charged staff")
  }else{
    showToolTip("Enabling charged staff")
  }
  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

     showToolTip( "Changing staff charge delay to: " .  arrayDelays%UserInput% )
     staffChargeDuration = % arrayDelays%UserInput%
  }
  return
}

lowerStaffCharge:
{
  staffChargeDuration:= staffChargeDuration - 1
  if(staffChargeDuration < 20){
    staffChargeDuration:= 20
  }
  showToolTip("New staff charge duration is " . staffChargeDuration . " ms")
  return
}

raiseStaffCharge:
{
  staffChargeDuration:= staffChargeDuration + 1
  if(staffChargeDuration > 10000){
    staffChargeDuration:= 10000
  }
  showToolTip("New staff charge duration is " . staffChargeDuration . " ms")
  return
}


SetHeroApprentice:
{
  characterType:="apprentice"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, On
  Hotkey, % "*$" keyAlternateWeapon, On
  return
}

SetHeroSquire:
{
  characterType:="squire"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroHuntress:
{
  characterType:="huntress"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroMonk:
{
  characterType:="monk"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}


showToolTip(text, time=3000){
  ToolTip % text, 20, 50
  SetTimer, RemoveToolTip, % time
  return
}

RemoveToolTip:
{
  SetTimer, RemoveToolTip, Off
  ToolTip
  return
}

displayHelp(errorText=""){
  showToolTip( (errorText = "" ? "" : errorText . "`n" ) . "Need to select a class first. F5: Apprentice/Adept, F6: Squire/Countess, F7: Huntress/Ranger, F8:Monk/Initiate")
  return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2012, 3:57 am 
Great work on the update! Hey, do you feel like incorporating the Barbarian into this script? So far only a little bit of early work has been done, this is the only script I know of:

http://forums.trendyent.com/showthread. ... acro/page2

But specifically, check out my post here, which suggests that we incorporate this script and use the same "adjustable" or pre-set delays for the Barbarian combo attack, depending on the swing speed of the weapons he has equipped:

http://forums.trendyent.com/showthread. ... post325123

Cheers!


Report this post
Top
  
Reply with quote  
 Post subject: update 1.7
PostPosted: February 2nd, 2012, 10:56 am 
Offline

Joined: February 1st, 2012, 10:55 pm
Posts: 4
Yes, I just played barbarian tonight and noticed the need for the new combo attack in this script. I wrote it just now, but only did minor testing.

Attached here is the new 1.7 script that does the barbarian combo attack. Note that it's pretty late right now and brain is a bit foggy, so hopefully I didn't make any errors. Let me know if you find a bug.

Changelog:
Version 1.7: 2012/02/02 - Add Barbarian. (F9 key)
*) Do barbarian combo attack as primary auto-attack.
*) You can decrease or increase the delay between left and right click by using the staff charge keys while you have the barbarian class selected. (Default is Numpad -/+ or right alt and a number.)

Code:
; Title: Dungeon Defenders Rapid Fire
; AutoHotkey Version Tested: AutoHotkey Basic and AutoHotkey_L Unicode 64 bits
; Language:       English
; Platform:       WINDOWS
; Original based on:
; Author:         doppleganger
; Version 1.5 Minor Adjustments, Script Suspend functionality added.

; Version 1.6: 2012/02/01 - Lots of changes.
; Author: Ordanos
; *) Toggling charged staff is now done with Numpad *.
; *) Suspend script right shift key now defaults to being a toggle. (Holding down keys is a pain.)
; *) Numpad is used by default for new features. This should stop problems with hotkeys and chat.
;    If you don't have a numpad or don't want to use it, see "DISABLE NUMPAD" in the
;    CUSTOMIZE YOUR KEYBINDINGS section below.
; *) Can now toggle primary auto-attack via a keyboard key. Hit Numlock / to enable.
;    Hit it again to disable. This means you don't have to hold down the mouse or keys!
; *) Can now toggle alternate auto-attack via a keyboard key. Hit Numlock Enter to enable.
;    Hit it again to disable. This means you don't have to hold down the mouse or keys!
; *) You can decrease and increase your staff charge time easily with Numpad - and +.
; *) More user friendly. Many features now give you notifications in the top left to
;    let you know what is going on. Help is also displayed if you have not selected a class.
; *) Alternate auto-attack on apprentice keeps firing and does a charge up.
; *) Alternate auto-attack on squire just keeps his sword in block position.
; *) Use built in auto-attack now if a class has one.

; Version 1.7: 2012/02/02 - Add Barbarian. (F9 key)
; Author: Ordanos
; *) Do barbarian combo attack as primary auto-attack.
; *) You can decrease or increase the delay between left and right click by using the staff charge
;    keys while you have the barbarian class selected. (Default is Numpad -/+ or right alt and a number.)

#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
keyBarbarian:="F9"                 ;Activate auto-attack settings for Barbarian
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)

keyToggleAutoAttack:="NumpadDiv"   ;Hitting this key will enable primary auto-attack. Hit again to turn off.
keyToggleAutoAlternateAttack:="NumpadEnter" ;Hitting this key will enable alternate auto-attack. Hit again to turn off.
keyToggleChargedStaff:="NumpadMult"       ;Toggle between charged versus non charged staff attacks (Apprentice)
keyLowerStaffCharge:="NumpadSub"   ; Lowers staff charge time.
keyRaiseStaffCharge:="NumpadAdd"   ; Raises staff charge time.
; DISABLE NUMPAD: REMOVE THE BEGINNING SEMI-COLONS ON THE NEXT 5 LINES TO DISABLE USE OF THE NUMPAD. DO NOT REMOVE ON THIS LINE
;keyToggleAutoAttack:="["   ;Hitting this key will enable primary auto-attack. Hit again to turn off.
;keyToggleAutoAlternateAttack:="]" ;Hitting this key will enable alternate auto-attack. Hit again to turn off.
;keyToggleChargedStaff:="\"       ;Toggle between charged versus non charged staff attacks (Apprentice)
;keyLowerStaffCharge:="-"   ; Lowers staff charge time.
;keyRaiseStaffCharge:="="   ; Raises staff charge time.




; ++++++++++++++++++++ CUSTOMIZE MOUSE CLICK SPAM RATE +++++++++++++++++
mainRangedDelay=20         ;Delay between main ranged attacks, in milliseconds, 10 is around the lower you should put
alternateRangedDelay=75    ;Delay between apprentice alternate 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:=true         ;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, On             ;Hotkey turned on at first to force player to choose a setup (F5,F6...)
Hotkey, % "*$" keyAlternateWeapon, AlternateWeapon, On  ;Hotkey turned on at first to force player to choose a setup (F5,F6...)
Hotkey, % keyApprentice, SetHeroApprentice
Hotkey, % keySquire, SetHeroSquire
Hotkey, % keyHuntress, SetHeroHuntress
Hotkey, % keyMonk, SetHeroMonk
Hotkey, % keyBarbarian, SetHeroBarbarian
Hotkey, % "*~" keyToggleChargedStaff, ToggleStaffAttack
Hotkey, % "*" keySelectChargeDuration, SetChargeDuration
Hotkey, % "*" KeySuspend, SuspendHotkeys
Hotkey, % keyLowerStaffCharge, lowerStaffCharge
Hotkey, % keyRaiseStaffCharge, raiseStaffCharge
Hotkey, % keyToggleAutoAttack, ToggleAutoAttack, "T2" ; allow 2 threads for this hotkey. so we can toggle with same key
Hotkey, % keyToggleAutoAlternateAttack, ToggleAutoAlternateAttack, "T2" ; allow 2 threads for this hotkey. so we can toggle with same key


;Initialization
bChargedStaff:=true
staffChargeDuration=149      ;Some initial value from the delayValues list
barbarianComboDelay:=100      ; Initial barbarian click delay between left and right clicks.
delayValues=50,100,149,250,500,750,1000,1250,1500,1750
characterType:=""
doToggleAutoAttack:=false
doToggleAutoAlternateAttack:=false
StringSplit, arrayDelays, delayValues, `,

;Status Variables
inAutoAttack:=false
inAutoAlternateAttack:=false

return   ; End of Auto-execute section




; Only use for apprentice
MainWeapon:
{
  if(characterType=""){
    Send {%keyUseWeapon%}
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack || doToggleAutoAlternateAttack){
    showToolTip("Primary or alternate auto-attack is on. Disable to use mouse attack")
    return
  }

   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.
   {
     ; 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)
     {
       showToolTip("Enabling mouse double click auto-attack")
       Send {%keyUseWeapon% Up}
       if(characterType="barbarian"){ ; barbarian allows a combo attack.
         While GetKeyState(keyUseWeapon, "P")
         {
           Send {%keyUseWeapon%}
           Sleep barbarianComboDelay
           Send {%keyAlternateWeapon%}
           Sleep barbarianComboDelay
         }
       }
          else ; apprentice
       {
         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
           }
         } ; end while

       } ; end apprentice else

     }
     else    ;Enter in single shot 'charge up' attack mode (mainly for the apprentice staff charge attacks)
     {
       keywait, %keyUseWeapon%, u
       Send {%keyUseWeapon% Up}
     }
   }
   else   ;There was no 'press-n-hold', finish sending a regular mouse click
   {
     Send {%keyUseWeapon% Up}
   }

   return
}


; Only use for apprentice
AlternateWeapon:
{
  if(characterType=""){
    Send {%keyAlternateWeapon%}
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack || doToggleAutoAlternateAttack){
    showToolTip("Primary or alternate auto-attack is on. Disable to use mouse attack")
    return
  }

  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% Down}
      Sleep staffChargeDuration
      Send {%keyAlternateWeapon% Up}
      Sleep alternateRangedDelay
    }
  }
  else   ;There was no 'press-n-hold', finish sending a regular mouse click
  {
    Send {%keyAlternateWeapon% Up}
  }

  return
}


ToggleAutoAttack:
{
  if(characterType=""){
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack = true){
    showToolTip("Disabling auto-attack")
    doToggleAutoAttack:=false
    return
  }

  inAutoAttack:=true

  if(doToggleAutoAlternateAttack=true){ ; disable the alternate attack if it is already going
    doToggleAutoAlternateAttack:= false
    return
  }

  ; Was going to attempt to streamline script with these, but didn't see much improvement.
  ;SetBatchLines -1
  ;SetMouseDelay, -1

  doToggleAutoAttack:=true
  showToolTip("Enabling auto-attack")

  if (characterType = "apprentice")
  {
    Send {%keyUseWeapon%}
    Sleep initialRapidfireDelay      ;Delay to prevent auto-attack firing mode from kicking in too fast

    While doToggleAutoAttack
    {
      ;Are we doing charged staff attacks?
      if(bChargedStaff = true)
      {
        Send {%keyUseWeapon% Down}
        Sleep staffChargeDuration
        Send {%keyUseWeapon% Up}
      }
      else   ;We are doing non charged staff attacks
      {
        Send {%keyUseWeapon%}
      }
      Sleep mainRangedDelay
    }
  }
  else   ;We monitor only single clicks for this hero, this is mainly for melee attacks
  {
    ;Enter in auto-attack mode
    if(characterType="barbarian"){ ; barbarian allows a combo attack.
      While doToggleAutoAttack
      {
        Send {%keyUseWeapon%}
        Sleep barbarianComboDelay
        Send {%keyAlternateWeapon%}
        Sleep barbarianComboDelay
      }
    }
    else
    {
      Send {%keyUseWeapon% Down}
      While doToggleAutoAttack
      {
        Sleep 50
        if(!GetKeyState(keyUseWeapon) ){ ; User probably clicked primary mouse button. Disable attack.
          doToggleAutoAttack:=false
          break
        }
      }
      Send {%keyUseWeapon% Up}
    }
  }

  inAutoAttack:=false
  showToolTip("Primary auto-attack disabled")

  ; The alternate auto-attack hotkey disabled us and exited. Running the alternate routine again to continue.
  ; We want to do this in a separate thread, so that it doesn't count against our threads per hotkey.
  if(inAutoAlternateAttack){
    SetTimer, ToggleAutoAlternateAttack, -1000 ; negative value to run once. [v1.0.46.16+]
  }

  return
}





ToggleAutoAlternateAttack:
{
  if(characterType=""){
    displayHelp("Need to select a class.")
    return
  }

  if(characterType="huntress"){
    showToolTip("Huntress does not need auto alternate attack")
    return
  }

  if(doToggleAutoAlternateAttack = true){
    showToolTip("Disabling alternate auto-attack")
    doToggleAutoAlternateAttack:=false
    return
  }

  inAutoAlternateAttack:=true

  if(doToggleAutoAttack){ ; disable primary auto-attack if it is going
    doToggleAutoAttack:= false
    return
  }

  doToggleAutoAlternateAttack:= true

  if( characterType = "apprentice" ){
    showToolTip("Enabling apprentice alternate auto-attack")
    While doToggleAutoAlternateAttack
    {
      Send {%keyAlternateWeapon% Down}
      Sleep staffChargeDuration
      Send {%keyAlternateWeapon% Up}
      Sleep alternateRangedDelay
    }
  }else{
    showToolTip("Enabling alternate auto-attack")
    Send {%keyAlternateWeapon% Down}
    While doToggleAutoAlternateAttack
    {
      Sleep 50
      if(!GetKeyState(keyAlternateWeapon) ){ ; User probably clicked alternate mouse button. Disable attack.
        doToggleAutoAlternateAttack:=false
        break
      }
    }
    Send {%keyAlternateWeapon% Up}
  }

  inAutoAlternateAttack:=false
  showToolTip("Alternate auto-attack disabled")

  ; The primary auto-attack hotkey disabled us and exited. Running the primary routine again to continue.
  ; We want to do this in a separate thread, so that it doesn't count against our threads per hotkey.
  if(inAutoAttack){
    SetTimer, ToggleAutoAttack, -1000 ; negative value to run once. [v1.0.46.16+]
  }

  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:
{
  if(bChargedStaff){
    showToolTip("Disabling charged staff")
  }else{
    showToolTip("Enabling charged staff")
  }
  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

        if(characterType="barbarian"){
          showToolTip( "New barbarian combo delay is " .  arrayDelays%UserInput% . " ms")
          barbarianComboDelay = % arrayDelays%UserInput%
          return
        }

     showToolTip( "New staff charge duration is " .  arrayDelays%UserInput% . " ms")
     staffChargeDuration = % arrayDelays%UserInput%
  }
  return
}

lowerStaffCharge:
{
  if(characterType="barbarian"){
    barbarianComboDelay:= barbarianComboDelay - 1
    if(barbarianComboDelay < 20){
      barbarianComboDelay:= 20
    }
    showToolTip("New barbarian combo delay is " . barbarianComboDelay . " ms")
    return
  }

  staffChargeDuration:= staffChargeDuration - 1
  if(staffChargeDuration < 20){
    staffChargeDuration:= 20
  }
  showToolTip("New staff charge duration is " . staffChargeDuration . " ms")
  return
}

raiseStaffCharge:
{
  if(characterType="barbarian"){
    barbarianComboDelay:= barbarianComboDelay + 1
    if(barbarianComboDelay > 10000){
      barbarianComboDelay:= 10000
    }
    showToolTip("New barbarian combo delay is " . barbarianComboDelay . " ms")
    return
  }

  staffChargeDuration:= staffChargeDuration + 1
  if(staffChargeDuration > 10000){
    staffChargeDuration:= 10000
  }
  showToolTip("New staff charge duration is " . staffChargeDuration . " ms")
  return
}


SetHeroApprentice:
{
  characterType:="apprentice"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, On
  Hotkey, % "*$" keyAlternateWeapon, On
  return
}

SetHeroSquire:
{
  characterType:="squire"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroHuntress:
{
  characterType:="huntress"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroMonk:
{
  characterType:="monk"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroBarbarian:
{
  characterType:="barbarian"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, On
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}


showToolTip(text, time=3000){
  ToolTip % text, 20, 50
  SetTimer, RemoveToolTip, % time
  return
}

RemoveToolTip:
{
  SetTimer, RemoveToolTip, Off
  ToolTip
  return
}

displayHelp(errorText=""){
  showToolTip( (errorText = "" ? "" : errorText . "`n" ) . "Need to select a class first. F5: Apprentice/Adept, F6: Squire/Countess, F7: Huntress/Ranger, F8:Monk/Initiate, F9:Barbarian")
  return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2012, 11:01 pm 
Offline

Joined: February 1st, 2012, 10:55 pm
Posts: 4
Version 1.8. Probably my last change for now.
*) Disable toggleable auto-attack when primary/alternate fire pressed.
*) Add Windows-Escape hotkey to exit script.

Key Summary:
F5: Apprentice/Adept, F6: Squire/Countess, F7: Huntress/Ranger, F8:Monk/Initiate, F9:Barbarian

Double click and hold left mouse enables auto-fire of primary
Double click and hold right mouse enables auto-fire of alternate

Numpad /: Toggle primary auto attack
Numpad Enter: Toggle alternate auto attack

Right alt and 1,2,3,4,5,6,7,8,9, or 0: Change staff charge duration or barbarian combo click delay if barbarian selected.

Numlock -/+: Change apprentice charge duration in small increments. (Or barbarian combo click delay if barbarian selected.)

Numpad *: Toggle staff charge.

Win-Escape: Exit Script
Right Shift: Suspend script.


Code:
; Title: Dungeon Defenders Rapid Fire
; AutoHotkey Version Tested: AutoHotkey Basic and AutoHotkey_L Unicode 64 bits
; Language:       English
; Platform:       WINDOWS
; Original based on:
; Author:         doppleganger
; Version 1.5 Minor Adjustments, Script Suspend functionality added.

; Version 1.6: 2012/02/01 - Lots of changes.
; Author: Ordanos
; *) Toggling charged staff is now done with Numpad *.
; *) Suspend script right shift key now defaults to being a toggle. (Holding down keys is a pain.)
; *) Numpad is used by default for new features. This should stop problems with hotkeys and chat.
;    If you don't have a numpad or don't want to use it, see "DISABLE NUMPAD" in the
;    CUSTOMIZE YOUR KEYBINDINGS section below.
; *) Can now toggle primary auto-attack via a keyboard key. Hit Numlock / to enable.
;    Hit it again to disable. This means you don't have to hold down the mouse or keys!
; *) Can now toggle alternate auto-attack via a keyboard key. Hit Numlock Enter to enable.
;    Hit it again to disable. This means you don't have to hold down the mouse or keys!
; *) You can decrease and increase your staff charge time easily with Numpad - and +.
; *) More user friendly. Many features now give you notifications in the top left to
;    let you know what is going on. Help is also displayed if you have not selected a class.
; *) Alternate auto-attack on apprentice keeps firing and does a charge up.
; *) Alternate auto-attack on squire just keeps his sword in block position.
; *) Use built in auto-attack now if a class has one.

; Version 1.7: 2012/02/02 - Add Barbarian. (F9 key)
; Author: Ordanos
; *) Do barbarian combo attack as primary auto-attack.
; *) You can decrease or increase the delay between left and right click by using the staff charge
;    keys while you have the barbarian class selected. (Default is Numpad -/+ or right alt and a number.)

; Version 1.8: 2012/02/11
; Author: Ordanos
; *) Disable toggleable auto-attack when primary/alternate fire pressed.
; *) Add Windows-Escape hotkey to exit script.

#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
keyBarbarian:="F9"                 ;Activate auto-attack settings for Barbarian
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)

keyToggleAutoAttack:="NumpadDiv"   ;Hitting this key will enable primary auto-attack. Hit again to turn off.
keyToggleAutoAlternateAttack:="NumpadEnter" ;Hitting this key will enable alternate auto-attack. Hit again to turn off.
keyToggleChargedStaff:="NumpadMult"       ;Toggle between charged versus non charged staff attacks (Apprentice)
keyLowerStaffCharge:="NumpadSub"   ; Lowers staff charge time.
keyRaiseStaffCharge:="NumpadAdd"   ; Raises staff charge time.
; DISABLE NUMPAD: REMOVE THE BEGINNING SEMI-COLONS ON THE NEXT 5 LINES TO DISABLE USE OF THE NUMPAD. DO NOT REMOVE ON THIS LINE
;keyToggleAutoAttack:="["   ;Hitting this key will enable primary auto-attack. Hit again to turn off.
;keyToggleAutoAlternateAttack:="]" ;Hitting this key will enable alternate auto-attack. Hit again to turn off.
;keyToggleChargedStaff:="\"       ;Toggle between charged versus non charged staff attacks (Apprentice)
;keyLowerStaffCharge:="-"   ; Lowers staff charge time.
;keyRaiseStaffCharge:="="   ; Raises staff charge time.




; ++++++++++++++++++++ CUSTOMIZE MOUSE CLICK SPAM RATE +++++++++++++++++
mainRangedDelay=20         ;Delay between main ranged attacks, in milliseconds, 10 is around the lower you should put
alternateRangedDelay=75    ;Delay between apprentice alternate 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:=true         ;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, On             ;Hotkey turned on at first to force player to choose a setup (F5,F6...)
Hotkey, % "*$" keyAlternateWeapon, AlternateWeapon, On  ;Hotkey turned on at first to force player to choose a setup (F5,F6...)
Hotkey, % keyApprentice, SetHeroApprentice
Hotkey, % keySquire, SetHeroSquire
Hotkey, % keyHuntress, SetHeroHuntress
Hotkey, % keyMonk, SetHeroMonk
Hotkey, % keyBarbarian, SetHeroBarbarian
Hotkey, % "*~" keyToggleChargedStaff, ToggleStaffAttack
Hotkey, % "*" keySelectChargeDuration, SetChargeDuration
Hotkey, % "*" KeySuspend, SuspendHotkeys
Hotkey, % keyLowerStaffCharge, lowerStaffCharge
Hotkey, % keyRaiseStaffCharge, raiseStaffCharge
Hotkey, % keyToggleAutoAttack, ToggleAutoAttack, "T2" ; allow 2 threads for this hotkey. so we can toggle with same key
Hotkey, % keyToggleAutoAlternateAttack, ToggleAutoAlternateAttack, "T2" ; allow 2 threads for this hotkey. so we can toggle with same key


;Initialization
bChargedStaff:=true
staffChargeDuration=149      ;Some initial value from the delayValues list
barbarianComboDelay:=100      ; Initial barbarian click delay between left and right clicks.
delayValues=50,100,149,250,500,750,1000,1250,1500,1750
characterType:=""
doToggleAutoAttack:=false
doToggleAutoAlternateAttack:=false
StringSplit, arrayDelays, delayValues, `,

;Status Variables
inAutoAttack:=false
inAutoAlternateAttack:=false

return   ; End of Auto-execute section

#Esc:: ;Win Esc
ExitApp
return






MainWeapon:
{
  if(characterType=""){
    Send {%keyUseWeapon%}
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack || doToggleAutoAlternateAttack){
    doToggleAutoAttack:=false
    doToggleAutoAlternateAttack:=false
    ; showToolTip("Primary or alternate auto-attack is on. Disable to use mouse attack")
    return
  }

   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.
   {
     ; 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)
     {
       showToolTip("Enabling mouse double click auto-attack")
       Send {%keyUseWeapon% Up}
       if(characterType="barbarian"){ ; barbarian allows a combo attack.
         While GetKeyState(keyUseWeapon, "P")
         {
           Send {%keyUseWeapon%}
           Sleep barbarianComboDelay
           Send {%keyAlternateWeapon%}
           Sleep barbarianComboDelay
         }
       }
          else ; apprentice
       {
         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
           }
         } ; end while

       } ; end apprentice else

     }
     else    ;Enter in single shot 'charge up' attack mode (mainly for the apprentice staff charge attacks)
     {
       keywait, %keyUseWeapon%, u
       Send {%keyUseWeapon% Up}
     }
   }
   else   ;There was no 'press-n-hold', finish sending a regular mouse click
   {
     Send {%keyUseWeapon% Up}
   }

   return
}


; Only use for apprentice
AlternateWeapon:
{
  if(characterType=""){
    Send {%keyAlternateWeapon%}
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack || doToggleAutoAlternateAttack){
    doToggleAutoAttack:=false
    doToggleAutoAlternateAttack:=false
    ; showToolTip("Primary or alternate auto-attack is on. Disable to use mouse attack")
    return
  }

  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% Down}
      Sleep staffChargeDuration
      Send {%keyAlternateWeapon% Up}
      Sleep alternateRangedDelay
    }
  }
  else   ;There was no 'press-n-hold', finish sending a regular mouse click
  {
    Send {%keyAlternateWeapon% Up}
  }

  return
}


ToggleAutoAttack:
{
  if(characterType=""){
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack = true){
    showToolTip("Disabling auto-attack")
    doToggleAutoAttack:=false
    return
  }

  inAutoAttack:=true

  if(doToggleAutoAlternateAttack=true){ ; disable the alternate attack if it is already going
    doToggleAutoAlternateAttack:= false
    return
  }

  ; Was going to attempt to streamline script with these, but didn't see much improvement.
  ;SetBatchLines -1
  ;SetMouseDelay, -1

  doToggleAutoAttack:=true
  showToolTip("Enabling auto-attack")

  if (characterType = "apprentice")
  {
    Send {%keyUseWeapon%}
    Sleep initialRapidfireDelay      ;Delay to prevent auto-attack firing mode from kicking in too fast

    While doToggleAutoAttack
    {
      ;Are we doing charged staff attacks?
      if(bChargedStaff = true)
      {
        Send {%keyUseWeapon% Down}
        Sleep staffChargeDuration
        Send {%keyUseWeapon% Up}
      }
      else   ;We are doing non charged staff attacks
      {
        Send {%keyUseWeapon%}
      }
      Sleep mainRangedDelay
    }
  }
  else   ;We monitor only single clicks for this hero, this is mainly for melee attacks
  {
    ;Enter in auto-attack mode
    if(characterType="barbarian"){ ; barbarian allows a combo attack.
      While doToggleAutoAttack
      {
        Send {%keyUseWeapon%}
        Sleep barbarianComboDelay
        Send {%keyAlternateWeapon%}
        Sleep barbarianComboDelay
      }
    }
    else
    {
      Send {%keyUseWeapon% Down}
      While doToggleAutoAttack
      {
        Sleep 50
        if(!GetKeyState(keyUseWeapon) ){ ; User probably clicked primary mouse button. Disable attack.
          doToggleAutoAttack:=false
          break
        }
      }
      Send {%keyUseWeapon% Up}
    }
  }

  inAutoAttack:=false
  showToolTip("Primary auto-attack disabled")

  ; The alternate auto-attack hotkey disabled us and exited. Running the alternate routine again to continue.
  ; We want to do this in a separate thread, so that it doesn't count against our threads per hotkey.
  if(inAutoAlternateAttack){
    SetTimer, ToggleAutoAlternateAttack, -1000 ; negative value to run once. [v1.0.46.16+]
  }

  return
}





ToggleAutoAlternateAttack:
{
  if(characterType=""){
    displayHelp("Need to select a class.")
    return
  }

  if(characterType="huntress"){
    showToolTip("Huntress does not need auto alternate attack")
    return
  }

  if(doToggleAutoAlternateAttack = true){
    showToolTip("Disabling alternate auto-attack")
    doToggleAutoAlternateAttack:=false
    return
  }

  inAutoAlternateAttack:=true

  if(doToggleAutoAttack){ ; disable primary auto-attack if it is going
    doToggleAutoAttack:= false
    return
  }

  doToggleAutoAlternateAttack:= true

  if( characterType = "apprentice" ){
    showToolTip("Enabling apprentice alternate auto-attack")
    While doToggleAutoAlternateAttack
    {
      Send {%keyAlternateWeapon% Down}
      Sleep staffChargeDuration
      Send {%keyAlternateWeapon% Up}
      Sleep alternateRangedDelay
    }
  }else{
    showToolTip("Enabling alternate auto-attack")
    Send {%keyAlternateWeapon% Down}
    While doToggleAutoAlternateAttack
    {
      Sleep 50
      if(!GetKeyState(keyAlternateWeapon) ){ ; User probably clicked alternate mouse button. Disable attack.
        doToggleAutoAlternateAttack:=false
        break
      }
    }
    Send {%keyAlternateWeapon% Up}
  }

  inAutoAlternateAttack:=false
  showToolTip("Alternate auto-attack disabled")

  ; The primary auto-attack hotkey disabled us and exited. Running the primary routine again to continue.
  ; We want to do this in a separate thread, so that it doesn't count against our threads per hotkey.
  if(inAutoAttack){
    SetTimer, ToggleAutoAttack, -1000 ; negative value to run once. [v1.0.46.16+]
  }

  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:
{
  if(bChargedStaff){
    showToolTip("Disabling charged staff")
  }else{
    showToolTip("Enabling charged staff")
  }
  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

        if(characterType="barbarian"){
          showToolTip( "New barbarian combo delay is " .  arrayDelays%UserInput% . " ms")
          barbarianComboDelay = % arrayDelays%UserInput%
          return
        }

     showToolTip( "New staff charge duration is " .  arrayDelays%UserInput% . " ms")
     staffChargeDuration = % arrayDelays%UserInput%
  }
  return
}

lowerStaffCharge:
{
  if(characterType="barbarian"){
    barbarianComboDelay:= barbarianComboDelay - 1
    if(barbarianComboDelay < 20){
      barbarianComboDelay:= 20
    }
    showToolTip("New barbarian combo delay is " . barbarianComboDelay . " ms")
    return
  }

  staffChargeDuration:= staffChargeDuration - 1
  if(staffChargeDuration < 20){
    staffChargeDuration:= 20
  }
  showToolTip("New staff charge duration is " . staffChargeDuration . " ms")
  return
}

raiseStaffCharge:
{
  if(characterType="barbarian"){
    barbarianComboDelay:= barbarianComboDelay + 1
    if(barbarianComboDelay > 10000){
      barbarianComboDelay:= 10000
    }
    showToolTip("New barbarian combo delay is " . barbarianComboDelay . " ms")
    return
  }

  staffChargeDuration:= staffChargeDuration + 1
  if(staffChargeDuration > 10000){
    staffChargeDuration:= 10000
  }
  showToolTip("New staff charge duration is " . staffChargeDuration . " ms")
  return
}


SetHeroApprentice:
{
  characterType:="apprentice"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, On
  Hotkey, % "*$" keyAlternateWeapon, On
  return
}

SetHeroSquire:
{
  characterType:="squire"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroHuntress:
{
  characterType:="huntress"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroMonk:
{
  characterType:="monk"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroBarbarian:
{
  characterType:="barbarian"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, On
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}


showToolTip(text, time=3000){
  ToolTip % text, 20, 50
  SetTimer, RemoveToolTip, % time
  return
}

RemoveToolTip:
{
  SetTimer, RemoveToolTip, Off
  ToolTip
  return
}

displayHelp(errorText=""){
  showToolTip( (errorText = "" ? "" : errorText . "`n" ) . "Need to select a class first. F5: Apprentice/Adept, F6: Squire/Countess, F7: Huntress/Ranger, F8:Monk/Initiate, F9:Barbarian")
  return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2012, 8:57 am 
Offline

Joined: February 1st, 2012, 10:55 pm
Posts: 4
Version 1.9: 2012/02/16
*) Change barbarian to use built-in combo auto-attack.
*) Change window title detection to require exactly Dungeon Defenders in window title. This allows other windows to have Dungeon Defenders in the title and not trigger shortcuts. (For example when browsing a website.) If you find this script not working in the future, search for IfWinActive below and update the 'Dungeon Defenders' text with the new window title.

Code:
; Title: Dungeon Defenders Rapid Fire
; AutoHotkey Version Tested: AutoHotkey Basic and AutoHotkey_L Unicode 64 bits
; Language:       English
; Platform:       WINDOWS
; Original based on:
; Author:         doppleganger
; Version 1.5 Minor Adjustments, Script Suspend functionality added.

; Version 1.6: 2012/02/01 - Lots of changes.
; Author: Ordanos
; *) Toggling charged staff is now done with Numpad *.
; *) Suspend script right shift key now defaults to being a toggle. (Holding down keys is a pain.)
; *) Numpad is used by default for new features. This should stop problems with hotkeys and chat.
;    If you don't have a numpad or don't want to use it, see "DISABLE NUMPAD" in the
;    CUSTOMIZE YOUR KEYBINDINGS section below.
; *) Can now toggle primary auto-attack via a keyboard key. Hit Numlock / to enable.
;    Hit it again to disable. This means you don't have to hold down the mouse or keys!
; *) Can now toggle alternate auto-attack via a keyboard key. Hit Numlock Enter to enable.
;    Hit it again to disable. This means you don't have to hold down the mouse or keys!
; *) You can decrease and increase your staff charge time easily with Numpad - and +.
; *) More user friendly. Many features now give you notifications in the top left to
;    let you know what is going on. Help is also displayed if you have not selected a class.
; *) Alternate auto-attack on apprentice keeps firing and does a charge up.
; *) Alternate auto-attack on squire just keeps his sword in block position.
; *) Use built in auto-attack now if a class has one.

; Version 1.7: 2012/02/02 - Add Barbarian. (F9 key)
; Author: Ordanos
; *) Do barbarian combo attack as primary auto-attack.
; *) You can decrease or increase the delay between left and right click by using the staff charge
;    keys while you have the barbarian class selected. (Default is Numpad -/+ or right alt and a number.)

; Version 1.8: 2012/02/11
; Author: Ordanos
; *) Disable toggleable auto-attack when primary/alternate fire pressed.
; *) Add Windows-Escape hotkey to exit script.

; Version 1.9: 2012/02/16
; Author: Ordanos
; *) Change barbarian to use built-in combo auto-attack.
; *) Change window title detection to require exactly Dungeon Defenders in window title. This allows
;    other windows to have Dungeon Defenders in the title and not trigger shortcuts. (For example when
;    browsing a website.) If you find this script not working in the future, search for IfWinActive below
;    and update the 'Dungeon Defenders' text with the new window title.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.

SetTitleMatchMode, 3


; ++++++++++++++++++++ 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
keyBarbarian:="F9"                 ;Activate auto-attack settings for Barbarian
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)

keyToggleAutoAttack:="NumpadDiv"   ;Hitting this key will enable primary auto-attack. Hit again to turn off.
keyToggleAutoAlternateAttack:="NumpadEnter" ;Hitting this key will enable alternate auto-attack. Hit again to turn off.
keyToggleChargedStaff:="NumpadMult"       ;Toggle between charged versus non charged staff attacks (Apprentice)
keyLowerStaffCharge:="NumpadSub"   ; Lowers staff charge time.
keyRaiseStaffCharge:="NumpadAdd"   ; Raises staff charge time.
; DISABLE NUMPAD: REMOVE THE BEGINNING SEMI-COLONS ON THE NEXT 5 LINES TO DISABLE USE OF THE NUMPAD. DO NOT REMOVE ON THIS LINE
;keyToggleAutoAttack:="["   ;Hitting this key will enable primary auto-attack. Hit again to turn off.
;keyToggleAutoAlternateAttack:="]" ;Hitting this key will enable alternate auto-attack. Hit again to turn off.
;keyToggleChargedStaff:="\"       ;Toggle between charged versus non charged staff attacks (Apprentice)
;keyLowerStaffCharge:="-"   ; Lowers staff charge time.
;keyRaiseStaffCharge:="="   ; Raises staff charge time.




; ++++++++++++++++++++ CUSTOMIZE MOUSE CLICK SPAM RATE +++++++++++++++++
mainRangedDelay=20         ;Delay between main ranged attacks, in milliseconds, 10 is around the lower you should put
alternateRangedDelay=75    ;Delay between apprentice alternate 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:=true         ;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, On             ;Hotkey turned on at first to force player to choose a setup (F5,F6...)
Hotkey, % "*$" keyAlternateWeapon, AlternateWeapon, On  ;Hotkey turned on at first to force player to choose a setup (F5,F6...)
Hotkey, % keyApprentice, SetHeroApprentice
Hotkey, % keySquire, SetHeroSquire
Hotkey, % keyHuntress, SetHeroHuntress
Hotkey, % keyMonk, SetHeroMonk
Hotkey, % keyBarbarian, SetHeroBarbarian
Hotkey, % "*~" keyToggleChargedStaff, ToggleStaffAttack
Hotkey, % "*" keySelectChargeDuration, SetChargeDuration
Hotkey, % "*" KeySuspend, SuspendHotkeys
Hotkey, % keyLowerStaffCharge, lowerStaffCharge
Hotkey, % keyRaiseStaffCharge, raiseStaffCharge
Hotkey, % keyToggleAutoAttack, ToggleAutoAttack, "T2" ; allow 2 threads for this hotkey. so we can toggle with same key
Hotkey, % keyToggleAutoAlternateAttack, ToggleAutoAlternateAttack, "T2" ; allow 2 threads for this hotkey. so we can toggle with same key


;Initialization
bChargedStaff:=true
staffChargeDuration=90      ;Some initial value from the delayValues list
delayValues=50,100,149,250,500,750,1000,1250,1500,1750
characterType:=""
doToggleAutoAttack:=false
doToggleAutoAlternateAttack:=false
StringSplit, arrayDelays, delayValues, `,

;Status Variables
inAutoAttack:=false
inAutoAlternateAttack:=false

return   ; End of Auto-execute section

#Esc:: ;Win Esc
ExitApp
return





MainWeapon:
{
  if(characterType=""){
    Send {%keyUseWeapon%}
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack || doToggleAutoAlternateAttack){
    doToggleAutoAttack:=false
    doToggleAutoAlternateAttack:=false
    ; showToolTip("Primary or alternate auto-attack is on. Disable to use mouse attack")
    return
  }

   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.
   {
     ; 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)
     {
       showToolTip("Enabling mouse double click auto-attack")
       Send {%keyUseWeapon% Up}
       if(characterType="barbarian"){ ; barbarian allows a combo attack.
         Send {%keyUseWeapon% Down}
         Send {%keyAlternateWeapon% Down}
         While GetKeyState(keyUseWeapon, "P")
         {
           Sleep 100
         }
         Send {%keyUseWeapon% Up}
         Send {%keyAlternateWeapon% Up}
       }
       else ; apprentice
       {
         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
           }
         } ; end while

       } ; end apprentice else

     }
     else    ;Enter in single shot 'charge up' attack mode (mainly for the apprentice staff charge attacks)
     {
       keywait, %keyUseWeapon%, u
       Send {%keyUseWeapon% Up}
     }
   }
   else   ;There was no 'press-n-hold', finish sending a regular mouse click
   {
     Send {%keyUseWeapon% Up}
   }

   return
}


; Only use for apprentice
AlternateWeapon:
{
  if(characterType=""){
    Send {%keyAlternateWeapon%}
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack || doToggleAutoAlternateAttack){
    doToggleAutoAttack:=false
    doToggleAutoAlternateAttack:=false
    ; showToolTip("Primary or alternate auto-attack is on. Disable to use mouse attack")
    return
  }

  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% Down}
      Sleep staffChargeDuration
      Send {%keyAlternateWeapon% Up}
      Sleep alternateRangedDelay
    }
  }
  else   ;There was no 'press-n-hold', finish sending a regular mouse click
  {
    Send {%keyAlternateWeapon% Up}
  }

  return
}


ToggleAutoAttack:
{
  if(characterType=""){
    displayHelp("Need to select a class.")
    return
  }

  if(doToggleAutoAttack = true){
    showToolTip("Disabling auto-attack")
    doToggleAutoAttack:=false
    return
  }

  inAutoAttack:=true

  if(doToggleAutoAlternateAttack=true){ ; disable the alternate attack if it is already going
    doToggleAutoAlternateAttack:= false
    return
  }

  ; Was going to attempt to streamline script with these, but didn't see much improvement.
  ;SetBatchLines -1
  ;SetMouseDelay, -1

  doToggleAutoAttack:=true
  showToolTip("Enabling auto-attack")

  if (characterType = "apprentice")
  {
    Send {%keyUseWeapon%}
    Sleep initialRapidfireDelay      ;Delay to prevent auto-attack firing mode from kicking in too fast

    While doToggleAutoAttack
    {
      ;Are we doing charged staff attacks?
      if(bChargedStaff = true)
      {
        Send {%keyUseWeapon% Down}
        Sleep staffChargeDuration
        Send {%keyUseWeapon% Up}
      }
      else   ;We are doing non charged staff attacks
      {
        Send {%keyUseWeapon%}
      }
      Sleep mainRangedDelay
    }
  }
  else   ;We monitor only single clicks for this hero, this is mainly for melee attacks
  {
    Send {%keyUseWeapon% Down}
    if(characterType="barbarian"){ ; barbarian allows a combo attack.
      Send {%keyAlternateWeapon% Down}
    }

    While doToggleAutoAttack
    {
      Sleep 50
      if(!GetKeyState(keyUseWeapon) ){ ; User probably clicked primary mouse button. Disable attack.
        doToggleAutoAttack:=false
        break
      }
    }

    Send {%keyUseWeapon% Up}
    if(characterType="barbarian"){ ; barbarian allows a combo attack.
      Send {%keyAlternateWeapon% Up}
    }

  }

  inAutoAttack:=false
  showToolTip("Primary auto-attack disabled")

  ; The alternate auto-attack hotkey disabled us and exited. Running the alternate routine again to continue.
  ; We want to do this in a separate thread, so that it doesn't count against our threads per hotkey.
  if(inAutoAlternateAttack){
    SetTimer, ToggleAutoAlternateAttack, -1000 ; negative value to run once. [v1.0.46.16+]
  }

  return
}





ToggleAutoAlternateAttack:
{
  if(characterType=""){
    displayHelp("Need to select a class.")
    return
  }

  if(characterType="huntress"){
    showToolTip("Huntress does not need auto alternate attack")
    return
  }

  if(doToggleAutoAlternateAttack = true){
    showToolTip("Disabling alternate auto-attack")
    doToggleAutoAlternateAttack:=false
    return
  }

  inAutoAlternateAttack:=true

  if(doToggleAutoAttack){ ; disable primary auto-attack if it is going
    doToggleAutoAttack:= false
    return
  }

  doToggleAutoAlternateAttack:= true

  if( characterType = "apprentice" ){
    showToolTip("Enabling apprentice alternate auto-attack")
    While doToggleAutoAlternateAttack
    {
      Send {%keyAlternateWeapon% Down}
      Sleep staffChargeDuration
      Send {%keyAlternateWeapon% Up}
      Sleep alternateRangedDelay
    }
  }else{
    showToolTip("Enabling alternate auto-attack")
    Send {%keyAlternateWeapon% Down}
    While doToggleAutoAlternateAttack
    {
      Sleep 50
      if(!GetKeyState(keyAlternateWeapon) ){ ; User probably clicked alternate mouse button. Disable attack.
        doToggleAutoAlternateAttack:=false
        break
      }
    }
    Send {%keyAlternateWeapon% Up}
  }

  inAutoAlternateAttack:=false
  showToolTip("Alternate auto-attack disabled")

  ; The primary auto-attack hotkey disabled us and exited. Running the primary routine again to continue.
  ; We want to do this in a separate thread, so that it doesn't count against our threads per hotkey.
  if(inAutoAttack){
    SetTimer, ToggleAutoAttack, -1000 ; negative value to run once. [v1.0.46.16+]
  }

  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:
{
  if(bChargedStaff){
    showToolTip("Disabling charged staff")
  }else{
    showToolTip("Enabling charged staff")
  }
  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

     showToolTip( "New staff charge duration is " .  arrayDelays%UserInput% . " ms")
     staffChargeDuration = % arrayDelays%UserInput%
  }
  return
}

lowerStaffCharge:
{
  staffChargeDuration:= staffChargeDuration - 1
  if(staffChargeDuration < 20){
    staffChargeDuration:= 20
  }
  showToolTip("New staff charge duration is " . staffChargeDuration . " ms")
  return
}

raiseStaffCharge:
{
  staffChargeDuration:= staffChargeDuration + 1
  if(staffChargeDuration > 10000){
    staffChargeDuration:= 10000
  }
  showToolTip("New staff charge duration is " . staffChargeDuration . " ms")
  return
}


SetHeroApprentice:
{
  characterType:="apprentice"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, On
  Hotkey, % "*$" keyAlternateWeapon, On
  return
}

SetHeroSquire:
{
  characterType:="squire"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroHuntress:
{
  characterType:="huntress"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroMonk:
{
  characterType:="monk"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, Off
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}

SetHeroBarbarian:
{
  characterType:="barbarian"
  showToolTip("Selecting " . characterType)
  Hotkey, % "*$" keyUseWeapon, On
  Hotkey, % "*$" keyAlternateWeapon, Off
  return
}


showToolTip(text, time=3000){
  ToolTip % text, 20, 50
  SetTimer, RemoveToolTip, % time
  return
}

RemoveToolTip:
{
  SetTimer, RemoveToolTip, Off
  ToolTip
  return
}

displayHelp(errorText=""){
  showToolTip( (errorText = "" ? "" : errorText . "`n" ) . "Need to select a class first. F5: Apprentice/Adept, F6: Squire/Countess, F7: Huntress/Ranger, F8:Monk/Initiate, F9:Barbarian")
  return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2012, 12:39 pm 
judas wrote:
How do u do this on xbox360 controller on pc?


http://www.electracode.com/4/joy2key/Jo ... ersion.htm


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, sks and 21 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