timer press key every xxx minutes inside loop?

Ask gaming related questions (AHK v1.1 and older)
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

timer press key every xxx minutes inside loop?

Post by ravena1 » 27 Jan 2022, 16:26

help please im trying to priority to press key(buff skill) every 3 minutes before proceding to main attack loop

something like this

Code: Select all

SetTimer, buff, 1800000


home::
Loop,
{
buff()
}


Buff(){
if(timer=180000) {     ;how do i check if buff timer reaches 3mins? to trigger this?
send 9   ;press buff skill key
return
} else {
attack()
return
}

;the rest of attack main script here bla bla DONT MIND it, still uncomplete
attack() {
send {alt down}
sleep, 50
send {0 down}
sleep, 50
send {0 up}
sleep, 50
send {alt up}
sleep, 100
Click, Down
sleep, 30
Click, Up
sleep, 1500
return
}

its giving me error T_T
Last edited by ravena1 on 28 Jan 2022, 03:34, edited 3 times in total.

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: timer press key every xxx minutes inside loop?

Post by mikeyww » 27 Jan 2022, 20:18

I would have a look at every line in your script, from top to bottom, to see what it does. Shorten your script while you are testing it. Timer and Loots are undefined. To set a timer, you can use SetTimer. Example

ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: timer press key every xxx minutes inside loop?

Post by ravena1 » 28 Jan 2022, 03:25

mikeyww wrote:
27 Jan 2022, 20:18
I would have a look at every line in your script, from top to bottom, to see what it does. Shorten your script while you are testing it. Timer and Loots are undefined. To set a timer, you can use SetTimer. Example
please dont mind the main script it is still uncomplete..
but all i want is to do first is check timer if it reach 3 minutes, its having me hard time to understand the setTimer function... can you make example how to do that thank you

ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: timer press key every xxx minutes inside loop?

Post by ravena1 » 28 Jan 2022, 03:31

ravena1 wrote:
28 Jan 2022, 03:25
mikeyww wrote:
27 Jan 2022, 20:18
I would have a look at every line in your script, from top to bottom, to see what it does. Shorten your script while you are testing it. Timer and Loots are undefined. To set a timer, you can use SetTimer. Example
please dont mind the main script it is still uncomplete..
but all i want is to do first is check timer if it reach 3 minutes, its having me hard time to understand the setTimer function... can you make example how to do that thank you

Code: Select all

SetTimer, buff, 1800000


home::
Loop,
{
buff()
}


Buff(){
if(timer=180000) {       ; how do i check if buff timer reaches 3mins? to trigger this?
send 9 ;buff skill key
}  else {
attack()
return
}

;the rest of attack main script here bla bla DONT MIND it, still uncomplete
attack() {
       send {alt down}
        sleep, 50
        send {0 down}
        sleep, 50
        send {0 up}
        sleep, 50
        send {alt up} 
        sleep, 100
        Click, Down
        sleep, 30
        Click, Up
        sleep, 1500
        return
}
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: timer press key every xxx minutes inside loop?

Post by mikeyww » 28 Jan 2022, 07:27

An example is below. You don't need a function. You can use a simple labeled subroutine.

Code: Select all

Global start := A_TickCount

Home::
SoundBeep, 1500
Loop
{
 buff()
 Sleep, 200
}

buff() {
 If (A_TickCount - start < 2000)
  Return
 MsgBox, Done!
 ExitApp
}
Or:

Code: Select all

Global start

Home::
SoundBeep, 1500
start := A_TickCount
Loop
{
 buff()
 Sleep, 200
}

buff() {
 If (A_TickCount - start < 2000)
  Return
 MsgBox, Done!
 ExitApp
}
Or:

Code: Select all

Home::
start := A_TickCount
SetTimer, Buff, 150
SoundBeep, 1500
Return

Buff:
If (A_TickCount - start < 2000)
  Return
SetTimer,, Off
MsgBox, Done!
Return
Or:

Code: Select all

Home::
SetTimer, Buff, -2000
SoundBeep, 1500
Return

Buff:
MsgBox, Done!
Return

ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: timer press key every xxx minutes inside loop?

Post by ravena1 » 28 Jan 2022, 14:57

mikeyww wrote:
28 Jan 2022, 07:27
An example is below. You don't need a function. You can use a simple labeled subroutine.

Code: Select all

Global start := A_TickCount

Home::
SoundBeep, 1500
Loop
{
 buff()
 Sleep, 200
}

buff() {
 If (A_TickCount - start < 2000)
  Return
 MsgBox, Done!
 ExitApp
}
Or:

Code: Select all

Global start

Home::
SoundBeep, 1500
start := A_TickCount
Loop
{
 buff()
 Sleep, 200
}

buff() {
 If (A_TickCount - start < 2000)
  Return
 MsgBox, Done!
 ExitApp
}
Or:

Code: Select all

Home::
start := A_TickCount
SetTimer, Buff, 150
SoundBeep, 1500
Return

Buff:
If (A_TickCount - start < 2000)
  Return
SetTimer,, Off
MsgBox, Done!
Return
Or:

Code: Select all

Home::
SetTimer, Buff, -2000
SoundBeep, 1500
Return

Buff:
MsgBox, Done!
Return
im not sure how to explain it
but its like this

my character do attacking monster routine

oh wait my buffs is gone after 3 minutes, i have to STOP ATTACKING and use BUFF now

Code: Select all

Global start

Home::
start := A_TickCount
Loop
{
 buff()
 Sleep, 200
}

buff() {
 If (A_TickCount - start < 180000)  ;-- 3mins(?)
    send 9 ;-- buff skill
    sleep, 500
}
  else  {
    attack()
  }
}


attack()
    ImageSearch, Attackx, AttackY, 353, 215, 716, 523, attack.png
     if(ErrorLevel) {
        Loot()
    } else if(!ErrorLevel) { 

        MouseMove, %NAttackX%, %AttackY%
        sleep, 100
        Click, Down
        sleep, 30
        Click, Up
        return
    } else {
        sleep, 30
        return
    }
}


