How to stop and continue the Loop?

Ask gaming related questions (AHK v1.1 and older)
User avatar
jasonch
Posts: 3
Joined: 18 Jul 2017, 14:01

How to stop and continue the Loop?

27 Jul 2017, 15:08

Hello and thanks in advance guys! So here my problem for hours:

Code: Select all

SetMouseDelay, 10
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen

F12::
outer:
Loop {
    PixelSearch, X, Y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x00FF00, 30, Fast
    if ErrorLevel {
	Loop {
		Random, RandomX, 0, %A_ScreenWidth%
		Random, RandomY, 0, %A_ScreenHeight%
		PixelGetColor, Color, %RandomX%, %RandomY%
			If Color=0x000000
			{
				Continue, outer
			}
			Else
			{
			MouseMove, %RandomX%, %RandomY%, 40
			Sleep, 200
			Click
			Continue
			}
	}
	}
else {
	MouseMove, %X%, %Y%, 20
	Sleep, 200
	Click
}
}
F11::ExitApp
Return
What I want from this script is to continually search the color "0x00FF00" but if there's none, i want it to randomly choose 1 coordinate and repeatedly left-click in that coordinate UNTIL the color "0x000000" goes in to the mouse position, when it does, it will again choose random coordinate and repeatedly click there once again. All of this until it finds the color "0x00FF00" on the screen.

I wanted to use "goto" commands but I know there is a way to this using loops. Thank you!!
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: How to stop and continue the Loop?

28 Jul 2017, 03:29

This is my test code that I wrote to figure out the same script as you want (in principle). When you hold E it searches around the mouse for color red and beeps. If it finds color, it beeps twice then starts beeping faster. If you move away the cursor from red it starts beeping slowly again and search for red color again. Releasing E key breaks script.

Code: Select all

SendMode Input
#NoEnv
#MaxThreadsperHotkey 1
SetBatchLines -1
CoordMode, Screen

Suspend

*e::
BreakLoop = 0
Loop,
{
if (BreakLoop = 1)
break
MouseGetPos, mX, mY
PixelSearch, nX, nY, mX - 150, mY - 150, mX + 150, mY + 150, 0x0000E5, 10, Fast
Soundbeep,400
Sleep,500
	if ErrorLevel
	Continue
		Soundbeep,500,500			
		Sleep,500
		Soundbeep,500,500	
			Loop
			{
			if (BreakLoop = 1)
			break
			MouseGetPos, mX, mY
			PixelSearch, nX, nY, mX - 150, mY - 150, mX + 150, mY + 150, 0x0000E5, 10, Fast
			Soundbeep,900,100
			if ErrorLevel
			break
			}
}


*e Up::
BreakLoop = 1
Return




*~CapsLock::
	Suspend
	Return

*RAlt::
Process, Close, AutoHotKey.exe
User avatar
jasonch
Posts: 3
Joined: 18 Jul 2017, 14:01

Re: How to stop and continue the Loop?

28 Jul 2017, 10:52

This is exactly what I want it to do, except I want the E to be, like, pressed permanently and instead of me moving the cursor, the script will move it if the color "0x0000E5" appears inside the 150 pixel range of the cursor.
User avatar
jasonch
Posts: 3
Joined: 18 Jul 2017, 14:01

Re: How to stop and continue the Loop?

01 Aug 2017, 19:18

I somehow managed to do it:

Code: Select all

SetMouseDelay, 5
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
Black=0x000000
F12::
AutoAim:
Loop {
	PixelSearch, X, Y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x00FF00, 30, Fast
	If (ErrorLevel=1) {
		MouseGetPos, xpos, ypos 
		PixelGetColor, color, %xpos%, %ypos%
		If (color = Black) {
				Random, RandomX, 160, 1128
				Random, RandomY, 120, 576
				MouseMove, %RandomX%, %RandomY%, 40
				Continue, AutoAim
				}else{
				Sleep, 150
				Click
				}
		}else{
	Send, 1
	MouseMove, %X%, %Y%, 20
	Sleep, 150
	Click
	}
}
F10::Pause
F11::ExitApp
Return
But it eats alot of my cpu, how can I let it use less guys?

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 48 guests