independent multiple timers

Ask gaming related questions (AHK v1.1 and older)
veladorn
Posts: 9
Joined: 27 Oct 2018, 12:58

independent multiple timers

09 Dec 2018, 15:09

Hey, I'm trying to make a merged script running three (or maybe more then) automatized actions. Currently I encounter a problem that running this vesion, I only get launched the last one timer, there is nothing happening if requirements for A and B occur. Could someone explain what I've missed?

Code: Select all

`::
Pause

SetTimer, A
SetTimer, B
SetTimer, C
return

A:
CoordMode, Pixel
PixelSearch, Px, Py, 1645, 850, 1700, 900, #2F3C4C, 0, Fast
If (Errorlevel = 0)
send {D}
Random, randA, 20, 100
Sleep %randA%
return

B:
Coordmode, Pixel
PixelSearch, Px, Py, 1800, 1000, 1800, 1000, 0x0E2D64, 0, RGB
If (Errorlevel = 1)
Send {5}
Random, randB, 3000, 4000
Sleep %randB%
return

C:
Send, {space}
Random, randC, 12500, 15000
Sleep %randC%
return
Last edited by veladorn on 09 Dec 2018, 16:37, edited 1 time in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: indepented multiple timers

09 Dec 2018, 15:28

#2F3C4C invalid color ID
veladorn
Posts: 9
Joined: 27 Oct 2018, 12:58

Re: indepented multiple timers

09 Dec 2018, 15:57

It's not the matter, running individual script works fine with hex color, there is something wrong with combination :(
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: indepented multiple timers

09 Dec 2018, 16:54

:facepalm:
https://autohotkey.com/docs/commands/PixelSearch.htm#Parameters wrote:The decimal or hexadecimal color ID to search for, in Blue-Green-Red (BGR) format, which can be an expression. Color IDs can be determined using Window Spy (accessible from the tray menu) or via PixelGetColor. For example: 0x9d6346
does #2F3C4C look like a hexadecimal number to you? i see a string
veladorn
Posts: 9
Joined: 27 Oct 2018, 12:58

Re: independent multiple timers

09 Dec 2018, 17:06

Code: Select all

`::
Pause

SetTimer, A
SetTimer, B
SetTimer, C
return

A:
CoordMode, Pixel
PixelSearch, Px, Py, 1645, 850, 1700, 900, 0x2F3C4C, 0, Fast
If (Errorlevel = 0)
send {D}
Random, randA, 20, 100
Sleep %randA%
return

B:
Coordmode, Pixel
PixelSearch, Px, Py, 1800, 1000, 1800, 1000, 0x0E2D64, 0, RGB
If (Errorlevel = 1)
Send {5}
Random, randB, 3000, 4000
Sleep %randB%
return

C:
Send, {space}
Random, randC, 12500, 15000
Sleep %randC%
return
I've changed the code as you suggest, but there is still the same problem as I described in my first post.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: independent multiple timers

09 Dec 2018, 22:45

long sleeps in timers mess up their interruptibility, try this instead:

Code: Select all

CoordMode, Pixel
SetTimer, A, -1
SetTimer, B, -1
SetTimer, C, -1

`::Pause

A:
	PixelSearch, Px, Py, 1645, 850, 1700, 900, 0x2F3C4C, 0, Fast
	If (Errorlevel = 0)
		send {D}

	restartAfter(20, 100)
return

B:
	PixelSearch, Px, Py, 1800, 1000, 1800, 1000, 0x0E2D64, 0, RGB
	If (Errorlevel = 1)
		Send {5}
 
	restartAfter(3000, 4000)
return

C:
	Send, {space}

	restartAfter(12500, 15000)
return

restartAfter(min, max) {
	Random rand, min, max
	SetTimer % A_ThisLabel, % -rand
}
veladorn
Posts: 9
Joined: 27 Oct 2018, 12:58

Re: independent multiple timers

10 Dec 2018, 11:42

Thanks, it works fine now. It'd be perfect if it had one more function. The thing is that the values in each timer's min-max are set just once upon launching of the script. wouldn't it be diffcult to make the values randomized after each timer's restart?


one more thing. I need to add one another pixel checking, but strangely I can't seem to get it work in the script.

First I'm checking the point to get the pixel color.

Code: Select all

CoordMode, Pixel
PixelGetColor, color, 16, 131, RGB
MsgBox %color%
Then i try to add the color from the MsgBox into the script:

Code: Select all

	PixelSearch, Px, Py, 0, 131, 500, 131, 0x6E050F, 3, fast
	if (Errorlevel = 0)
	Send {2}
	restartAfter(100, 500)
	return
position on y axis is constant, so i'm checking the range on x where is might appear, and somehow it doesn't work. the color certainly appears, but there is no action in the script. game is running directx11, could it be problematic?
veladorn
Posts: 9
Joined: 27 Oct 2018, 12:58

Re: independent multiple timers

11 Dec 2018, 06:09

Ok, sorry, my mistake. My first question is not up to date, the values ARE randomized the way i needed :bravo:
Still maybe it's a question for another topic, but I can't find out why the color could be not found by script, any ideas?:(
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: independent multiple timers

12 Dec 2018, 10:56

PixelSearch defaults to BGR mode. You are using RGB mode in PixelGetColor, so I guess you also want RGB mode in PixelSearch
PixelSearch, Px, Py, 0, 131, 500, 131, 0x6E050F, 3, fast RGB

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 69 guests