Sign in to follow this  
Followers 0
Zer0Velocity

Help with triple color check

6 posts in this topic

I have this script but can't get it to search until 3 or more of the same colours match, which are either left, right, top, bottom and then click if the 3 colours are met at that position, or it keeps searching until it does. It must not use more than about 25 pixels between the searches from the first colour found. Any help with this would be very grateful, as I can't seem to get it to work no matter how hard I try :)

HotKeySet("{NUMPADDOT}", "search")

HotKeySet("{ESC}", "quit")

Func search()

$Colour1 = 0xFF710C

$Search1 = PixelSearch(0,0,@DesktopWidth,@DesktopHeight,$Colour1)

$Searchright = PixelGetColor($Search1[0]+25,$Search1[1])

$Searchleft = PixelGetColor($Search1[0]-25,$Search1[1])

$Searchdown = PixelGetColor($Search1[0],$Search1[1] +25)

$Searchup = PixelGetColor($Search1[0],$Search1[1] -25)

If IsArray($Search1) Then

;Msgbox(0, "Right", $Searchright)

;MouseMove ( $Search1[0]+25 , $Search1[1],0 )

;Msgbox(0, "left", $Searchleft)

;MouseMove ( $Search1[0]-25 , $Search1[1],0 )

;Msgbox(0, "up", $Searchup)

;MouseMove ( $Search1[0] , $Search1[1]-25,0 )

;Msgbox(0, "down", $SearchDown)

;MouseMove ( $Search1[0] , $Search1[1]+25,0 )

Msgbox(0, "Current Search Pixel", $Search1[0] & $Search1[1])

Do

$Search = $Search1

Until $Searchright = $Search & $Searchleft = $Search

Msgbox(0, "Next Search Pixel", $Search[0] & $Search[1])

EndIf

EndFunc

Func quit()

Exit

EndFunc

WinWaitClose("")

Share this post


Link to post
Share on other sites



This is closer but you must finish it:

HotKeySet("{NUMPADDOT}", "search")
HotKeySet("{ESC}", "quit")

Func search()
    $Colour1 = 0xFF710C
    Do
        $Search1 = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $Colour1)
        If IsArray($Search1) Then
            MsgBox(0, "Current Search Pixel", $Search1[0] & $Search1[1])
            $Searchright = PixelGetColor($Search1[0] + 25, $Search1[1])
            $Searchleft = PixelGetColor($Search1[0] - 25, $Search1[1])
            $Searchdown = PixelGetColor($Search1[0], $Search1[1] + 25)
            $Searchup = PixelGetColor($Search1[0], $Search1[1] - 25)
        EndIf
                $Search = $Search1
    Until $Searchright = $Search And $Searchleft = $Search ; here you compare color with coordinates!!!
    MsgBox(0, "Next Search Pixel", $Search[0] & $Search[1])
EndFunc   ;==>search


Func quit()
    Exit
EndFunc   ;==>quit

WinWaitClose("")

Share this post


Link to post
Share on other sites

Thanks for the reply, I have tried the above but it still doesn't seem to go to anything which has the colour 3 times within the certain distance. It keeps on going to the first colour which has no matching colour around that. Can someone please help me as i can't seem to get it to work :)

Share this post


Link to post
Share on other sites

Please someone help me :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#include <Array.au3>
#include <Misc.au3>
#include <GUIConstants.au3>

HotKeySet("{ESC}", "_quit")

$SearchArea = _DrawRect_Drag("01") ;Define Search area "01"=Left mouse Click

While 1
    ;Color 1 Search
    $Array01 = _PixelFindAll(0xFF710C,0,0,0,$SearchArea[0],$SearchArea[1],$SearchArea[2],$SearchArea[3]) ;Find all instances of the defined color within
    _ZeroSearch($Array01, 16740620, 32)
    
    ;Color 2 Search
    $Array01 = _PixelFindAll(0xFF710C,0,0,0,$SearchArea[0],$SearchArea[1],$SearchArea[2],$SearchArea[3]) ;Find all instances of the defined color within
    _ZeroSearch($Array01, 16740620, 32) 
    
    ;Color 3 Search
    $Array01 = _PixelFindAll(0xFF710C,0,0,0,$SearchArea[0],$SearchArea[1],$SearchArea[2],$SearchArea[3]) ;Find all instances of the defined color within
    _ZeroSearch($Array01, 16740620, 32)     
    
Wend





