Random delay in Goto through PixelSearch?

Ask gaming related questions (AHK v1.1 and older)
hellcat99
Posts: 1
Joined: 23 Mar 2020, 05:54

Random delay in Goto through PixelSearch?

23 Mar 2020, 06:01

Hello, I'm experiencing an issue with a script I've been working on. The intended successful goal of the script is to wait until, where if it isn't detected, the script will loop back to the PixelSearch until it is and when it is detected, to go to the blue tag as seen in my code. It works, however I'm noticing that for some reason, the script doesn't detect yellow instantly as it would (I tested this part) if I had put the code at the beginning of the loop and thus, causes about a 2 second delay. Any help is appreciated.

Code: Select all

F6::Reload
F8::ExitApp
F5::
trapresetting = 0
Loop {
	red:
	ImageSearch, redX, redY, 0, 0, A_ScreenWidth, A_ScreenHeight, *10 Images/red.png
	if (Errorlevel = 0 && trapresetting = 0) {
		redpending:
		PixelSearch,,, redX, redY, redX + 32, redY + 32, 0xFFFF00, 0, RGB Fast
		if (Errorlevel = 0 && trapresetting = 1) {
			Goto blue
		} else if (Errorlevel = 1 && trapresetting = 1) {
			Goto redpending
		}
		redsuccess:
		PixelSearch, successX, successY, redX, redY, redX + 32, redY + 32, 0x26FF00, 0, RGB Fast
		if (Errorlevel = 0) {
			Random, successXA, successX - 4, successX + 8
			Random, successYA, successY + 7, successY + 19

			Randsleep(75, 150)
			Mousemove(successXA, successYA, 80)
			Click

			trapresetting = 1
			Goto redpending
		}
		redfailure:
		PixelSearch, failureX, failureY, redX, redY, redX + 32, redY + 32, 0xFF3000, 0, RGB Fast
		if (Errorlevel = 0) {
			Random, failureXA, failureX - 4, failureX + 8
			Random, failureYA, failureY + 7, failureY + 19

			Randsleep(75, 150)
			Mousemove(failureXA + 2, failureYA + 13, 80)
		}
	}
	blue:
	ImageSearch, blueX, blueY, 0, 0, A_ScreenWidth, A_ScreenHeight, *10 Images/blue.png
	if (Errorlevel = 0) {
		bluesuccess:
		PixelSearch, successX, successY, blueX, blueY, blueX + 32, blueY + 32, 0x26FF00, 0, RGB Fast
		if (Errorlevel = 0) {
			Random, successXA, successX - 4, successX + 8
			Random, successYA, successY + 7, successY + 19

			Randsleep(75, 150)
			Mousemove(successXA, successYA, 80)
		}
		bluefailure:
		PixelSearch, failureX, failureY, blueX, blueY, blueX + 32, blueY + 32, 0xFF3000, 0, RGB Fast
		if (Errorlevel = 0) {
			Random, failureXA, failureX - 4, failureX + 8
			Random, failureYA, failureY + 7, failureY + 19

			Randsleep(75, 150)
			Mousemove(failureXA + 2, failureYA + 13, 80)
		}
	}
}

Randsleep(min, max) {
    Random, rand, %min%, %max%
    Sleep %rand%
}

Mousemove(x, y, speed := 200) {
	MouseGetPos, x0, y0
	Random, r, -2., 2.
	xd := x-x0, yd := y-y0
	z := Sqrt(xd*xd+yd*yd)//speed
	xd := xd/z, yd := yd/z
	x2 := -yd*r/z, y2 := xd*r/z
	x3 := yd*r/2, y3 := -xd*r/2, z--
	Loop, % z
	Mousemove, x0+=xd+x3+=x2, y0+=yd+y3+=y2, 1
	Mousemove, x, y, 1
}

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 84 guests