Jump to content
Sign in to follow this  
mcdohl

Help request on repeating loop coding please

Recommended Posts

mcdohl

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

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×