Pixel Trigger With a Rule

Ask gaming related questions
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Pixel Trigger With a Rule

19 Jul 2017, 10:35

Hello, I am working on color aim assist but I'm stuck ;-;
Please, masters of AHK, help me!

Here is the algorithm:

There is a moving circle target of various colors. When you hover over it, red text appears above. When that red text appears, it means the cursor is on target. So 5ms after that instant I want the cursor to lock on the pixel it is situated on for as long as the red text is visible. When red text disappears, unlock cursor and start searching for the red text around the pointer again.

Here is my script that finds the red text when I hold a button:

Code: Select all

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

~*LButton::
BreakLoop = 0       ; this section is for breaking the loop
Loop,
{
if (BreakLoop = 1)
{
	break
}
Else
Loop,
{
	MouseGetPos, mouseX, mouseY           ; These two lines check for red color range around the pointer in 150 pixels radius
	PixelSearch, rX, rY, mouseX - 150, mouseY- 150, mouseX + 150, mouseY + 150, 0x0B18A2,  35, Fast
}

*LButton Up::        ; break the loop when I release the button
BreakLoop =1
Return
I can easily make the cursor follow the red color itself by adding these lines:

Code: Select all

	If ((rX != "") && (rY != ""))         ;if the red color is found, move cursor on it. Loop "locks" it by repeating the steps.
	MouseMove, %rX%, %rY%
	
The problem is, I don't want cursor to simply lock on red color. I want red color to act as an indicator to scan 1 pixel color at current mouse position and lock on it until red color indicator is no longer visible. How to make it?
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: Pixel Trigger With a Rule

19 Jul 2017, 13:08

So to me it sounds like you need a step where once you find the red pixel, you need to use a different PixelSearch that uses the returned rX,rY when that was first found rather than the mouseX. That is, use a second PIxelSearch with PixelSearch, rX, rY, rX - 150, rY - 150, rX + 150, rY + 150, 0x0B18A2, 35, Fast and keep using that one until there is no match.

I'll let you play around with the logic to switch between "Red Found" and "Red Disappeared" modes. PixelSearch can set a built in variable called ErrorLevel that you may be interested in combining with an If statement; also, Loops can be inside of Loops.
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Pixel Trigger With a Rule

19 Jul 2017, 14:40

I'll try tomorrow with 2 loops, and post the results. i thought it's impossible because someone wrote that in forum.
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Pixel Trigger With a Rule

20 Jul 2017, 03:04

After some testing I figured out how loops work yay!

This is my final test script which woks in notepad. It looks for white color first, then activates the red color mode and repeats the process until E button is released :ugeek:
Now I just have to adapt it to my needs :ugeek: :ugeek: :ugeek:

Code: Select all

*e::
SetBatchLines -1
CoordMode, pixel,screen
CoordMode, mouse,screen 
Send,e
Sleep,500
BreakLoop = 0
Loop,
{
if (BreakLoop = 1)
break
Sleep,500
MouseGetPos, mX, mY
PixelSearch, nX, nY, mX - 150, mY - 150, mX + 150, mY + 150, 0xFFFFFF, 20, Fast
	if ErrorLevel
	Continue
	else
	Send, White Color was found
	Loop,
	{
	if (BreakLoop = 1)
	break
	Sleep,500
	MouseGetPos, mX, mY
	PixelSearch, nX, nY, mX - 10, mY - 10, mX + 10, mY + 10, 0x0000E7, 50, Fast
	if ErrorLevel
	Continue
	else
	Send, Red Color was found
	break
	}
}


*e Up::
BreakLoop = 1
Return
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Pixel Trigger With a Rule

20 Jul 2017, 12:02

In the end, this didn't work. There are too many similar pixels on screen... It often gets a color a little bit too late and pointer jumps around the background as a result.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 19 guests