How to improve this script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fabio
Posts: 6
Joined: 22 Oct 2019, 09:24

How to improve this script?

22 Oct 2019, 09:34

Ok, I'm not a pro, I just got macro bits out there that resulted in this script. So far it runs well, but as I do not understand much of the subject I would like someone to help me improve it, make it cleaner. Thank you in advance.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Seq2T_TimerState := 0                       ;MUST be at the top of the script
#NoEnv
SendMode Input
#SingleInstance, Force
Process, WaitClose, grim dawn.exe
    ExitApp

global Toggle := false
return
	
UseSkill(key)
{
    ;IfWinActive, Grim Dawn
	{
		Send {%key%}
	}
}

; this key will start and stop the loop
~Shift::
	ToggleLoop(false)
return
	; restart loop
Numpad9::
	ToggleLoop(true)
return

;this function will toggle the loop, if the reset parameter is true we will restart the timers.
ToggleLoop(reset)
{
	Toggle := !Toggle || reset
	
	; list all the skills you have timers for here
	if(Toggle)
	{
		Gosub Ascenção
		Gosub ELA
		Gosub Anel
		Gosub Sombra
		Gosub Attack
		Gosub Veno
	}

	; enable or disable timers for all skills you want to loop
	SetTimer, Ascenção, % (Toggle) ? 11000 : "Off"  ;22 seg
	SetTimer, ELA, % (Toggle) ? 1800 : "Off" ;1.8  seg
	SetTimer, Anel, % (Toggle) ? 1500 : "Off"  ;3 seg
	SetTimer, Sombra, % (Toggle) ? 1750 : "Off"  ;3.5 seg
	SetTimer, Attack, % (Toggle) ? 200 : "Off"  ;.2 seg
	SetTimer, Veno, % (Toggle) ? 8000 : "Off"  ;16seg
}


; make a label for all skills here

Attack:
	UseSkill(1)
return

Ascenção:
	UseSkill(3)
return

ELA:
	UseSkill(5)
return

Anel:	
    	UseSkill(6)
return

Sombra:	
    	UseSkill(4)
return

Veno:	
    	UseSkill(7)
return



$RButton::                                  ;start the sequence
{
    Seq2T_count++
    if (Seq2T_count = 3) {                  ;n+1 actions in the sequence
        Seq2T_count := 1
    }
    if (Seq2T_TimerState = 1) {
        if (Seq2T_count = 1) {              ; = action#
            send 8                          ;1st action in the sequence
        }
        else if (Seq2T_count = 2) {         ; = action#
            send E                        ;2nd action in the sequence
        }
        return
    }
    else if (Seq2T_TimerState = 0) {
        send RButton                         ;1st action in the sequence
        SetTimer, Seq2T_Timer, 6000         ;reset timer duration in ms
        Seq2T_TimerState := 1
    }
    return
}
Seq2T_Timer:
{
    Seq2T_count := 0
    SetTimer, Seq2T_Timer, Delete
    Seq2T_TimerState := 0
    return
}
;--------------------------------------------------------
$2::                                        ;start the sequence
{
    Seq2T_count++
    if (Seq2T_count = 3) {                  ;n+1 actions in the sequence
        Seq2T_count := 1
    }
    if (Seq2T_TimerState = 1) {
        if (Seq2T_count = 1) {              ; = action#
            Send 2                     	    ;first action in the sequence
        }
        else if (Seq2T_count = 2) {         ; = action#
            Send 4                          ;second action in the sequence
        }
        return
    }
    else if (Seq2T_TimerState = 0) {
        Send 2                              ;first action in the sequence
        SetTimer, Seq2T_Timer, 6000         ;reset timer duration in ms
        Seq2T_TimerState := 1
    }
    return
}

;--------------------------------------------------------
NumpadEnter::
  Suspend
  Pause ,,1
  if A_IsPaused {
    ToolTip, PAUSADO, 1500, 1250
  } else {
    ToolTip, RUNNING, 1500, 1250
    SetTimer RemoveToolTip, 1000
  }
return


RemoveToolTip:
  ToolTip
  SetTimer, RemoveToolTip, Off
return
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: How to improve this script?

22 Oct 2019, 10:11

Could you provide a bit more info what you exactly want to achieve with the script?
Fabio
Posts: 6
Joined: 22 Oct 2019, 09:24

Re: How to improve this script?

22 Oct 2019, 23:15

Right, it works fine but I use two monitors and when I do activities on the monitor that is not the game the script stops and I lose the right mouse click. I also thought I could merge the sequence codes. Thanks.
Fabio
Posts: 6
Joined: 22 Oct 2019, 09:24

Re: How to improve this script?

24 Oct 2019, 06:06

I identified the problem. When I switch anothers windows and go back to the window game the key to un-suspend no longer works. Can someone help me?

Code: Select all

NumpadEnter::
  Suspend
  Pause ,,1
  if A_IsPaused {
    ToolTip, PAUSED, 1500, 1250
  } else {
    ToolTip, RUNNING, 1500, 1250
    SetTimer RemoveToolTip, 1000
  }
return


RemoveToolTip:
  ToolTip
  SetTimer, RemoveToolTip, Off
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 360 guests