Hey Guys / Gals!
When using PixelSearch in AHK it starts at the top left of the screen and works its way down to the bottom right, which for most cases is fine, but not in a game where your character is in the center of the screen, and often you wish to target the color closest.
I had a lot of help from google building this code and would like to see if anyone has any thoughts/ways to make this better. Or if anyone was having an issue with it, some slight changes can be made for it to be incorporated into your own program.
A call is made to grab the Runelite client window, this works best when all of the sidebar tool's are closed/retracted. but some offsets could be added in.
From there we do some simple math and divide it by 2 and for every loop that is done we add said loops index count to it, I also added in a random number of numbers as well, I feel the changes I made improved the speed a bit and there is plenty of room for adjustments.
So its starts in the center of the screen and spiral outward searching for the color, you may wish to add in some offsets so it's only searching the actual game screen and not the inventory / chat windows, as it stands now, this will favor any colors on the right side of your character.
When using PixelSearch in AHK it starts at the top left of the screen and works its way down to the bottom right, which for most cases is fine, but not in a game where your character is in the center of the screen, and often you wish to target the color closest.
I had a lot of help from google building this code and would like to see if anyone has any thoughts/ways to make this better. Or if anyone was having an issue with it, some slight changes can be made for it to be incorporated into your own program.
A call is made to grab the Runelite client window, this works best when all of the sidebar tool's are closed/retracted. but some offsets could be added in.
From there we do some simple math and divide it by 2 and for every loop that is done we add said loops index count to it, I also added in a random number of numbers as well, I feel the changes I made improved the speed a bit and there is plenty of room for adjustments.
So its starts in the center of the screen and spiral outward searching for the color, you may wish to add in some offsets so it's only searching the actual game screen and not the inventory / chat windows, as it stands now, this will favor any colors on the right side of your character.
Code:
find:
WinActivate, RuneLite
WinGetPos, RSWINX1, RSWINY1, RSWINX2, RSWINY2, RuneLite
Loop
{
xx1:=Floor(RSWINX2/2+A_Index*Rand(2,20))
yy1:=Floor(RSWINY2/2-A_Index*Rand(2,20))
xx2:=Floor(RSWINX2/2-A_Index*Rand(2,20))
yy2:=Floor(RSWINY2/2+A_Index*Rand(2,20))
PixelSearch, X1, Y1, %xx2%, %yy1%, %xx1%, %yy2%, 0xFFFF00, 5, fast
if ErrorLevel
{
FileAppend Target Searching: %xx1% %yy1% %xx2% %yy2%`n, *
}
else
{
FileAppend Color Found at: %X1% %Y1% `n, *
MoveMouse(X1, Y1+5, Rand(12,19))
}
}
Last edited:

