Jump to content

Pixel Search


Recommended Posts

Okay well im updating my fishing bot do its more user friendly, and can be set up in just few clicks instead of about 30...

My only problem is, its not finding the blober....

Any ideas why my code is broken?

Here it is:

;Include files:
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#Include <Misc.au3>
#include <WinAPI.au3>


;Settings:
$prog = "Fish Progression" ; Program Title
opt("SendKeyDelay",75) ; Slow down send
HotKeySet("{pause}", "Quit")
Global $searchL, $searchT, $searchR, $searchB, $color, $numofcasts, $castfail, $bait, $Pole, $numofbait, $Baittimer, $Baitnum, $Estimatehour,$castnum , $Statuslable, $esttimer, $Estimatecatchhour , $Estimatecastshour


#Region ### START Koda GUI section ### Form=
$Maingui = GUICreate($prog, 329, 110)
$group1 = GUICtrlCreateGroup("Please select a fishing profile:", 8, 8, 161, 49)
$profilebox = GUICtrlCreateCombo("Please select", 16, 24, 145, 25)
GUICtrlSetData(-1, FileRead("Profiles/Profilelist.txt"))
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Which bait are you using?", 8, 56, 161, 49)
$Baitbox= GUICtrlCreateCombo("None", 16, 72, 145, 25)
GUICtrlSetData(-1, "Shiny Bauble|Sharpened Fish Hook|Nightcrawlers|Flesh Eating Worm|Bright Baubles|Aquadynamic Fish Lens|Aquadynamic Fish Attractor")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$newprofile = GUICtrlCreateButton("Make a new profile", 176, 16, 139, 25, 0)
$loadprofile = GUICtrlCreateButton("Import an Un-offical profile", 176, 48, 139, 25, 0)
$Startbutton = GUICtrlCreateButton("Start!", 176, 80, 139, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Startbutton
            Setupbot()
        Case $newprofile
            $dll = DllOpen("user32.dll") ; Read somewhere thats User32.ddl speeds up _IsPressed detection?
            WinActivate("World of Warcraft")
            ToolTip("Choose the color that you wish to use in the Profile. There is a colour block at the bottom of your screen to help you", 0, 0)

    ;Color select

    ; Present a GUI to show the color at the mouse cursor
    $colourgui = GUICreate("",200,100,(@DesktopWidth/4)-100,@DesktopHeight-125,$WS_POPUP,$WS_EX_TOPMOST) ; Create a large borderless GUI that is always on top so user can see the color
    GUISetState(@SW_SHOW)

    ; Wait for a colour to be clicked on
    While -1
        If WinActive("World of Warcraft") = 0 Then WinActivate("World of Warcraft") ; Make sure Wow stays active while user is selecting color
        $mouse = MouseGetPos()
        $color = PixelGetColor($mouse[0],$mouse[1])
        GUISetBkColor("0x" & Hex($color,6),$colourgui) ; Update gui with color seen
        If _IsPressed("01",$dll) Then ExitLoop; Exit loop when user left clicks
    WEnd
    GUIDelete($ColourGUI)
    ToolTip("Thank you for selecting the colour!",0,0,"",2)
    Sleep(500)
    DllClose($dll) ; Close DLL
    
    ;ask for profile name
    $newprofilename = InputBox($prog, "Please Type the name of the new profile below!", "", "", 300, 200)
    FileWriteLine("Profiles/" & $newprofilename & ".txt", $color) ; right profile
    ;add profile to list
    $1 = FileReadLine("Profiles/Profilelist.txt", 1)
    FileWriteLine("Profiles/temp.txt", $1)
    FileDelete("Profiles/Profilelist.txt")
    $file1 = FileReadLine("Profiles/temp.txt", 1)
    FileWriteLine("Profiles/Profilelist.txt", $file1 & "|" & $newprofilename)
    FileDelete("Profiles/temp.txt")
    MsgBox(64, $prog, "Please Restart " & $prog &" for changes to take effect.")
    
Case $loadprofile
    $import = FileOpenDialog("Please choose the profile you wish to import", @ScriptDir, "Profiles (*.txt)")
    ;add profile to list
    $1 = FileReadLine("Profiles/Profilelist.txt", 1)
    FileWriteLine("Profiles/temp.txt", $1)
    FileDelete("Profiles/Profilelist.txt")
    $file1 = FileReadLine("Profiles/temp.txt", 1)
    FileWriteLine("Profiles/Profilelist.txt", $file1 & "|" & $import)
    FileDelete("Profiles/temp.txt")
    MsgBox(64, $prog, "Please Restart " & $prog &" for changes to take effect.")
    EndSwitch
WEnd

Func Setupbot()
    $profile = GUICtrlRead($profilebox)
    $bait = GUICtrlRead($baitbox)
    GUISetState(@SW_HIDE, $MainGUI)
    ToolTip('Setting up bot, do not move the mouse!',0,0,"",2)
    
    If WinActive("World of Warcraft") = 0 Then WinActivate("World of Warcraft")
    Sleep(2000)
    Send("{Home}") ; Zoom in WoW
        Send("{Home}")
            Send("{Home}")
                Send("{Home}") 
                    Send("{Home}")
                            sleep(2000)
                                    MouseMove(@DesktopWidth/2, @DesktopHeight/2)
                                    MouseClickDrag("Right", @DesktopWidth/2, @DesktopHeight/2, @DesktopWidth/2, @DesktopHeight/2 +1)
                                    Sleep(2000)
;Selecting search area
    ; Select the upper left of the search area
    MouseMove(@DesktopWidth/12, @DesktopHeight/3.4)
    $mouse = MouseGetPos()
    $searchL = $mouse[0]
    $searchT = $mouse[1]
    Sleep(1000)
    ; Select the lower right of the search area
    MouseMove(@DesktopWidth/5*4, @DesktopHeight/1.4)
    $mouse = MouseGetPos()
    $searchR = $mouse[0]
    $searchB = $mouse[1]
    Sleep(1000)
    
;load GUi
$infowindow = GUICreate($prog, 243, 85, @DesktopWidth/2 -121.5 , @DesktopHeight/9)
$Statuslable = GUICtrlCreateLabel("Status: Idle", 8, 8, 400, 17)
$Castnum = GUICtrlCreateLabel("Number of casts:", 8, 32, 400, 17)
$Baitnum = GUICtrlCreateLabel("Bait used:", 8, 56, 400, 17)
GUISetState(@SW_SHOW)
WinSetOnTop($prog, "", 1)
ToolTip('',0,0,"",2) ; Delete Tooltip
Fish()
EndFunc

Func Fish()
WinActivate("World of Warcraft")
Sleep(1000)
If $bait = "None" Then
    sleep(1000)
Else
GUICtrlSetData($Statuslable,"Equiping " & $bait & "! Please Wait...")
Send("/use " & $bait &  "{Enter}")
Send("/use 16 {Enter}")
$Baittimer = TimerInit()
Sleep(4000)
$numofbait +=1
EndIf
GUICtrlSetData($Baitnum, "Bait used: " & $numofbait)

$getcolour = FileReadLine($bait & ".txt", 1)
        
;start fishing
While -1
    While -1
        _checkbait()
        WinActivate("World of Warcraft")
        Sleep(500)
        GUICtrlSetData($Statuslable, "Status: Casting...")
        Sleep(1000)
        Send("1") ; Use the first slot of the cast bar to start fishing
        $numofcasts += 1
        GUICtrlSetData($Statuslable, "Status: Waiting for Blobber...")
        Sleep(3000)
        GUICtrlSetData($Statuslable, "Status: Searching for Bobber...")
        $timer = TimerInit() ; Set a timeout for finding bobber
        While -1
            $bobber = PixelSearch($searchL,$searchT,$searchR,$searchB,"0x" & Hex($getcolour,7),10,1) ; Look for user selected color in a large area in the center of the screen

            If @error <> 1 Then ExitLoop ; When color is found, bail out of the loop to start looking for splash
            If TimerDiff($timer) > 10000 Then
                GUICtrlSetData($Statuslable, "Status: Blobber not found!")
                $castfail += 1
                ;----------------------------------------
                Sleep(1000)
                WinActivate("World of Warcraft")
                ExitLoop 2
            EndIf
        Wend
        $timer = TimerInit() ; Set a timeout for finding splash
        MouseMove($bobber[0], $bobber[1]) ; Move the mouse to the bobber (so the user knows what this script is looking at, and hopefully doesn't move the mouse)
        While -1
            GUICtrlSetData($Statuslable, "Status: Searching for Splash...")
            $splash = PixelSearch($bobber[0]-10,$bobber[1]-10,$bobber[0]+10,$bobber[1]+10,"0x" & Hex($color,6),10,1) ; Search a tiny 20x20 square for the bobber color
            If @error = 1 Then ExitLoop ; When the color isn't found, the bobber just bobbed (Splash Detected!)
            If TimerDiff($timer) > 13150 Then
                GUICtrlSetData($Statuslable, "Status: Splash not found!")
                $castfail += 1
                ;------------------------------------
                Sleep(1000)
                WinActivate("World of Warcraft")
                Exitloop 2
            EndIf
        Wend
        GUICtrlSetData($Statuslable, "Status: Splash Detected!")
        Sleep(Random(23,98))
        MouseClick("Right", $bobber[0], $bobber[1], 1, 0) ; Even if the user moves the mouse, this instantly moves it to the bobber and right-clicks
        Sleep(2000)
        GUICtrlSetData($Statuslable, "Status: Waiting to fish again")
        Sleep(1000)
    Wend
Wend
        
EndFunc

Func _checkbait()
    $TimeMil = TimerDiff($Baittimer)
    If $TimeMil>=9.5 * 60 * 1000 Then ; check if bait is gone
        If $bait = "None" Then
                sleep(1000)
        Else
        GUICtrlSetData($Statuslable, "Status: Equiping Bait")
        Send("/use " & $bait &  "{Enter}")
        Send("/use 16 {Enter}")
        $Baittimer = TimerInit()
        $numofbait +=1
        Sleep(1000)
        $Baittimer = TimerInit(); RESET TIMER
        EndIf
    EndIf
EndFunc

; Quit the script when the user presses {pause}
Func Quit()
    Exit
EndFunc

Thanks

Edited by Rorka
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...