Thread Rating:
  • 40 Vote(s) - 4.78 Average
  • 1
  • 2
  • 3
  • 4
  • 5
5.4.2.5.2 - Better Troops Deployment (LF Style), Fixed Train Troops
ALERT: long post

1. LocateTH
i've written this function and put a button to trigger it manually while visiting a village for testing purposes. what am i missing?
running 32bit exe, no th found. is there some other functions /variables to initiate before _CaptureRegion() ?

Code:
Func LocateTH() ; locates TH

Global $atkTHs[5] = [$atkTH6,$atkTH7,$atkTH8,$atkTH9,$atkTH10]

   _CaptureRegion()
   $THLocation1 = 0
   $searchTH1 = "-"
   for $i = 0 to 4
      $THLocation1 = _ImageSearch($atkTHs[$i], 1, $THx1, $THy1, $Tolerance1) ; Getting TH Location
      If $THLocation1 = 1 Then
         if $i = 0 Then
            $searchTH1 = '"4-' & $i+6 & '"'
         Else
            $searchTH1 = '"' & $i+6 & '"'
         EndIf
         ExitLoop
      EndIf
   Next
   If $THx1 > 227 And $THx1 < 627 And $THy1 > 151 And $THy1 < 419 And $searchTH1 <> "-" Then
    $THLoc1 = "Inside"
    Else
        $THLoc1 = "Outside"
    EndIf
    SetLog("located townhall: " & $searchTH1 & " @" & $THx1 & "," & $THy1 & ". It's " & $THLoc1)
EndFunc
this is the output
Code:
located townhall: - @0,0. It's -

2. revised CompareResources
this is my revised CompareResources to meet ALL conditions specified - (gold/elixir AND max th) - for example.
Code:
Func CompareResources() ;Compares resources and returns true if conditions meet, otherwise returns false
    If GUICtrlRead($chkMeetTH) <> $GUI_CHECKED Then
        $MaxTH = "-"
    EndIf
    If $SearchCount <> 0 And Mod($SearchCount, 20) = 0 Then
        If $MinGold - 2000 >= 0 Then $MinGold -= 2000
        If $MinElixir - 2000 >= 0 Then $MinElixir -= 2000
        If $MinDark - 100 >= 0 Then $MinDark -= 100
        If $MinTrophy - 2 >= 0 Then $MinTrophy -= 2
        SetLog("~Gold: " & $MinGold & "; Elixir: " & $MinElixir & "; Dark: " & $MinDark & "; Trophy: " & $MinTrophy & "; Townhall: " & $MaxTH)
    EndIf

    Local $G = (Number($searchGold) >= Number($MinGold)), $E = (Number($searchElixir) >= Number($MinElixir)), $D = (Number($searchDark) >= Number($MinDark)), $T = (Number($searchTrophy) >= Number($MinTrophy))
    Local $THL = -1, $THLO = -1

    Switch $searchTH
        Case "4-6"
            $THL = 0
        Case "7"
            $THL = 1
        Case "8"
            $THL = 2
        Case "9"
            $THL = 3
        Case "10"
            $THL = 4
         EndSwitch

    Switch $THLoc
        Case "Inside"
            $THLO = 0
      Case "Outside"
            $THLO = 1
         EndSwitch


    Local $chkMeetGxE_bool = True
    Local $chkMeetDE_bool = True
    Local $chkMeetTrophy_bool = True
    Local $chkMeetGorE_bool = True
    Local $chkMeetTH_bool = True
    Local $chkMeetTHO_bool = True

    If GUICtrlRead($chkMeetGxE) = $GUI_CHECKED Then
        If $G = False Or $E = False Then
            $chkMeetGxE_bool = False


        EndIf
    EndIf

    If GUICtrlRead($chkMeetDE) = $GUI_CHECKED Then
        If $D = False Then
            $chkMeetDE_bool = False


        EndIf
    EndIf

    If GUICtrlRead($chkMeetTrophy) = $GUI_CHECKED Then
        If $T = False Then
            $chkMeetTrophy_bool = False


        EndIf
     EndIf

    If GUICtrlRead($chkMeetGorE) = $GUI_CHECKED Then
        If $G = False And $E = False Then
            $chkMeetGorE_bool = False


        EndIf
     EndIf

    If GUICtrlRead($chkMeetTH) = $GUI_CHECKED Then
        If $THL > _GUICtrlComboBox_GetCurSel($cmbTH) And ZombieSearch() = False Then
            $chkMeetTH_bool = False
        EndIf
     EndIf

    If GUICtrlRead($chkMeetTHO) = $GUI_CHECKED Then
        If $THLO <> 1 Then
            $chkMeetTHO_bool = False
        EndIf
     EndIf

    Local $Boolean = $chkMeetGxE_bool And $chkMeetDE_bool And $chkMeetTrophy_bool And $chkMeetGorE_bool And $chkMeetTH_bool And $chkMeetTHO_bool
    Return $Boolean
EndFunc   ;==>CompareResources

please note i've added the option to attack the base even if th > than specified IF that village is deadbase. don't know if could work as i'm having problems with deadbase/imagesearch as per first point

