Using PixelSearch to identify all possible entities on screen (MMORPG Bot)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
sh00ter666
Posts: 18
Joined: 07 Oct 2016, 10:55

Using PixelSearch to identify all possible entities on screen (MMORPG Bot)

Post by sh00ter666 » 15 Mar 2019, 12:46

Hey there folks,

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
As you can see, in this iteration I am trying to scan at least 5 objects, always calling PixelSearch with an offset of 100 pixels to the right and down. I've tried to elaborate the problem in the MS Paint image linked above, but this will lead to me missing out portions of possible entity positions.

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 :geek:

User avatar
lmstearn
Posts: 698
Joined: 11 Aug 2016, 02:32
Contact:

Re: Using PixelSearch to identify all possible entities on screen (MMORPG Bot)

Post by lmstearn » 15 Mar 2019, 23:50

Hi @sh00ter666,
The above link is broken, unfortunately. Is it possible to include the image via attachment?
One thing of benefit in these types of searches is a criteria on how far the targets are separated from each other. If a target object can be at least M X M pixels in size, then skip M units and resume the search.
Let's iterate left to right. If you know that it's very unlikely for a target to be closer than N pixels to another target, then skip M + N units and resume. To avoid searching the area just below the first match, estimate the N units down in terms of M, and store the position in an array, where it can be skipped later. Once the top row is complete, then proceed downward, and then right to left, seeking the centre in a "spiral" fashion, and when a colour unique to the character is found, change this search pattern. It gets complicated.
If the character has a "unique" pattern in context, then it might be better to use ImageSearch, or even GDIP_ImageSearch.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

User avatar
sh00ter666
Posts: 18
Joined: 07 Oct 2016, 10:55

Re: Using PixelSearch to identify all possible entities on screen (MMORPG Bot)

Post by sh00ter666 » 16 Mar 2019, 08:04

Hi Imstearn!

First off, thank you for taking the time to respond. The image link has been broken up automatically by the forum software. It doesn't seem to want me to include any images (although it worked in the past).


The idea you mention is something I tried to implement in the code sample, by resuming the search M+N units offset from the first, but that leaves me with having to divide the screen into multiple quadrants to cover the whole screen. But if nothing else works, that'd be something I will have to refine.


Try to see if the image is now available as an attachment.

As I said, because of 3D graphics and depth, I don't think that ImageSearch will yield any results, unless I were to take images of a monster from all different angles, but the effort of hard coding that is not favorable, since there are hundreds of different enemy types. Unless of course, there was some variation variable for the ImageSearch method as well, but from skimming the article I cannot make that out.

I tested the script from the first post on a similar MS Paint "training" picture, and it worked somewhat well. I must admit though that I am not the most literate AHK user. So visualizing some debug information on screen while the script runs would be favorable. Its good that you mention GDIP, I have downloaded and included the library already to run a test with it, but I would still have to play around with it to see how to include it into a hotkey/method within my script :mrgreen:
Attachments
PixelSearch_Sample.png
PixelSearch_Sample.png (59.85 KiB) Viewed 2145 times

Post Reply

Return to “Ask for Help (v1)”