loop-like script, but with individual cooldowns

Ask gaming related questions (AHK v1.1 and older)
kroki
Posts: 9
Joined: 17 Jan 2022, 04:31

loop-like script, but with individual cooldowns

Post by kroki » 17 Jan 2022, 04:39

I am trying to make a script that will on right mouse button hold:

press f, then a, then d, then finally q. id like to put individual cooldowns on f,a,d, so when i click right mouse button before cooldown on these keys passes, it will only press q

heres what i come up with (without cooldowns)

Code: Select all

~RButton::
#IfWinActive ahk_class Diablo II

While, GetKeyState("RButton","P")
{
send f 
sleep 200
send a
sleep 200
send d
sleep 200
send q
sleep 10000
}
any help would be greatly appreciated :D

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: loop-like script, but with individual cooldowns

Post by Rohwedder » 17 Jan 2022, 05:22

Hallo,
what does Cooldown of a key mean?
Should this key be held down for a certain period of time?

kroki
Posts: 9
Joined: 17 Jan 2022, 04:31

Re: loop-like script, but with individual cooldowns

Post by kroki » 17 Jan 2022, 05:28

Rohwedder wrote:
17 Jan 2022, 05:22
Hallo,
what does Cooldown of a key mean?
Should this key be held down for a certain period of time?
cooldown meaning that it wont be pressed again if i rapidly click right mouse button, before the cooldown ends, for example 10 seconds for each key other than q

kroki
Posts: 9
Joined: 17 Jan 2022, 04:31

Re: loop-like script, but with individual cooldowns

Post by kroki » 17 Jan 2022, 05:29

Rohwedder wrote:
17 Jan 2022, 05:22
Hallo,
what does Cooldown of a key mean?
Should this key be held down for a certain period of time?
to prevent key being pressed again when i hold down right mouse button. for example 10 second period for all keys other than Q

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: loop-like script, but with individual cooldowns

Post by Rohwedder » 17 Jan 2022, 08:29

Try:

Code: Select all

#If Cooldown
*f:: ;to prevent key being pressed again
*a:: ;when i hold down right mouse button
*d::Return
#IfWinActive ahk_class Diablo II
~RButton::
While, Cooldown := GetKeyState("RButton","P")
{
	send f
	sleep 200
	send a
	sleep 200
	send d
	sleep 200
	send q
	sleep 10000
}
Return

kroki
Posts: 9
Joined: 17 Jan 2022, 04:31

Re: loop-like script, but with individual cooldowns

Post by kroki » 17 Jan 2022, 08:36