Loot()
    ImageSearch, Lootx, LootY, 353, 215, 716, 523, loot.png
     if(ErrorLevel) {
        return
    } else if(!ErrorLevel) { 

        MouseMove, %LootX%, %LootY%
        sleep, 100
        Click, Down
        sleep, 30
        Click, Up
        return
    } else {
        sleep, 30
        return
    }
}


do you have a better idea how to execute my script? thank you so much
Last edited by ravena1 on 28 Jan 2022, 15:08, edited 1 time in total.

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: timer press key every xxx minutes inside loop?

Post by mikeyww » 28 Jan 2022, 15:03

I thought that I provided all possible examples, but if none of them work, then I am out of ideas. Others may have additional suggestions for you.

Setting a timer does not actually define a variable called "timer", but my last example shows how to execute a labeled subroutine when a timer expires.

ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: timer press key every xxx minutes inside loop?

Post by ravena1 » 28 Jan 2022, 15:10

mikeyww wrote:
28 Jan 2022, 15:03
I thought that I provided all possible examples, but if none of them work, then I am out of ideas. Others may have additional suggestions for you.

Setting a timer does not actually define a variable called "timer", but my last example shows how to execute a labeled subroutine when a timer expires.
i edited my code, can you check it? thank you

Code: Select all

Global start

Home::
start := A_TickCount
Loop
{
 buff()
 Sleep, 200
}

buff() {
 If (A_TickCount - start < 180000)  ;-- 3mins(?)
    send 9 ;-- buff skill
    sleep, 500
    start := 0      ;-- will this gonna reset the timer? im not sure
}
  else  {
    attack()
  }
}


attack()
    ImageSearch, Attackx, AttackY, 353, 215, 716, 523, attack.png
     if(ErrorLevel) {
        Loot()
    } else if(!ErrorLevel) { 

        MouseMove, %NAttackX%, %AttackY%
        sleep, 100
        Click, Down
        sleep, 30
        Click, Up
        return
    } else {
        sleep, 30
        return
    }
}


Loot()
    ImageSearch, Lootx, LootY, 353, 215, 716, 523, loot.png
     if(ErrorLevel) {
        return
    } else if(!ErrorLevel) { 

        MouseMove, %LootX%, %LootY%
        sleep, 100
        Click, Down
        sleep, 30
        Click, Up
        return
    } else {
        sleep, 30
        return
    }
}

ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: timer press key every xxx minutes inside loop?

