How to use 1 random SetTimer and 1 constant SetTimer

Ask gaming related questions (AHK v1.1 and older)
johnwick
Posts: 6
Joined: 22 Jan 2022, 21:15

How to use 1 random SetTimer and 1 constant SetTimer

Post by johnwick » 22 Jan 2022, 21:43

Hey. So I'm running a script where if I press a key (F6), it runs a script indefinitely for a game. This script would have 2 SetTimer functions. One of them is a constant - every 11.5min it presses down on a key (BUFF function). Another SetTimer is random - every x seconds between two values (LOOP section), it activates a function that presses another key. Here is the code I currently have (assume the programid lines work):

Code: Select all

F6:: 

SetTimer, buff, 690000

;CONSTANT SECTION
BUFF:
ControlSend,,{g}, ahk_id %programid1%
sleep 500
return

;INTENDED TO PRESS THE SPACEBAR ONCE AFTER A RANDOM AMOUNT OF TIME HAS ELAPSED. CHANGES EVERYTIME THE SPACEBAR IS PRESSED
Loop
{
Random,x,60000,120000
ControlSend,,{Space}, ahk_id %programid1%,,,, NA
Sleep x
}

The problem with the current code is that the BUFF function runs, but the loop section doesn't. I tried using the Random in-built AHK function, but the way I implement it, the Randomized number is always the same. I know you can change it everytime if you put it in a loop, but I don't know how to do it and my attempt failed. How would I go about doing it such that when I press the F6 key, every 11.5min the BUFF function is run and after a random amount of time the Spacebar is pressed (the loop section).

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

Re: How to use 1 random SetTimer and 1 constant SetTimer

Post by Rohwedder » 23 Jan 2022, 02:28

Hallo,
try:

Code: Select all

F6::
SetTimer, buff, 690000
sleep 500
Gosub, Rand

;CONSTANT SECTION
BUFF:
ControlSend,,{g}, ahk_id %programid1%
return
;INTENDED TO PRESS THE SPACEBAR ONCE AFTER A RANDOM AMOUNT OF TIME HAS ELAPSED. CHANGES EVERYTIME THE SPACEBAR IS PRESSED
Rand:
Random, Rand, 60000, 120000
SetTimer, Rand,% Rand
ControlSend,,{Space}, ahk_id %programid1%,,,, NA
Return

Post Reply

Return to “Gaming Help (v1)”