;=================================   PixelFindAll   ==============================
; Function Name:    _PixelFindAll
; Description:      Finds all instances of a pixel within a given area and returns array with Total and all locations X and Y.
;                   Allows you to limit results by skiping pixels within a given distance to each other.
; Requires:                         None
; Parameters:       $Pixel          Colour value of pixel to find (in decimal or hex).
;                   $XDist          Horizontal distance from found pixel to skip before continueing search (moving right)
;                   $YDist          Vertical distance from found pixel to skip before continueing search (moving down)
;                   $sv             Shade Varience
;                   $SB_l           left coordinate of total area to search. Default is 0 (far left side of screen)
;                   $SB_t           top coordinate of total area to search. Default is 0 (top most Side of screen)
;                   $SB_r           Right coordinate of total area to search. Default is @DesktopWidth (Far Right side of screen)
;                   $SB_b           Bottom coordinate of total area to search. Default is @DesktopHeight (Bottom most side of screen)
; Syntax:         _PixelFindAll($pixel[, $XDist, $YDist, $sv, $SB_l, $SB_t, $SB_r, $SB_b])
; Author(s):    
; Returns:      $Array[0][0] = 0 on failure
;===============================================================================
Func _PixelFindAll($pixel,$XDist=0,$YDist=0,$sv=0,$SB_l=0,$SB_t=0,$SB_r=@DesktopWidth,$SB_b=@DesktopHeight)
    Dim $Array[2][2], $Count = "0", $SB_l_Max = $SB_l, $SB_b_Max = $SB_b
    $Array[0][0] = "0"

    While 1
        $xy = PixelSearch($SB_l,$SB_t,$SB_r,$SB_b,$pixel,$sv)
        If @error And $SB_b = $SB_b_Max Then
            SetError(1)
            
            Dim $Array2[2][2]
            $Array2[0][0] = "0"
            $Count = "0"

            For $i = 1 to $Array[0][0]
                $Write = 1              
                For $j = $i+1 to $Array[0][0]
                    $VarX = _CompareNumbers($Array[$i][0], $Array[$j][0], $XDist)
                    If $VarX = 0 Then
                        $VarY = _CompareNumbers($Array[$i][1], $Array[$j][1], $YDist)
                        If $VarY = 0 Then $Write = 0
                    EndIf
                Next
                If $Write = 1 Then
                    $Count = $Count+1
                    $Array2[0][0] = $Count
                    ReDim $Array2[$Count+1][2]
                        $Array2[$Count][0] = $Array[$i][0]
                        $Array2[$Count][1] = $Array[$i][1]              
                EndIf
            Next

            Return $Array2
        ElseIf @error Then
            $SB_t = $SB_b + 1
            $SB_b = $SB_b_Max
            $SB_l = $SB_l_Max
        Else
            $Count = $Count+1
            $Array[0][0] = $Count
            ReDim $Array[$Count+1][2]
            $Array[$Count][0] = $xy[0]
            $Array[$Count][1] = $xy[1]

            $SB_t = $xy[1]
            $SB_b = $SB_t
            $SB_l = $xy[0]+1+$YDist 
        EndIf
    WEnd
EndFunc;==========================  PixelFindAll   ===============================

Func _CompareNumbers($Number1, $Number2, $byhowmuch);SUB Function of PixelFindAll
    ;Verify that $Number1 is more than $byhowmuch from $Number2
    ;Returns 0 if within $byhowmuch
    If $Number1 = $Number2 Then
        Return 0
    ElseIf $Number1 > $Number2 Then
        If ($Number1-$byhowmuch) >= $Number2 Then Return 1
    ElseIf $Number1 < $Number2 Then
        If ($Number1+$byhowmuch) <= $Number2 Then Return 1
    EndIf
    Return 0
EndFunc

