Speed up PixelSearch?

Ask gaming related questions (AHK v1.1 and older)
vanker
Posts: 9
Joined: 12 Oct 2017, 17:01

Speed up PixelSearch?

15 Oct 2017, 18:03

Basically what it does is detect a white pixel in a fixed radius, wait for that pixel to be some shade of red and press space when it does, here is some code, I'll explain below

Code: Select all

#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
#Persistent
#MaxThreadsPerHotkey 2
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input


plot(x1, y1, a, r, byref x2, byref y2) {    
rad := (a * 0.01745329252)
x2 := (x1 - sin(rad) * r)
y2 := (y1 + cos(rad) * r)
}


xMidScrn :=  A_ScreenWidth //2
yMidScrn :=  A_ScreenHeight //2
yMidScrn := yMidScrn - 2 


toggle := False
f1 UP::
toggle := !toggle
loop{
    If (!toggle) {
        break
    }
    coordmode mouse
    coordmode pixel
    setformat floatfast, 0
    arc := 5  , radius  := 53
    loop {
        If (!toggle) {
        break
    }
            plot(xMidScrn, yMidScrn, a_index * arc, radius, x2, y2)
            PixelSearch, oX, oY, x2, y2, x2, y2, 0xFFFFFF , 30 , Fast RGB

        if !ErrorLevel
          {

            ;mousemove oX, oY
            psX := oX
            psY := oY
            break
          }
    }


    loop
    {
    If (!toggle) {
        break
    }
        PixelSearch, oX1, oY1, psX, psY, psX, psY, 0xFF0000 , 70 , Fast RGB
        Sleep 100
    } until (!ErrorLevel) || (a_index = 50)
             Send {Space down}
                Sleep 30
             Send {Space up} 
}
return
Before you say that pixelgetcolor may be faster, it doesn't seem to work in my case and here is my theory, 1st of all here is the image Image, that small white block can spawn at any time at random location along this radius but that white block have different shaders of white, so it's not always (#FFFFFF) and this is probably because some background pixel colors leak inside of it or something similar...
I also thought that I could use the pixelsearch to find the white just like I'm using it right now, and for finding the red and pressing space I could just do

Code: Select all

loop {
        plot(xMidScrn, yMidScrn, a_index * arc, radius, x2, y2)
        PixelSearch, oX, oY, x2, y2, x2, y2, 0xFFFFFF , 20, Fast RGB

    if !ErrorLevel
      {
         pixelgetcolor white, oX, oY, rgb
         break
      }
}

loop 
{
        pixelgetcolor c, x2, y2, rgb

} until (white <> c) 
   Send {Space down}
   Sleep 10
   Send {Space up}

But the same thing as before happens, it keeps pressing space even if appears that the white is still white and that's probably because it changed to a diff shade of white.

So I got stuck with pixelsearch, and while works 5/10 of the times it's not optimal and that is because it can't search fast enough.

For you visuals out there check out this GIF (that is not the actual speed, it appears to be slow cause I've used mousemove to track down it's path)

Is there anything that we could do? or this is how far we can reach with AHK?
Thanks!!
User avatar
Spawnova
Posts: 555
Joined: 08 Jul 2015, 00:12
Contact:

Re: Speed up PixelSearch?

15 Oct 2017, 19:51

Perhaps searching for pink may help, it looks like red line is overlapping on the white, so just doing a pixelsearch for a color such as 0xf97077 (grabbed from image provided) may yield better results.
Since that shade of pink is only really shown when the red overlaps a bright white it should only appear when it's inside that zone, some shade variance will probably also be needed.

just a thought. =P
vanker
Posts: 9
Joined: 12 Oct 2017, 17:01

Re: Speed up PixelSearch?

15 Oct 2017, 20:11

Spawnova wrote:Perhaps searching for pink may help, it looks like red line is overlapping on the white, so just doing a pixelsearch for a color such as 0xf97077 (grabbed from image provided) may yield better results.
Since that shade of pink is only really shown when the red overlaps a bright white it should only appear when it's inside that zone, some shade variance will probably also be needed.

just a thought. =P
Yeah, maybe but the thing is "waiting" for the red isn't the problem as I can just keep scanning the white part until some shade of red (or pink in this case) comes in contact with it.


Finding the white part is the culprit here, If I could just speed that up...

I'm doing 3~~5 increment on each iteration of the loop, I can try to boost that up to 10-15 but it may skip some pixels and not find the white.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 77 guests