3. other issues
a. i would like to take screenshots of what the bot considers zombies or not dead bases when attacking with the option deadbase, testing purposes. this is what i've added
Code:
DirCreate(@ScriptDir & "\Dead\")
DirCreate(@ScriptDir & "\unDead\")
and the modified villagesearch
Code:
Func VillageSearch() ;Control for searching a village that meets conditions
    While 1
        Switch $iradAttackMode
            Case 0
                SetLog("============Searching For Dead Base============")
            Case 1
                SetLog("============Searching For Weak Base============")
            Case 2
                SetLog("============Searching For All Base============")
        EndSwitch
        SetLog("~Gold: " & $MinGold & "; Elixir: " & $MinElixir & "; Dark: " & $MinDark & "; Trophy: " & $MinTrophy & "; Townhall: " & $MaxTH)

        $SearchCount = 0
        $OptimizeSleep = 0
        While 1
            If _Sleep(1000) Then ExitLoop (2)
            GetResources() ;Reads Resource Values

            If $Restart = True Then ExitLoop (2)
            If CompareResources() Then
                If $iradAttackMode = 0 Then
                    If ZombieSearch() Then
                        SetLog("~~~~~~~Dead Base Found!~~~~~~~")
                        Local $Date = @MDAY & "." & @MON & "." & @YEAR
                        Local $Time = @HOUR & "." & @MIN& "." & @SEC
                        _CaptureRegion()
                        _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Dead\" & $Date & " at " & $Time & ".jpg")
                        ExitLoop
                    Else
                        SetLog("~~~~~~~Not dead base, skipping~~~~~~~")
                        Local $Date = @MDAY & "." & @MON & "." & @YEAR
                        Local $Time = @HOUR & "." & @MIN & "." & @SEC
                        _CaptureRegion()
                        _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\unDead\" & $Date & " at " & $Time & ".jpg")
                        Click(750, 500) ;Click Next
                    EndIf
                Else
                    ExitLoop
                EndIf
            Else
                Click(750, 500) ;Click Next
            EndIf
        WEnd
        If GUICtrlRead($chkAlertSearch) = $GUI_CHECKED Then
            TrayTip("Match Found!", "Gold: " & $searchGold & "; Elixir: " & $searchElixir & "; Dark: " & $searchDark & "; Trophy: " & $searchTrophy & "; Townhall: " & $searchTH & "", 0)
            If FileExists(@WindowsDir & "\media\Windows Exclamation.wav") Then
               SoundPlay(@WindowsDir & "\media\Windows Exclamation.wav", 1)
            Else
               SoundPlay(@WindowsDir & "\media\Festival\Windows Exclamation.wav", 1)
            EndIf
        EndIf
        SetLog("===============Searching Complete===============")
        readConfig()
        ExitLoop
    WEnd
EndFunc   ;==>VillageSearch

b.troop donation
i found out my clanmate with 30 spaces in clan castle wasn't getting troops donated. the solution has been to change every occurrence of
Code:
                            Click(($DonateTroop[0]+200), ($DonateTroop[1]-20),5) ; donate archer

with
Code:
                            Click(($DonateTroop[0]+200), ($DonateTroop[1]-30),5) ; donate archer

it seems to work fine with this change for everyone.

c. Train()
you have missed the last click to close the 4th barrack so the bot behaves weird
this is just the end of the function with the 2 lines to add back
Code:
EndIf
            If _Sleep(500) Then ExitLoop (2)
            Click(1, 1, 2, 250); Click away twice with 250ms delay
        Next

        SetLog("Training Troops Complete")
        ExitLoop
    WEnd
EndFunc   ;==>Train

d. idle()
i was thinking, is the "if" statement outside the "while" one necessary?
Code:
If $fullArmy = False Then
            While $fullArmy = False
by looking at the function i would say no, so we could clean more code

that's almost all, for now
 


Messages In This Thread
Edited bot - by saxmydix - 01-27-2015, 01:28 AM
RE: 5.4.2.2.2 - by saxmydix - 01-27-2015, 01:58 PM
RE: 5.4.2.2.2 + - by saxmydix - 01-29-2015, 06:03 PM
RE: 5.4.2.2.2 - Looking @ dropCC - by LiveToDrink - 01-30-2015, 12:55 PM
TRAIN SPEED - by kennethwut - 02-01-2015, 07:18 AM
Crash on deploying Wall Breakers - by clarkii - 02-01-2015, 07:05 AM
RE: 5.4.2.4 Safar46's Mods - - by saxmydix - 02-01-2015, 01:07 PM
RE: 5.4.2.4 Safar46's Mods - Fix Deadbase search, Use barracks troops, and more fixed... - by indy - 02-01-2015, 01:06 PM
RE: 5.4.2.4.3 - Fix Attack Townhall - by promac - 02-03-2015, 12:12 AM
RE: 5.4.2.4.3 - by promac - 02-03-2015, 01:29 AM
RE: 5.4.2.4.3 - by promac - 02-03-2015, 01:40 AM
RE: - by promac - 02-03-2015, 03:48 AM
RE: 5.4.2.4.4 - Fixed Locate Collectors - by BoBz - 02-03-2015, 04:02 AM
RE: 5.4.2.5 - by indy - 02-03-2015, 08:36 PM
RE: 5.4.2.5 - - by indy - 02-03-2015, 09:35 PM

Forum Jump:


Users browsing this thread: 70 Guest(s)

About The Bytecode Club

We're a community forum focused on Reverse Engineering, we try to target Java/Android but we also include other langauges/platforms. We pride ourselves in supporting and free and open sourced applications.

Website