Sign in to follow this  
Followers 0
meowbits

Pixel search based on user-defined coords

1 post in this topic

Anyone know if this is actually setting the coodinates, $left, $top, $right, $bottom after the user defines them?

I'm trying to use those coords as a pixel search.

Opt("WinWaitDelay",3000)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)

#include <IE.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Dim $pos = "", $CHex = "", $Cpos = "", $Count = 0, $data[11], $Label_[11], $Run, $Launcher, $cwait = 0
Dim $pause, $left = 0, $right = 0, $top = 0, $bottom = 0
Dim $Gloc = @ScriptDir & "\Games\", $Ginfo

Opt("PixelCoordMode", 0)   ;1=absolute, 0=relative, 2=client
Opt("MouseCoordMode", 0)   ;1=absolute, 0=relative, 2=client

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

$Gamebot = GUICreate("FarmBot", 392, 402, -1, -1, -1, $WS_EX_ACCEPTFILES)
$Group_5 = GUICtrlCreateGroup("Game Launch", 10, 80, 370, 80)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetState(-1, $GUI_DISABLE)
$Radio_9 = GUICtrlCreateRadio("Dont Launch Anything", 230, 100, 130, 20)
GUICtrlSetState(-1, $GUI_CHECKED)
$Group_10 = GUICtrlCreateGroup("Pixel Search Area", 10, 170, 370, 100)
$Label_11 = GUICtrlCreateLabel("Left              Top             Right         Bottom", 20, 190, 350, 20)
$Input_12 = GUICtrlCreateInput($left, 20, 210, 40, 20)
$Input_13 = GUICtrlCreateInput($top, 80, 210, 40, 20)
$Input_14 = GUICtrlCreateInput($right, 140, 210, 40, 20)
$Input_15 = GUICtrlCreateInput($bottom, 200, 210, 40, 20)
$Button_29 = GUICtrlCreateButton("Get Area", 280, 240, 90, 25)
$Button_33 = GUICtrlCreateButton("Run GameBot", 140, 360, 110, 30)
$Button_34 = GUICtrlCreateButton("Exit GameBot", 270, 360, 110, 30)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_34
            ExitLoop
        Case $msg = $Button_29
            Get_Area()
        Case $msg = $Button_33
             Set_Run()


; pixel search
     $left = IniRead($Gloc & $Ginfo & ".ini", "Settings", "Left", "None")
     GUICtrlSetData($Input_12, $left)
     $top = IniRead($Gloc & $Ginfo & ".ini", "Settings", "Top", "None")
     GUICtrlSetData($Input_13, $top)
     $right = IniRead($Gloc & $Ginfo & ".ini", "Settings", "Right", "None")
     GUICtrlSetData($Input_14, $right)
     $bottom = IniRead($Gloc & $Ginfo & ".ini", "Settings", "Bottom", "None")
     GUICtrlSetData($Input_15, $bottom)
     $Vary = IniRead($Gloc & $Ginfo & ".ini", "Settings", "Vary", "5")
    EndSelect
WEnd

Func Get_Area()
     $Count = 0
     If GUICtrlRead($Button_29) = "Get Area" Then
         HotKeySet("{F9}", "set_Area")
         ToolTip('Press "F9" to Get the Area under the Mouse Left-Top-Right-Bottom, Click "Done" when Finished', 0, 0)
         GUICtrlSetData($Button_29, "Done")
         Return
     Else
         HotKeySet("{F9}")
         ToolTip('')
         GUICtrlSetData($Button_29, "Get Area")
         $Count = 0
     EndIf
EndFunc;==>Get_Area

Func set_Area()
     $Count = $Count + 1
     $Mpos = MouseGetPos()
     If $Count = 1 Then GUICtrlSetData($Input_12, $Mpos[0])
     If $Count = 2 Then GUICtrlSetData($Input_13, $Mpos[1])
     If $Count = 3 Then GUICtrlSetData($Input_14, $Mpos[0])
     If $Count = 4 Then GUICtrlSetData($Input_15, $Mpos[1])
     If $Count >= 4 Then $Count = 0
EndFunc;==>set_Area
 
Func Set_Run()
    If $Run = 1 Then
        Run(@ComSpec & " /c Start " & $Launcher, "", @SW_HIDE)
        $ON = True
    ElseIf $Run = 2 Then
        $Launched = FileGetShortName($Launcher)
        Run(@ComSpec & " /c Start " & $Launched, "", @SW_HIDE)
        $ON = True
    EndIf
    GUISetState(@SW_MINIMIZE, $Gamebot)
    ToolTip('Press F9 to Start Game', 0, 0)
    _ReduceMemory()
    HotKeySet("{F9}", "_start")
EndFunc;==>Set_Run


Func _start()
     $Colors = IniReadSection($Gloc & $Ginfo & ".ini", "Colors")
     For $i = 0 To $Colors[0][0]
         $data[$i] = IniRead($Gloc & $Ginfo & ".ini", "Colors", $i, "")
         If $i >= 10 Then ExitLoop
     Next
     $pause = Not $pause
     While $pause
         ToolTip('GameBot is "Running"..   Press F9 to Quit', 0, 0)
         $t = 0
         Do
             $t = $t + 1
             If $t > 10 Then ExitLoop
             Sleep($cwait)
         Until Not @error
         If $t > 10 Then ContinueLoop
         MouseClick("left", $Cpos[0], $Cpos[1], 1, 0)
;MouseMove($left, $top)
     WEnd
     ToolTip('')
     GUISetState(@SW_RESTORE, $Gamebot)
     HotKeySet("{F9}")
EndFunc;==>_start

Func _ReduceMemory()
     Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
     Return $ai_Return[0]
EndFunc;==>_ReduceMemory