Post by ravena1 » 28 Jan 2022, 17:31

mikeyww wrote:
28 Jan 2022, 15:03
I thought that I provided all possible examples, but if none of them work, then I am out of ideas. Others may have additional suggestions for you.

Setting a timer does not actually define a variable called "timer", but my last example shows how to execute a labeled subroutine when a timer expires.
this probably wont work
i think i might create 2 script instead
buff.ahk
attack.ahk

then pause attack.ahk everytime i buff
do you think this will work??

Code: Select all

PostMessage, 0x0111, 65306,,, attack.ahk - AutoHotkey  ; Pause.
buff.ahk

Code: Select all

ins::
  sleep, 180000 ;- 3mins
  send 9
  sleep, 500
  PostMessage, 0x0111, 65306,,, attack.ahk - AutoHotkey  ; Pause.

attack.ahk

Code: Select all

 home:: 
Loop
{
 attack()
 Sleep, 200
}


   attack()
    ImageSearch, Attackx, AttackY, 353, 215, 716, 523, attack.png
     if(ErrorLevel) {
        Loot()
    } else if(!ErrorLevel) { 
        MouseMove, %AttackX%, %AttackY%
        sleep, 100
        Click, Down
        sleep, 30
        Click, Up
        return
    } else {
        sleep, 30
        return
    }
}


Loot()
    ImageSearch, Lootx, LootY, 353, 215, 716, 523, loot.png
     if(ErrorLevel) {
        return
    } else if(!ErrorLevel) { 
        MouseMove, %LootX%, %LootY%
        sleep, 100
        Click, Down
        sleep, 30
        Click, Up
        return
    } else {
        sleep, 30
        return
    }
Last edited by ravena1 on 29 Jan 2022, 03:58, edited 1 time in total.

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: timer press key every xxx minutes inside loop?

Post by mikeyww » 28 Jan 2022, 19:06

I'd say that a single script can be readily made to meet your goal, but your goal is not clearly described yet. Your first description was, "I'm trying to priority to press key(buff skill) every 3 minutes before proceding to main attack loop". Your second description was, "check timer if it reach 3 minutes". I do not understand either description. To describe your goal, I would use a series of short, numbered steps. Each item should be a single check, action, event, etc. That might help. If you want to check something every three minutes, then when does that stop? What does it mean to "press key(buff skill)"? What is "Check timer?" Generally speaking, a timer has a start and an end, so there is nothing to check while it is running. In summary, your current descriptions are too vague for me to follow.

ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

Re: timer press key every xxx minutes inside loop?

Post by ravena1 » 29 Jan 2022, 03:53

mikeyww wrote:
28 Jan 2022, 19:06
I'd say that a single script can be readily made to meet your goal, but your goal is not clearly described yet. Your first description was, "I'm trying to priority to press key(buff skill) every 3 minutes before proceding to main attack loop". Your second description was, "check timer if it reach 3 minutes". I do not understand either description. To describe your goal, I would use a series of short, numbered steps. Each item should be a single check, action, event, etc. That might help. If you want to check something every three minutes, then when does that stop? What does it mean to "press key(buff skill)"? What is "Check timer?" Generally speaking, a timer has a start and an end, so there is nothing to check while it is running. In summary, your current descriptions are too vague for me to follow.
i guess you dont really play mmorpg, buffing is very important before you attack monsters.

i wish someone who play mmorpg can understand it. anyone?

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: timer press key every xxx minutes inside loop?

Post by mikeyww » 29 Jan 2022, 06:55

No answers! You're right. I will leave this one to the gaming pros. :)

sai05
Posts: 5
Joined: 19 Jan 2020, 11:26

Re: timer press key every xxx minutes inside loop?

Post by sai05 » 31 Jan 2022, 15:33

mikeyww wrote:
29 Jan 2022, 06:55
No answers! You're right. I will leave this one to the gaming pros. :)

im new in autohotkey but i can share some.logic

why not use imagesearch

Search image in spesific area if 1 do ski buff if 0 Do Do attack
because im not see any macro can pause time to check buff
except you make auto buff every time nefor attack

Post Reply

Return to “Gaming Help (v1)”