I am trying to realize a simple click/grind bot for an old MMORPG.
I opted with the PixelSearch method, because that seemed to be the easiest solution to wrap my head around for this point in time.
I am not sure if ImageSearch would be optiomal, since the game is 3D and monsters tend to rotate, appear smaller in the distance etc.
Here is a concept of the problem at hand, with some additional text notes:
https i.imgur.com /4y363CZ.png Broken Link for safety
The problem in a nutshell: I do not only want to scan the first pixel / entity and the program to stop there. I want to identify all of them and mark their position on screen with a little marker (maybe a transparent click-through GUI. The only task that is then left to do is to move the mouse to one of the positions and then double-click it to attack. I believe the idea and goal to be very basic.
My problem right now. I don't know how to scan and store all matching pixels in a list of some sorts that would allow me to go from there. As I see it, PixelSearch will always stop at the first encounter and return a pixels coordinates.
I have set up a basic script that gets the job done okayish, but it's definitely improvable.
Code: Select all
#SingleInstance, Force
CoordMode, Pixel, Screen
CoordMode,Mouse,Screen
SetMouseDelay 50
width = A_ScreenWidth
height = A_ScreenHeight
centerx = width/2
centery = height/2
sx:=0
sy:=0
ex:=A_ScreenWidth
ey:=A_ScreenHeight
; REFERENCE: PixelSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID [, Variation, Fast|RGB]
;To define a search area, in case I don't want the whole screen.
$End::
Switch :=!Switch
if(Switch =1)
{
MouseGetPos, sx,sy
}
else if(Switch =0)
{
MouseGetPos,ex,ey,
Gui,1:Destroy
Gui,1:+Alwaysontop -Caption Border +LastFound
WinSet, Transparent, 100
Gui,1:Color,00ff00
Gui,1:Show,% "x" sx " y" sy " w" ex-sx " h" ey-sy
Sleep, 2000
Gui,1:Destroy
}
return
^::
PixelSearch, ax, ay, sx, sy, ex, ey, 0xFF0000, 55, Fast RGB
if(!ErrorLevel)
{
MouseMove ax, ay
Loop 5
{
PixelSearch, ax, ay, ax+100, ay+100, ex, ey, 0xFF0000, 55, Fast RGB
if(!ErrorLevel)
MouseMove ax, ay
SoundBeep, 1500, 250
Sleep, 1500
}
}
else
SoundBeep, 800, 250
return
In another version, I have tried to start from the center of the screen and to gradually scan bigger rectangles in relation to the center of the screen, but that didn't work so good either. The game I'm targetting has your character centered, which means that the closest target you'd want to click is the one closest to the screen center.
I'd appreciate any sort of hints for this, as I'm feeling quite lost, and I also believe that my solution might be very inefficient