Sign in to follow this  
Followers 0
icepick090

pixelsearch

27 posts in this topic

I need help making a script to pixelsearch for a certain color, and then move the mouse to that color and right click it.. Willing to pay with paypal, msn: izorins@gmail.com

what i have seen from people is:

Func _ScanOverheadMap()

If $winpos[2] = 646 Then

;windowed

$coord = PixelSearch($winpos[0] + 3 + 50, $winpos[1] + 22 + 25, $winpos[0] + 3 + 580, $winpos[1] + 22 + 270, 0x7BA6F7, 0, 5)

Else

;fullscreen

$coord = PixelSearch($winpos[0] + 50, $winpos[1] + 25, $winpos[0] + 580, $winpos[1] + 270, 0x7BA6F7, 0, 5)

EndIf

If IsArray($coord) Then

Return True

Else

Return False

EndIf

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to the forums!

This should do it:

; Search the entire desktop for colour #7BA6F7
Local $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, 0x7BA6F7)
; If successful then click that location
If Not @Error Then MouseClick('Right', $Coords[0], $Coords[1])

Edit: Changed to the colour from the top post.

Edited by LxP

Share this post


Link to post
Share on other sites

hmm thats for desktop? what i am needing is for a full screen game.

Share this post


Link to post
Share on other sites

The @DesktopWidth and @DesktopHeight macros are used to determine what 'full-screen' is.

Share this post


Link to post
Share on other sites

oh, so this should work in the game?

Share this post


Link to post
Share on other sites

It sure should.

Share this post


Link to post
Share on other sites

Look at Opt("PixelCoordMode", NUMBER) in the help file, if you are wanting to do it in a specific window, you'll need to replace 'NUMBER' with either 2 or 0, and make sure the Coordinates your using are using the same (Client or Window Coords) using the AutoInfo tool (Can be changed in Options on the AutoInfo tool).

Also look at Opt("MouseCoordMode", NUMBER) using the same example to replace 'NUMBER'.

Then it should work on your game.

So my code would look something like:

Opt("WinTitleMatchMode", 4)
Opt("PixelCoordMode", 2)
Opt("MouseCoordMode", 2)

Global $GameTitle = "My Game"

While 1
    If Not WinActive($GameTitle) Then WinActivate($GameTitle)
    $Coords = PixelSearch(xCoordStart, yCoordStart, xCoordEnd, yCoordEnd, 0x7BA6F7)
    If Not @Error And IsArray($Coords) Then MouseClick('Left', $Coords[0], $Coords[1], 1, 1)
    Sleep(10)
Wend

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

hmm it worked but it seems to close out after a few seconds.

Share this post


Link to post
Share on other sites

Whose code are you referring to? My code isn't designed to click more than once.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

your code

Edited by icepick090

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

maybe because it doesnt repeat?

Precisely.

Ron's code will repeat and it will also continually click the same spot. Is that desired or should the code wait until the spot that was clicked change colour?

Edit: Added context.

Edited by LxP

Share this post


Link to post
Share on other sites

hmm i dont really understand but the color it clicks is the color of an armor a person has on, so it will auto follow them.

Share this post


Link to post
Share on other sites

To put it another way, should the script click the colour and then wait for the colour to move? Or should it just keep clicking away even if nothing changes?

Share this post


Link to post
Share on other sites

hmm click and wait for the color to move, because the people will be moving

Share this post


Link to post
Share on other sites

Something like this will do it then:

; Define colour to match
Local $Match = 0x7BA6F7

; Loop indefinitely
While 1
; Search the entire desktop for colour
    Local $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, $Match)
; If successful then click that location
    If Not @Error Then
        MouseClick('Right', $Coords[0], $Coords[1])
    ; Wait until the colour at that point changes
        Do
            Sleep(100)
        Until PixelGetColor($Coords[0], $Coords[1]) <> $Match
    Else
        Sleep(100)
    EndIf
WEnd

Ron's example will help you if you're looking to adapt the code to work with a windowed game as well.

Another piece of advice: grab the beta and set that up as the default to run scripts (Start > Programs > AutoIt v3 > Beta > Toggle AU3 Beta) because it has an improved PixelSearch() engine which will give much faster results.

Share this post


Link to post
Share on other sites

Something like this will do it then:

; Define colour to match
Local $Match = 0x7BA6F7

; Loop indefinitely
While 1
; Search the entire desktop for colour
    Local $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, $Match)
; If successful then click that location
    If Not @Error Then
        MouseClick('Right', $Coords[0], $Coords[1])
; Wait until the colour at that point changes
        Do
            Sleep(100)
        Until PixelGetColor($Coords[0], $Coords[1]) <> $Match
    Else
        Sleep(100)
    EndIf
WEnd

Ron's example will help you if you're looking to adapt the code to work with a windowed game as well.

Another piece of advice: grab the beta and set that up as the default to run scripts (Start > Programs > AutoIt v3 > Beta > Toggle AU3 Beta) because it has an improved PixelSearch() engine which will give much faster results.

ok did that, but it doesnt work ingame but on my desktop it does.

Share this post


Link to post
Share on other sites

Use the options that are in mine (Opt()'s) with Alex's code as he stated.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Opt("WinTitleMatchMode", 4)

Opt("PixelCoordMode", 2)

Opt("MouseCoordMode", 2)

; Define colour to match

Local $Match = 0xEF6B08

; Loop indefinitely

While 1

; Search the entire desktop for colour

Local $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, $Match)

; If successful then click that location

If Not @Error Then

MouseClick('Right', $Coords[0], $Coords[1])

; Wait until the colour at that point changes

Do

Sleep(100)

Until PixelGetColor($Coords[0], $Coords[1]) <> $Match

Else

Sleep(100)

EndIf

WEnd

like that?

Share this post


Link to post
Share on other sites

hmm that doesnt appear to work either... hmm, what should i do? =x

Share this post


Link to post
Share on other sites

When you say 'it doesn't work', what exactly do you mean? Does the mouse move in any way? Does it click the wrong location?

I would suggest trying this script with the beta; it will beep high to indicate that it found the pixel or low otherwise. I've also slowed it down so that the beeps don't drive you mad.

; Define colour to match
Local $Match = 0xEF6B08

; Loop indefinitely
While 1
; Search the entire desktop for colour
    Local $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, $Match)
; If successful then click that location
    If Not @Error Then
        Beep(800, 50)
        MouseClick('Right', $Coords[0], $Coords[1])
; Wait until the colour at that point changes
        Do
            Sleep(1000)
        Until PixelGetColor($Coords[0], $Coords[1]) <> $Match
    Else
        Beep(100, 50)
        Sleep(1000)
    EndIf
WEnd

Share this post


Link to post
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
Sign in to follow this  
Followers 0