Jump to content

Help request on repeating loop coding please


mcdohl
 Share

Recommended Posts

Hi,

I have done up the script (credit to Ewlyx for the reference for his original script) for a simple game and works fine, however now i would like it to repeat the whole script repetitively after the previous one ends. Please assist :D

;X Coords Input on 1680x1050 :  1518x198
;Y Coords Input on 1680x1050 :  1553x198

$Version = "1.1.0a"
Global $Paused
Global $gX = 0
Global $gY = 0
Global $c1X = 0
Global $c1Y = 0
Global $c2X = 0
Global $c2Y = 0
Global $success = False ;boolean for various checks
Global $managogFound = False ;flag for when a managog is found by _ImageSearch
Global $tolFail = 0 ;tolerance failures for _ImageSearch
Global $troopRecruitY = 0 ;Y coordinate of specified troop portrait in recruit troops window
Global $searchCoordsFound = False
$bmpLocation = @ScriptDir & "\Pics"
$managogsDir = "Managogs"
$buttonsDir = "Buttons"

;===========================================================================================================
;User Defined Variables

Global $mapX = 25 ;change this to the x coordinate of the map that your character is in. map starts at 15, goes to 585
Global $mapY = 15 ;change this to the x coordinate of the map that your character is in. map starts at 8, goes to 591
$collectTreasure = True ;set to True if you want to attack treasure caches as well, False if do not
$troops = "templar" ;set this to the troops you are using i.e. "templar" or "warlock"
$defaultCheckRate = .2 ;smaller the number, the faster the image checks are.  increase if managogs aren't being found.

;===========================================================================================================
;HotKeys

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("q","RunScript")
HotKeySet("x","ChangeCoords")

;===========================================================================================================
;~Functions

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Func CheckFor($directory,$img,$tolerance=50,$startX=0,$startY=0,$endX=@DesktopWidth,$endY=@DesktopHeight,$seconds=$defaultCheckRate)
    $c = 0
    $string = $bmpLocation & "\" & $directory & "\" & $img & ".bmp"
    $updateString = $img
    ToolTip("Checking for " & $updateString,0,0)
    $tolerance = 70
    If $tolFail > 0 Then
        $tolerance += $tolFail
    EndIf
    Do
        $c += 1
        Sleep(100)
        If $c > ($seconds * 10) Then
            Return False
        EndIf
    ;Until _ImageSearchArea($string,1,$startX,$startY,$endX,$endY,$gX,$gY,$tolerance)
    Until _ImageSearchArea($string,1,216,180,1723,1002,$gX,$gY,$tolerance)
    If $img = "daily" Then
        $sX = $gX
        $sY = $gY
    EndIf
    Sleep(500)
    Return True
EndFunc

Func ClickImage($directory,$img,$tolerance=50,$startX=0,$startY=0,$endX=@DesktopWidth,$endY=@DesktopHeight,$seconds=$defaultCheckRate)
    If CheckFor($directory,$img,$tolerance,$startX,$startY,$endX,$endY,$seconds) Then
        MouseClick("left",$gX,$gY,1,0)
        Return True
    Else
        Return False
    EndIf
EndFunc 

Func HoverOverImage($directory,$img,$tolerance=50,$startX=0,$startY=0,$endX=@DesktopWidth,$endY=@DesktopHeight,$seconds=$defaultCheckRate)
    If CheckFor($directory,$img,$startX,$startY,$endX,$endY,$seconds,$tolerance) Then
        MouseMove($gX,$gY,0)
        Sleep(2000)
        Return True
    Else
        Return False
    EndIf
EndFunc

Func ClickOffsetOfImage($direction,$offset,$directory,$img,$clicks=1,$tolerance=50,$startX=0,$startY=0,$endX=@DesktopWidth,$endY=@DesktopHeight,$seconds=$defaultCheckRate)
    If CheckFor($directory,$img,$startX,$startY,$endX,$endY,$seconds,$tolerance) Then
        If $direction = "right" Then
            $gX += $offset
        ElseIf $direction = "left" Then
            $gX -= $offset
        ElseIf $direction = "up" Then
            $gY -= $offset
        ElseIf $direction = "down" Then
            $gY += $offset
        EndIf
        MouseClick("left",$gX,$gY,$clicks,0)
        Return True
    Else
        Return False
    EndIf
EndFunc

Func SearchForAttackSword()
    ;Searches for the sword icon.  Used to make sure SearchForManagogs() actually found something.
    If CheckFor($managogsDir,"attackingsword") Or CheckFor($managogsDir,"attackingsword2") Or CheckFor($managogsDir,"attackingsword3") Then
        Return True
    Else
        Return False
    EndIf
EndFunc
    
Func SearchForManagogs()
    ;Iterates through each managog bitmap until it finds one.  Returns false if it doesn't.
    If ClickImage($managogsDir,"pan") Or ClickImage($managogsDir,"pan2") Or ClickImage($managogsDir,"pan3") Or ClickImage($managogsDir,"pan4")Then
        Return True
    ElseIf ClickImage($managogsDir,"iris") Or ClickImage($managogsDir,"iris2") Then
        Return True
    Else
        Return False
    EndIf
EndFunc

Func WaitForAttack()
    ;Waits for your character to get to the managog. If the attack button does not appear after 1 min, it will search for and click on the managog again.
    If ClickImage($buttonsDir,"attack",0,0,@DesktopWidth,@DesktopHeight,1,50) Then
        $success = True
        Sleep(2000)
    Else
        $success = False
    EndIf
EndFunc

Func RunScript()
    ;Main script activated by hotkey
    SearchForManagogs()
EndFunc 

;===========================================================================================================
;Main

While 1
    ToolTip("Press 'q' to begin...",0,0)
    Sleep(100)
WEnd
Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Please read the forum rules (a link can be found at the bottom right of each page) expecially the part about game automation and you will understand why you won't get any help on this subject here.

To cite Melba23: "Hope to see you soon with a legitimate question :) "

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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