hi, thanks for the reply. i dont understand how does this change anything though :(

ideally id want to press right mouse button, have ahk send keys: f,a,d with 200ms delay, then send q key. for f,a,d keys id like 10 seconds cooldown, so when i press right mouse button before 10 seconds run out, it only sends q

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: loop-like script, but with individual cooldowns

Post by Rohwedder » 17 Jan 2022, 10:45

Then perhaps?:

Code: Select all

#If Cooldown ;so when i press right mouse button
RButton::send q ; before 10 seconds run out,
; it only sends q
#IfWinActive ahk_class Notepad ;ahk_class Diablo II
RButton::
SoundBeep, 4000, 20
Cooldown := True ;Cooldown starts
send f
sleep 200
send a
sleep 200
send d
sleep 200
send q
sleep 10000
Cooldown := False ;Cooldown ends
SoundBeep, 1000, 20
Return
The soundbeeps are only for testing to indicate the beginning and end of the Cooldown.

kroki
Posts: 9
Joined: 17 Jan 2022, 04:31

Re: loop-like script, but with individual cooldowns

Post by kroki » 17 Jan 2022, 11:11

unfortunately this doesnt work as i imagined.

Code: Select all

~RButton::
#IfWinActive ahk_class Diablo II

While, GetKeyState("RButton","P")
{
send f 		;start a 9 second cooldown
sleep 200
send a		;start a 10 second cooldown
sleep 200
send d		;start a 11 second cooldown
sleep 200
send q
}
any idea how to make it work like this? how to add 3 separe cooldowns to these key presses? and itd have to work on right mouse button hold, not just click

kroki
Posts: 9
Joined: 17 Jan 2022, 04:31

Re: loop-like script, but with individual cooldowns

Post by kroki » 17 Jan 2022, 11:40

ok ive tried different approach and it works, just one minor thing to do. how to make it loop on itself, without need to release to right click button?

Code: Select all

~RButton::
#IfWinActive ahk_class Diablo II

While, GetKeyState("RButton","P")

  {  
    if (!t1 || A_TickCount-t1 > 60000) { 
        t1 := A_TickCount 
        SendInput a
        Sleep 250
        SendInput s
        Sleep 250
        SendInput d
        Sleep 250
        SendInput q
    } else

    if (!t2 || A_TickCount-t2 > 9000) { 
        t2 := A_TickCount 
        SendInput a 
        Sleep 200
        SendInput d
        Sleep 200
        SendInput q
    } else

    if (!t3 || A_TickCount-t3 > 5000) { 
        t3 := A_TickCount 
   
        SendInput q

    } else


;GetKeyState, state, w,
;    if State = U
;    break

return 
}  

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: loop-like script, but with individual cooldowns

Post by Xtra » 17 Jan 2022, 12:07

Give this a try:

Code: Select all

#IfWinActive ahk_class Diablo II
~RButton::
    While, GetKeyState("RButton","P") {
        if (A_Index = 1)
        {
            CDf := SendKey("f")
            CDa := SendKey("a")
            CDd := SendKey("d")   
        }
        else
        {
            if (A_TickCount - CDf >= 9000)
                CDf := SendKey("f")
            if (A_TickCount - CDa >= 10000)
                CDa := SendKey("a")
            if (A_TickCount - CDd >= 11000)
                CDd := SendKey("d")
        }
        SendKey("q", 0)
    }
return

SendKey(char, time := 200) {
    send, % char
    Sleep, time
    return A_TickCount
}
You should be able to tweak the timing if needed.

kroki
Posts: 9
Joined: 17 Jan 2022, 04:31

Re: loop-like script, but with individual cooldowns

Post by kroki » 18 Jan 2022, 04:30

Xtra wrote:
17 Jan 2022, 12:07
Give this a try:

Code: Select all

#IfWinActive ahk_class Diablo II
~RButton::
    While, GetKeyState("RButton","P") {
        if (A_Index = 1)
        {
            CDf := SendKey("f")
            CDa := SendKey("a")
            CDd := SendKey("d")   
        }
        else
        {
            if (A_TickCount - CDf >= 9000)
                CDf := SendKey("f")
            if (A_TickCount - CDa >= 10000)
                CDa := SendKey("a")
            if (A_TickCount - CDd >= 11000)
                CDd := SendKey("d")
        }
        SendKey("q", 0)
    }
return

SendKey(char, time := 200) {
    send, % char
    Sleep, time
    return A_TickCount
}
You should be able to tweak the timing if needed.
Works like a charm. Thank you everyone for replies :D

kroki
Posts: 9
Joined: 17 Jan 2022, 04:31

Re: loop-like script, but with individual cooldowns

Post by kroki » 18 Jan 2022, 05:40

Xtra wrote:
17 Jan 2022, 12:07
Give this a try:

Code: Select all

#IfWinActive ahk_class Diablo II
~RButton::
    While, GetKeyState("RButton","P") {
        if (A_Index = 1)
        {
            CDf := SendKey("f")
            CDa := SendKey("a")
            CDd := SendKey("d")   
        }
        else
        {
            if (A_TickCount - CDf >= 9000)
                CDf := SendKey("f")
            if (A_TickCount - CDa >= 10000)
                CDa := SendKey("a")
            if (A_TickCount - CDd >= 11000)
                CDd := SendKey("d")
        }
        SendKey("q", 0)
    }
return

SendKey(char, time := 200) {
    send, % char
    Sleep, time
    return A_TickCount
}
You should be able to tweak the timing if needed.
one more thing, would it be possible to put a cooldown on the whole sequence? currently it runs whole thing each time i do a right click. id like to put another 10 second cd on the whole thing, during which time hodling right click would only send q

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: loop-like script, but with individual cooldowns

Post by Xtra » 18 Jan 2022, 12:53

This will remember where the CD is at each time you right click.

Code: Select all

#IfWinActive ahk_class Diablo II
~RButton::
    While, GetKeyState("RButton","P") {
        if (!CDf || A_TickCount - CDf >= 9000)
            CDf := SendKey("f")
        if (!CDa || A_TickCount - CDa >= 10000)
            CDa := SendKey("a")
        if (!CDd || A_TickCount - CDd >= 11000)
            CDd := SendKey("d")
        SendKey("q", 0)
    }
return

SendKey(char, time := 200) {
    send, % char
    Sleep, time
    return A_TickCount
}

kroki
Posts: 9
Joined: 17 Jan 2022, 04:31

Re: loop-like script, but with individual cooldowns

Post by kroki » 18 Jan 2022, 13:02

works great, thanks!!

Post Reply

Return to “Gaming Help (v1)”