Func Terminate()
     Exit
EndFunc;==>Terminate




; declare variable color (use Eyedropper4.0 to find color,
; keep 0x and add your 6 digit number after it)

Dim $left, $top, $right, $bottom

Global $storeIconColor = 0xB0BD62 ; store icon color 
Global $hayBailColor = 0xF7A505 ; haybail color
Global $grassColor = 0x3A7A02   ; grass color

Global $bailsTobuy      ; Number of haybails to buy/sell
Global $storeCoords     ; Coordinates of the store icon
Global $otherCoords     ; Coordinates of the 'other' tab
Global $buyHayBailCoords ; Coordinates to buy haybail
Global $placeHayBailCoords ; Coordinates to place haybail
Global $sellHayBailCoords = $placeHayBailCoords
Global $confirmSellCoords; Coordinates to sell haybail

Global $storeCoords[2]        ; Coordinates of the store icon
Global $otherCoords[2]        ; Coordinates of the 
Global $buyHayBailCoords[2]  ; Coordinates of the 
Global $placeHayBailCoords[2]   ; Coordinates of the 
Global $ssellHayBailCoords[2]   ; Coordinates of the 
Global $confirmCoords[2]        ; Coordinates of the 

; declare ON true(on) false(off)
Global $ON

;If $bailsTobuy != Int Then
; dialog box to prompt for total bails to buy/sell - NEED HELP
; Amount of bails you can afford is ((Total Coins -50)/48)) round down
; if answer != integer stop or run a loop to ask again, not sure how to.
; answer = $baysToBuy

;If ($CmdLine[0] = 2) Then
;Exit 0
;EndIf

;If ($CmdLine[0] = 1) Then 
If $ON = True Then
; Open url to play FarmTown
    _IECreate ("http://apps.facebook.com/farmtown/play/", 1, 1, 1, 1)
; Initial loop
    Dim $iCounter = 1
    While $iCounter
    Sleep(500)
        if $ON = True Then
        ; start pixel search for store icon
            $coord1 = PixelSearch($left, $top, $right, $bottom, $storeIconColor,10)
            If IsArray($coord1) = 1 Then
            ; save coords as 'storeCoords'
                $storeCoords[0] = $coord1[0] 
                $storeCoords[1] = $coord1[1]
                MouseClick("left", $storeCoords[0], $storeCoords[1])
        ; Error msg
            Else
                MsgBox(0,"ERROR","Unable to find Store icon edit your '$storeIconColor'")
                Exit
            EndIf
            Sleep(300)
        ; start somesort of search to find the 'other' tab - NEED HELP
            $coord2 = 1
            If IsArray($coord2) = 1 Then
                $coord2[0] = 1100
                $coord2[1] = 210
            ; save coords as 'otherCoords'
                $otherCoords[0] = $coord2[0]
                $otherCoords[1] = $coord2[1]
                MouseClick("left", $otherCoords[0], $otherCoords[1])
        ; Error msg
            Else
                MsgBox(0,"ERROR","Unable to find '$otherCoords'")
                Exit
            EndIf
            Sleep(300)
        ; start pixel search for haybail icon
            $coord3 = PixelSearch($left, $top, $right, $bottom, $hayBailColor,10)
            If IsArray($coord3) = 1 Then
            ; save coords as 'buyHayBailCoords'
                $buyHayBailCoords[0] = $coord3[0]
                $buyHayBailCoords[1] = $coord3[1]
                MouseClick("left", $buyHayBailCoords[0], $buyHayBailCoords[1])
        ; Error msg
            Else
                MsgBox(0,"ERROR","Unable to find HayBail edit your '$haybailColor'")
                Exit
            EndIf
            Sleep(300)
        ; start pixel search for grass color
            $coord4 = PixelSearch($left, $top, $right, $bottom, $grassColor,10)
            If IsArray($coord4) = 1 Then
            ; save coords as 'placeHayBailCoords'
                $placeHayBailCoords[0] = $coord4[0]
                $placeHayBailCoords[1] = $coord4[1]
                MouseClick("left", $placeHayBailCoords[0], $placeHayBailCoords[1])
                Sleep(300)
                MouseClick("left", $sellHayBailCoords[0], $sellHayBailCoords[1])
        ; Error msg
            Else
                MsgBox(0,"ERROR","Unable to find Grass edit your '$grassColor'")
                Exit
            EndIf
            Sleep(300)
        ; start somesort of search to find the 'sell' tab - NEED HELP
            $coord5 = 1
            If IsArray($coord5) = 1 Then
                
            ; save coords as 'confirmSellCoords'
                $confirmSellCoords[0] = $coord5[0]
                $confirmSellCoords[1] = $coord5[1]
                MouseClick("left", $confirmSellCoords[0], $storeCoords[1])
            ; Error msg
            Else
                MsgBox(0,"ERROR","Unable to find 'confirmSellCoords'")
                Exit
            EndIf
        EndIf
        $iCounter +=1
    WEnd
    
    Dim $bCounter = 1
; Main loop
    While $bailsTobuy -1 >= $bCounter
        Sleep(5000)
        MouseClick("left", $storeCoords[0], $storeCoords[1])
        Sleep(300)
        MouseClick("left", $otherCoords[0], $otherCoords[1])
        Sleep(300)
        MouseClick("left", $buyHayBailCoords[0], $buyHayBailCoords[1])
        Sleep(300)
        MouseClick("left", $placeHayBailCoords[0], $placeHayBailCoords[1])
        Sleep(300)
        MouseClick("left", $sellHayBailCoords[0], $sellHayBailCoords[1])
        Sleep(300)
        MouseClick("left", $confirmSellCoords[0], $storeCoords[1])
        $bCounter +=1
    WEnd
EndIf

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