;=================================   _DrawRect_Drag   ============================
; Function Name:    _DrawRect_Drag
; Requires:         <GUIConstants.au3> & <Misc.au3>
; Description:      Gives a visual aid while defineing Top\Left|bottom\Right of a given area
; Parameters:       $ActionKey      Hex code for key to press to begin and end render
;                   $color          Color of the display box
; Syntax:            _DrawRect_Drag([$ActionKey][,$color])
; Author(s):        
; Returns:          $array[4]      $array[0] = Left, $array[1] = Top, $array[2] = Right, $array[3] = Bottom
;===============================================================================
Func _DrawRect_Drag($ActionKey = "2D", $color = 0xFF0000)

    Do
        $pos = MouseGetPos()
        Sleep(25)
    Until _IsPressed($ActionKey)
    
    Local $ScanWidth = 1, $ScanHeight = 1
    Local $positions[4]
    $positions[0] = $pos[0] ;LEFT
    $positions[1] = $pos[1] ;TOP
    $x = $pos[0]
    $y = $pos[1]
    
    $GUI_DR = GUICreate("", 0, 0, $x, $y, $WS_POPUP)
    WinSetTrans($GUI_DR,"",210)
    $Top_DR = GUICreate("Top Line", $ScanWidth, 2, $x, $y, $WS_POPUP, -1, $GUI_DR)
    GUISetBkColor($color)
    WinSetTrans($Top_DR,"",210)
    GUISetState()
    $Left_DR = GUICreate("Left Line", 2, $ScanHeight, $x, $y, $WS_POPUP, -1, $GUI_DR)
    GUISetBkColor($color)
    WinSetTrans($Left_DR,"",210)
    GUISetState()
    $Right_DR = GUICreate("Right Line", 2, $ScanHeight, $x + $ScanWidth - 2, $y, $WS_POPUP, -1, $GUI_DR)
    GUISetBkColor($color)
    WinSetTrans($Right_DR,"",210)
    GUISetState()
    $Bottom_DR = GUICreate("Bottom Line", $ScanWidth, 2, $x, $y + $ScanHeight, $WS_POPUP, -1, $GUI_DR)
    GUISetBkColor($color)
    WinSetTrans($Bottom_DR,"",210)
    GUISetState()
    Sleep(800)
    
    Do
        $MousePos = MouseGetPos()
        WinMove($Top_DR, "", $x, $y, $ScanWidth, 2)
        WinMove($Left_DR, "", $x, $y, 2, $ScanHeight) 
        WinMove($Right_DR, "", $x + $ScanWidth - 2, $y, 2, $ScanHeight)  
        WinMove($Bottom_DR, "", $x, $y + $ScanHeight, $ScanWidth, 2)
        If Not (($MousePos[0] - $x) <= 0) Then
            $ScanWidth = $MousePos[0] - $x + 1
        EndIf
        If Not (($MousePos[1] - $y) <= 0) Then
            $ScanHeight = $MousePos[1] - $y - 1
        EndIf
    Until _IsPressed($ActionKey)
    
    $positions[2] = $MousePos[0] ;RIGHT
    $positions[3] = $MousePos[1] ;BOTTOM
    
    GUISetState(@SW_HIDE,$GUI_DR)
    GUISetState(@SW_HIDE,$Top_DR)
    GUISetState(@SW_HIDE,$Left_DR)
    GUISetState(@SW_HIDE,$Right_DR)
    GUISetState(@SW_HIDE,$Bottom_DR)

    Return $positions
EndFunc;==========================   _DrawRect_Drag   ============================

Func _ZeroSearch($Array01, $Colour, $Offset)
    If $Array01[0][0] > 0 Then
        For $i = 1 to $Array01[0][0]
            $Searchright = PixelGetColor($Array01[$i][0] + $Offset, $Array01[$i][1])
            $Searchleft = PixelGetColor($Array01[$i][0] - $Offset, $Array01[$i][1])
            $Searchdown = PixelGetColor($Array01[$i][0], $Array01[$i][1] + $Offset)
            $Searchup = PixelGetColor($Array01[$i][0], $Array01[$i][1] - $Offset)
            
            If $Searchright= $Colour AND $Searchleft = $Colour Then
                MouseMove($Array01[$i][0] , $Array01[$i][1],20)
                ;MouseClick("left",$Array01[$i][0] , $Array01[$i][1]) ;Rem line above and unrem this line for desired result
            ElseIf $Searchup = $Colour AND $Searchdown = $Colour Then
                MouseMove($Array01[$i][0] , $Array01[$i][1],20)
                ;MouseClick("left",$Array01[$i][0] , $Array01[$i][1]) ;Rem line above and unrem this line for desired result
            EndIf

        Next
    Else
        ;MsgBox(0,"","Could not find Colour 1")
    EndIf   
EndFunc

Func _quit()
    Exit
EndFunc

Edited by ofLight

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Share this post


Link to post
Share on other sites

Very nice light!

You must have written that a while ago, needs these to run 3.2.12+

#include <Array.au3>

#include <Misc.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

8)


NEWHeader1.png

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