Jump to content

Pixel Search problems


Kal
 Share

Recommended Posts

Hi, I'm writing a bot for a game called Tales of Pirates. I want the bot to search the screen for a a pixel with a specific color and then click that pixel. The problem I am having is that I can't get the pixel search to only search the game window. This is my test code:

WinWaitActive("Tales of Pirates - Union War")
While 1
    $window_info = WinGetPos("Tales of Pirates - Union War")
    $enemy_coords = PixelSearch($window_info[0], $window_info[1], $window_info[2], $window_info[3], 0xC8600C)
    If @error == 0 Then
        MouseMove($enemy_coords[0], $enemy_coords[1], 0)
        MouseClick("left")
    EndIf
    Sleep(100)
WEnd

This is the line that is not working correctly: $enemy_coords = PixelSearch($window_info[0], $window_info[1], $window_info[2], $window_info[3], 0xC8600C)

I'm trying to get the script to only search the game window by getting the x and y coords and the window width and heigth and then use those variables to sepcify the area that PixelSearch() searches through. Shouldn't this work? I mean the PixelSearch() function takes 4 parameters: left, top, right and bottom. If I use WinGetPos() I get the window's x position, y position, width and heigth. So if I only want to search the game window the "left" paramater should equal the window's x position, the "top" parameter should equal the window's y position, the "right" parameter should equal the window's width and finally the "bottom" paramater should equal the windows heigth, right?

Am I missing something here because nothing happens when I run that code. However, it works when type this: $enemy_coords = PixelSearch(0, 0, 1440, 900, 0xC8600C) (1400 x 900 is my desktop resolution) but then it searches through the whole screen and I only want it to search through the game window.

Any help is appreciated!

And by the way I got another question concerning pixel search. Is it possible to use a pixel search that only matches when more than one pixel has the right color? For example say that I want pixel search only to match when a red pixel is to the left of a green pixel and to the right of a blue pixel. Can you do that somehow?

Edited by Kal
Link to comment
Share on other sites

I think that will work true :

$enemy_coords = PixelSearch($window_info[0], $window_info[1], $window_info[0] + $window_info[2], $window_info[1] + $window_info[3], 0xC8600C)

Is it possible to use a pixel search that only matches when more than one pixel has the right color?

Look here for MultiPixelSearch :

http://www.autoitscript.com/forum/index.php?showtopic=55769

Edited by Jex
Link to comment
Share on other sites

Yes that worked! Thanks a lot! Would you mind explaining how it works too? Why should the "width" parameter be the window width plus the x pos, shouldn't that result in a pixel search area that is bigger than the window? And the same thing for "heigth".

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...