Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #RequireAdmin
 - #include <StaticConstants.au3>
 - #include <ButtonConstants.au3>
 - #include <ComboConstants.au3>
 - #include <GuiComboBox.au3>
 - #include <GUIConstantsEx.au3>
 - #include <EditConstants.au3>
 - #include <WindowsConstants.au3>
 - #include <TrayConstants.au3>
 - #include <Misc.au3>
 - #include "Tesseract-OCR\Tesseract.au3"
 - Opt ("GUIOnEventMode", 1)
 - Opt ("MouseClickDelay", 10)
 - Opt ("MouseClickDownDelay", 10)
 - Opt ("MouseCoordMode", 0)
 - Opt ('PixelCoordMode', 0)
 - GUIRegisterMsg($WM_COMMAND, "GUIControl")
 - GUIRegisterMsg($WM_SYSCOMMAND, "GUIControl")
 - Global $Title = "BlueStacks App Player"
 - Global $HWnD = WinGetHandle (WinGetTitle($Title))
 - WinActivate ($HWnD)
 - Global $RunState = False
 - Global $Gold, $Elixir, $MinGold = 80000, $MinElixir = 80000, $SearchMode = 1, $SearchCheck = 0, $SearchCount = 0
 - Global $Attack = 0xF0E5D6, $FindAMatch = 0xF8E0A7
 - Global $Config = @ScriptDir & "\config.ini"
 - Global $Left = 47, $Top = 69, $Right = 660, $Bottom = 518
 - Global $BSsize = WinGetClientSize($hWnd)
 - Global $x_ratio = $BSsize[0]/800, $y_ratio = $BSsize[1]/600
 - Global $Troop[5][2] = [[60*$x_ratio,505*$y_ratio],[130*$x_ratio,505*$y_ratio],[200*$x_ratio,505*$y_ratio],[265*$x_ratio,505*$y_ratio],[372*$x_ratio,505*$y_ratio]]
 - Global $Barbarian[2] = [0,0], $Archer[2] = [0,0], $Golbin[2] =[0,0], $Giant[2] = [0,0]
 - Global $B1Pos[2] = [0,0], $B2Pos[2] = [0,0], $B3Pos[2] = [0,0], $B4Pos[2] = [0,0]
 - Global $B1Troop, $B2Troop, $B3Troop, $B4Troop
 - Global $UpLeft[5][2] = [[350*$x_ratio,51*$y_ratio],[230*$x_ratio,100*$y_ratio],[186*$x_ratio,160*$y_ratio],[144*$x_ratio,187*$y_ratio],[125*$x_ratio,200*$y_ratio]]
 - Global $UpRight[5][2] = [[460*$x_ratio,62*$y_ratio],[520*$x_ratio,97*$y_ratio],[570*$x_ratio,134*$y_ratio],[647*$x_ratio,186*$y_ratio],[692*$x_ratio,211*$y_ratio]]
 - Global $LowLeft[5][2] = [[77*$x_ratio, 306*$y_ratio],[130*$x_ratio,353*$y_ratio],[181*$x_ratio,395*$y_ratio],[214*$x_ratio,415*$y_ratio],[250*$x_ratio,442*$y_ratio]]
 - Global $LowRight[5][2] = [[734*$x_ratio,290*$y_ratio],[685*$x_ratio,318*$y_ratio],[630*$x_ratio,350*$y_ratio],[600*$x_ratio,369*$y_ratio],[535*$x_ratio,425*$y_ratio]]
 - #Region ##### GUI #####
 - $BotGUI = GUICreate("Clash of Clans Bot", 300, 500)
 - GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
 - GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")
 - $Button = GUICtrlCreateButton("START", 20, 450, 260, 40)
 - GUICtrlSetOnEvent(-1, "Start")
 - $MeetAll = GUICtrlCreateCheckbox("Meet all conditions", 30, 30, 140, 17)
 - GUICtrlSetState(-1, $GUI_CHECKED)
 - GUICtrlCreateLabel("Min Gold:", 30, 58, 58, 17)
 - $MinGoldInput = GUICtrlCreateInput("", 80, 54, 55, 21, $ES_NUMBER)
 - GUICtrlSetLimit(-1, 6)
 - GUICtrlSetData(-1, $MinGold)
 - GUICtrlCreateLabel("Min Elixir:", 30, 82, 57, 17)
 - $MinElixirInput = GUICtrlCreateInput("", 80, 78, 55, 21, $ES_NUMBER)
 - GUICtrlSetLimit(-1, 6)
 - GUICtrlSetData(-1, $MinElixir)
 - $Barrack01 = GUICtrlCreateCombo("Barrack 01", 175, 20, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
 - GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
 - _GUICtrlComboBox_SelectString(-1, "Barbarian")
 - $Barrack02 = GUICtrlCreateCombo("Barrack 02", 175, 46, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
 - GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
 - _GUICtrlComboBox_SelectString(-1, "Barbarian")
 - $Barrack03 = GUICtrlCreateCombo("Barrack 03", 175, 72, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
 - GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
 - _GUICtrlComboBox_SelectString(-1, "Archer")
 - $Barrack04 = GUICtrlCreateCombo("Barrack 04", 175, 98, 80, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
 - GUICtrlSetData(-1, "Barbarian|Archer|Goblin|Giant")
 - _GUICtrlComboBox_SelectString(-1, "Giant")
 - $Results = GUICtrlCreateEdit("", 20, 140, 260, 300, BitOR($SS_SUNKEN,$ES_READONLY, $SS_LEFT))
 - GUISetState(@SW_SHOW)
 - WinActivate($BotGUI)
 - #EndRegion ##### GUI #####
 - While 1
 - $Msg = GUIGetMsg()
 - WEnd
 - Func GUIControl($hWind, $iMsg, $wParam, $lParam)
 - Local $nNotifyCode = BitShift($wParam, 16)
 - Local $nID = BitAND($wParam, 0x0000FFFF)
 - Local $hCtrl = $lParam
 - #forceref $hWind, $iMsg, $wParam, $lParam
 - Switch $iMsg
 - Case 273
 - Switch $nID
 - Case $Button
 - $RunState = Not $RunState
 - If $RunState = True Then
 - GUICtrlSetData($Button,"STOP")
 - GUICtrlSetData($Results, "Bot Started.." & @CRLF, -1)
 - ElseIf $RunState = False Then
 - GUICtrlSetData($Button,"START")
 - GUICtrlSetData($Results, "Bot Stopped" & @CRLF, -1)
 - EndIf
 - EndSwitch
 - Case 274
 - Switch $wParam
 - Case 0xf060
 - Exit
 - EndSwitch
 - EndSwitch
 - Return $GUI_RUNDEFMSG
 - EndFunc
 - Func Start()
 - Sleep(1000)
 - While 1
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - MainScreen() ;Check if main screen
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - GetInput() ;Read user's input
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - ZoomOut()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - LocateBarrack() ;If barrack not located, ask user to manually click on barrack to locate position
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Train() ;Locate Barrack, Train Barrack
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Idle(900)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Attack() ;Prepare Attack, Read Value, Compute Value, Compare Value, Search Village, Drop Troop, Return Home
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - WEnd
 - EndFunc
 - Func GetInput()
 - $B1Troop = GUICtrlRead($Barrack01)
 - $B2Troop = GUICtrlRead($Barrack02)
 - $B3Troop = GUICtrlRead($Barrack03)
 - $B4Troop = GUICtrlRead($Barrack04)
 - $MinGold = Number(GUICtrlRead($MinGoldInput))
 - $MinElixir = Number(GUICtrlRead($MinElixirInput))
 - If GUICtrlRead($MeetAll) = $GUI_CHECKED Then
 - $SearchMode = 2
 - Else
 - $SearchMode = 1
 - EndIf
 - $B1Pos[0] = IniRead($Config, "Barrack 01", "X", "0")
 - $B1Pos[1] = IniRead($Config, "Barrack 01", "Y", "0")
 - $B2Pos[0] = IniRead($Config, "Barrack 02", "X", "0")
 - $B2Pos[1] = IniRead($Config, "Barrack 02", "Y", "0")
 - $B3Pos[0] = IniRead($Config, "Barrack 03", "X", "0")
 - $B3Pos[1] = IniRead($Config, "Barrack 03", "Y", "0")
 - $B4Pos[0] = IniRead($Config, "Barrack 04", "X", "0")
 - $B4Pos[1] = IniRead($Config, "Barrack 04", "Y", "0")
 - GUICtrlSetData($Results, "Barracks' position loaded successfully" & @CRLF & "Barrack 01: " & $B1Pos[0] & ", " & $B1Pos[1] & @CRLF, -1)
 - GUICtrlSetData($Results, "Barrack 02: " & $B2Pos[0] & ", " & $B2Pos[1] & @CRLF, -1)
 - GUICtrlSetData($Results, "Barrack 03: " & $B3Pos[0] & ", " & $B3Pos[1] & @CRLF, -1)
 - GUICtrlSetData($Results, "Barrack 04: " & $B4Pos[0] & ", " & $B4Pos[1] & @CRLF, -1)
 - EndFunc
 - #Region ##### TRAIN #####
 - Func LocateBarrack()
 - Local $ClickCheck, $LocateCheck = 0
 - While 1
 - While 1
 - If $RunState = False Then
 - ExitLoop(2)
 - EndIf
 - If $B1Pos[0] = 0 Then
 - $ClickCheck = MsgBox(6+65536, "Locate first barrack", "Click Continue then click on your first barrack. Cancel if not available. Try again to start over.", 0, $BotGUI)
 - If $ClickCheck = 11 Then
 - WinActivate ($HWnD)
 - FindPos($B1Pos)
 - IniWrite ($Config, "Barrack 01", "X", $B1Pos[0])
 - IniWrite ($Config, "Barrack 01", "Y", $B1Pos[1])
 - ElseIf $ClickCheck = 10 Then
 - $B1Pos[0] = 0
 - $B2Pos[0] = 0
 - $B3Pos[0] = 0
 - $B4Pos[0] = 0
 - ExitLoop
 - EndIf
 - Sleep(500)
 - EndIf
 - If $RunState = False Then
 - ExitLoop(2)
 - EndIf
 - If $B2Pos[0] = 0 Then
 - $ClickCheck = MsgBox(6+65536, "Locate second barrack", "Click Continue then click on you second barrack. Cancel if not available. Try again to start over.", 0, $BotGUI)
 - If $ClickCheck = 11 Then
 - WinActivate ($HWnD)
 - FindPos($B2Pos)
 - IniWrite ($Config, "Barrack 02", "X", $B2Pos[0])
 - IniWrite ($Config, "Barrack 02", "Y", $B2Pos[1])
 - ElseIf $ClickCheck = 10 Then
 - $B1Pos[0] = 0
 - $B2Pos[0] = 0
 - $B3Pos[0] = 0
 - $B4Pos[0] = 0
 - ExitLoop
 - EndIf
 - Sleep(500)
 - EndIf
 - If $RunState = False Then
 - ExitLoop(2)
 - EndIf
 - If $B3Pos[0] = 0 Then
 - $ClickCheck = MsgBox(6+65536, "Locate third barrack", "Click Continue then click on your third barrack. Cancel if not available. Try again to start over.", 0, $BotGUI)
 - If $ClickCheck = 11 Then
 - WinActivate ($HWnD)
 - FindPos($B3Pos)
 - IniWrite ($Config, "Barrack 03", "X", $B3Pos[0])
 - IniWrite ($Config, "Barrack 03", "Y", $B3Pos[1])
 - ElseIf $ClickCheck = 10 Then
 - $B1Pos[0] = 0
 - $B2Pos[0] = 0
 - $B3Pos[0] = 0
 - $B4Pos[0] = 0
 - ExitLoop
 - EndIf
 - Sleep(500)
 - EndIf
 - If $RunState = False Then
 - ExitLoop(2)
 - EndIf
 - If $B4Pos[0] = 0 Then
 - $ClickCheck = MsgBox(6+65536, "Locate fourth barrack", "Click Continue then click on your fourth barrack. Cancel if not available. Try again to start over.", 0, $BotGUI)
 - If $ClickCheck = 11 Then
 - WinActivate ($HWnD)
 - FindPos($B4Pos)
 - IniWrite ($Config, "Barrack 04", "X", $B4Pos[0])
 - IniWrite ($Config, "Barrack 04", "Y", $B4Pos[1])
 - ElseIf $ClickCheck = 10 Then
 - $B1Pos[0] = 0
 - $B2Pos[0] = 0
 - $B3Pos[0] = 0
 - $B4Pos[0] = 0
 - ExitLoop
 - EndIf
 - Sleep(500)
 - EndIf
 - ExitLoop(2)
 - WEnd
 - WEnd
 - EndFunc
 - Func TrainBarrack($x, $y, $z)
 - While 1
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - ControlClick ($HWnD, "","", "left", "1", $x, $y)
 - Sleep(1000)
 - ControlClick ($HWnD, "","", "left", "1", 560*$x_ratio, 490*$y_ratio)
 - Sleep(1000)
 - Select
 - Case $z = "Barbarian"
 - For $i = 1 To 65 Step 1
 - ControlClick ($HWnD, "","", "left", "1", 220*$x_ratio, 270*$y_ratio)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(50)
 - Next
 - Case $z = "Archer"
 - For $i = 1 To 65 Step 1
 - ControlClick ($HWnD, "","", "left", "1", 310*$x_ratio, 270*$y_ratio)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(50)
 - Next
 - Case $z = "Goblin"
 - For $i = 1 To 65 Step 1
 - ControlClick ($HWnD, "","", "left", "1", 490*$x_ratio, 270*$y_ratio)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(50)
 - Next
 - Case $z = "Giant"
 - For $i = 1 To 15 Step 1
 - ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 270*$y_ratio)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(50)
 - Next
 - EndSelect
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(1000)
 - ControlClick ($HWnD, "","", "left", "1", 656*$x_ratio, 113*$y_ratio)
 - Sleep(1000)
 - ExitLoop
 - WEnd
 - EndFunc
 - Func Train()
 - GUICtrlSetData("Begin training" & @CRLF, -1)
 - If $B1Pos[0] <> 0 Then
 - TrainBarrack($B1Pos[0],$B1Pos[1],$B1Troop)
 - EndIf
 - If $B2Pos[0] <> 0 Then
 - TrainBarrack($B2Pos[0],$B2Pos[1],$B2Troop)
 - EndIf
 - If $B3Pos[0] <> 0 Then
 - TrainBarrack($B3Pos[0],$B3Pos[1],$B3Troop)
 - EndIf
 - If $B4Pos[0] <> 0 Then
 - TrainBarrack($B4Pos[0],$B4Pos[1],$B4Troop)
 - EndIf
 - EndFunc
 - #EndRegion ##### TRAIN #####
 - #Region ##### ATTACK #####
 - Func Attack()
 - While 1
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - AssignTroop()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - PrepareAttack()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - GUICtrlSetData("Attack started. Begin searching.." & @CRLF, -1)
 - VillageSearch()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - GUICtrlSetData("Enemy Found! Prepare to drop troops" & @CRLF, -1)
 - DropTroop()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - ReturnHome()
 - ExitLoop
 - WEnd
 - EndFunc
 - Func PrepareAttack()
 - While 1
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Button($Attack)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Button($FindAMatch)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(2000)
 - ControlClick ($HWnD, "","", "left", "1", 470*$x_ratio, 330*$y_ratio) ;Click Break Shield
 - ExitLoop
 - WEnd
 - EndFunc
 - Func CheckSearch()
 - $Pixel = PixelSearch(0,0,900,700,0x0D355B,0,1,$HWnD) ;End Battle Button
 - While Not IsArray($Pixel)
 - $Pixel = PixelSearch(0,0,900,700,0x0D355B,0,1,$HWnD) ;End Battle Button
 - Sleep(200)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - WEnd
 - EndFunc
 - Func VillageSearch()
 - While 1
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - CheckSearch()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - ComputeValue()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - CompareValue()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - While $SearchCheck = 0
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - ControlClick ($HWnD, "","", "left", "1", 715*$x_ratio, 405*$y_ratio) ;Click Next
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - CheckSearch()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - ComputeValue()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - CompareValue()
 - WEnd
 - TrayTip ("Enemy Found!","Requirement met: Gold: " & $Gold & ". Elixir: " & $Elixir, 0, $TIP_ICONASTERISK)
 - Sleep(5000)
 - ExitLoop
 - WEnd
 - EndFunc
 - Func CheckTroop($a)
 - If $B1Troop = $a Or $B2Troop = $a Or $B3Troop = $a Or $B4Troop = $a Then
 - Return True
 - Else
 - Return False
 - EndIf
 - EndFunc
 - Func AssignTroop()
 - If CheckTroop("Barbarian") Then
 - $Barbarian[0] = $Troop[0][0]
 - $Barbarian[1] = $Troop[0][1]
 - If CheckTroop("Archer") Then
 - $Archer[0] = $Troop[1][0]
 - $Archer[1] = $Troop[1][1]
 - If CheckTroop("Goblin") Then
 - $Goblin[0] = $Troop[2][0]
 - $Goblin[1] = $Troop[2][1]
 - If CheckTroop("Giant") Then
 - $Giant[0] = $Troop[3][0]
 - $Giant[1] = $Troop[3][1]
 - ;MsgBox(0,"","Barbarian, Archer, Goblin, Giant")
 - EndIf
 - ElseIf CheckTroop("Giant") Then
 - $Giant[0] = $Troop[2][0]
 - $Giant[1] = $Troop[2][1]
 - ;MsgBox(0,"","Barbarian, Archer, Giant")
 - EndIf
 - ElseIf CheckTroop("Goblin") Then
 - $Goblin[0] = $Troop[1][0]
 - $Goblin[1] = $Troop[1][1]
 - If CheckTroop("Giant") Then
 - $Giant[0] = $Troop[2][0]
 - $Giant[1] = $Troop[2][1]
 - ;MsgBox(0,"","Barbarian, Goblin, Giant")
 - EndIf
 - ElseIf CheckTroop("Giant") Then
 - $Giant[0] = $Troop[1][0]
 - $Giant[1] = $Troop[1][1]
 - ;MsgBox(0,"","Barbarian, Giant")
 - EndIf
 - ElseIf CheckTroop("Archer") Then
 - $Archer[0] = $Troop[0][0]
 - $Archer[1] = $Troop[0][1]
 - If CheckTroop("Goblin") Then
 - $Goblin[0] = $Troop[1][0]
 - $Goblin[1] = $Troop[1][1]
 - If CheckTroop("Giant") Then
 - $Giant[0] = $Troop[2][0]
 - $Giant[1] = $Troop[2][1]
 - ;MsgBox(0,"","Archer, Goblin, Giant")
 - EndIf
 - ElseIf CheckTroop("Giant") Then
 - $Giant[0] = $Troop[1][0]
 - $Giant[1] = $Troop[1][1]
 - ;MsgBox(0,"","Archer, Giant")
 - EndIf
 - ElseIf CheckTroop("Goblin") Then
 - $Goblin[0] = $Troop[0][0]
 - $Goblin[1] = $Troop[0][1]
 - If CheckTroop("Giant") Then
 - $Giant[0] = $Troop[1][0]
 - $Giant[1] = $Troop[1][1]
 - ;MsgBox(0,"","Goblin, Giant")
 - EndIf
 - ElseIf CheckTroop("Giant") Then
 - $Giant[0] = $Troop[0][0]
 - $Giant[1] = $Troop[0][1]
 - ;MsgBox(0,"","Giant")
 - EndIf
 - EndFunc
 - Func DropTroop()
 - While 1
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropCombo($UpLeft)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropCombo($UpRight)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropCombo($UpLeft)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropCombo($UpRight)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropSingle("Giant",$UpLeft)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropSingle("Giant",$UpRight)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropSingle("Barbarian",$UpLeft)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropSingle("Archer",$UpLeft)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropSingle("Barbarian",$UpRight)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropSingle("Barbarian",$UpLeft)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - DropSingle("Archer",$UpRight)
 - ExitLoop
 - WEnd
 - EndFunc
 - Func DropSingle($T, $W)
 - While 1
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - If CheckTroop($T) Then
 - Select
 - Case $T = "Giant"
 - ControlClick ($HWnD, "","", "left", "1", $Giant[0], $Giant[1])
 - Sleep(300)
 - For $i = 1 to 3 Step 1
 - ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
 - Sleep(100)
 - Next
 - Sleep(300)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Case $T = "Barbarian"
 - ControlClick ($HWnD, "","", "left", "1", $Barbarian[0], $Barbarian[1])
 - Sleep(300)
 - For $x = 0 to 2 Step 1
 - For $i = 0 to 4 Step 1
 - ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
 - Sleep(100)
 - Next
 - Next
 - Sleep(300)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Case $T = "Archer"
 - ControlClick ($HWnD, "","", "left", "1", $Archer[0], $Archer[1])
 - Sleep(300)
 - For $x = 0 to 2 Step 1
 - For $i = 0 to 4 Step 1
 - ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
 - Sleep(100)
 - Next
 - Next
 - Sleep(300)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Case $T = "Goblin"
 - ControlClick ($HWnD, "","", "left", "1", $Goblin[0], $Goblin[1])
 - Sleep(300)
 - For $x = 0 to 2 Step 1
 - For $i = 0 to 4 Step 1
 - ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
 - Sleep(100)
 - Next
 - Next
 - Sleep(300)
 - EndSelect
 - EndIf
 - ExitLoop
 - WEnd
 - EndFunc
 - Func DropCombo($W)
 - While 1
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - If CheckTroop("Giant") Then
 - ControlClick ($HWnD, "","", "left", "1", $Giant[0], $Giant[1])
 - Sleep(500)
 - For $i = 1 to 3 Step 1
 - ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
 - Sleep(500)
 - Next
 - Sleep(500)
 - EndIf
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - If CheckTroop("Barbarian") Then
 - ControlClick ($HWnD, "","", "left", "1", $Barbarian[0], $Barbarian[1])
 - Sleep(300)
 - For $x = 0 to 2 Step 1
 - For $i = 0 to 4 Step 1
 - ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
 - Sleep(100)
 - Next
 - Next
 - Sleep(500)
 - EndIf
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - If CheckTroop("Archer") Then
 - ControlClick ($HWnD, "","", "left", "1", $Archer[0], $Archer[1])
 - Sleep(300)
 - For $x = 0 to 2 Step 1
 - For $i = 0 to 4 Step 1
 - ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
 - Sleep(100)
 - Next
 - Next
 - Sleep(500)
 - EndIf
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - If CheckTroop("Goblin") Then
 - ControlClick ($HWnD, "","", "left", "1", $Goblin[0], $Goblin[1])
 - Sleep(300)
 - For $x = 0 to 2 Step 1
 - For $i = 0 to 4 Step 1
 - ControlClick ($HWnD, "","", "left", "1", $W[$i][0], $W[$i][1])
 - Sleep(100)
 - Next
 - Next
 - Sleep(500)
 - EndIf
 - ExitLoop
 - WEnd
 - EndFunc
 - Func ReadValue(ByRef $x, ByRef $y)
 - $Read = _TesseractWinCapture($HWnD,"",0,"",1,2,$Left*$x_ratio,$Top*$y_ratio,$Right*$x_ratio,$Bottom*$y_ratio,0) ;Capture screen region with gold and elixir
 - $Read = StringRegExpReplace(StringRegExpReplace($Read, "(\v)+", @CRLF), "\A\v|\v\Z", "") ;Strip whitespaces & blank lines and split into array
 - $Read = StringSplit($Read, @CRLF, 1)
 - While UBound($Read) < 5
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - $Read = _TesseractWinCapture($HWnD,"",0,"",1,2,$Left*$x_ratio,$Top*$y_ratio,$Right*$x_ratio,$Bottom*$y_ratio,0) ;Capture screen region with gold and elixir
 - $Read = StringRegExpReplace(StringRegExpReplace($Read, "(\v)+", @CRLF), "\A\v|\v\Z", "") ;Strip whitespaces & blank lines and split into array
 - $Read = StringSplit($Read, @CRLF, 1)
 - WEnd
 - $x = Number(StringRegExpReplace($Read[2], "[^[:digit:]]", "")) ;Convert gold to number
 - $y = Number(StringRegExpReplace($Read[3], "[^[:digit:]]", "")) ;Convert exlir to number
 - EndFunc
 - Func ComputeValue()
 - Local $G[3],$E[3]
 - ReadValue($G[0], $E[0])
 - ReadValue($G[1], $E[1])
 - ReadValue($G[2], $E[2])
 - $Gold = _ArrayMin($G)
 - $Elixir = _ArrayMin($E)
 - GUICtrlSetData($Results, "(" & $SearchCount+1 & ") Gold: " & $Gold & ". Elixir: " & $Elixir & @CRLF, -1)
 - $SearchCount += 1 ; Counter for number of searches
 - EndFunc
 - Func CompareValue()
 - If $Gold >= $MinGold Then
 - If $Elixir >= $MinElixir Then
 - ;MsgBox(0, "Gold & Elixir Check", "Gold: " & $Gold & @CR & "Elixir: " & $Elixir & @CR & "Requirement met.")
 - Select
 - Case $SearchMode = 1
 - $SearchCheck = 1
 - Case $SearchMode = 2
 - $SearchCheck = 1
 - Case Else
 - $SearchCheck = 0
 - EndSelect
 - Else
 - ;MsgBox(0, "Gold & Elixir Check", "Gold: " & $Gold & @CR & "Elixir: " & $Elixir & @CR & "Not enough " & $MinElixir & " Elixir.")
 - Select
 - Case $SearchMode = 1
 - $SearchCheck = 1
 - Case $SearchMode = 2
 - $SearchCheck = 0
 - Case Else
 - $SearchCheck = 0
 - EndSelect
 - EndIf
 - Else
 - If $Elixir >= $MinElixir Then
 - ;MsgBox(0, "Gold & Elixir Check", "Gold: " & $Gold & @CR & "Elixir: " & $Elixir & @CR & "Not enough " & $MinGold & " Gold.")
 - Select
 - Case $SearchMode = 1
 - $SearchCheck = 1
 - Case $SearchMode = 2
 - $SearchCheck = 0
 - Case Else
 - $SearchCheck = 0
 - EndSelect
 - Else
 - ;MsgBox(0, "Gold & Elixir Check", "Gold: " & $Gold & @CR & "Elixir: " & $Elixir & @CR & "Not enough " & $MinGold & " Gold and " & $MinElixir & " Elixir." )
 - Select
 - Case $SearchMode = 1
 - $SearchCheck = 0
 - Case $SearchMode = 2
 - $SearchCheck = 0
 - Case Else
 - $SearchCheck = 0
 - EndSelect
 - EndIf
 - EndIf
 - EndFunc
 - #EndRegion ##### ATTACK #####
 - #Region ##### MINI FUNCTION #####
 - Func MainScreen()
 - While 1
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - GUICtrlSetData($Results, "Waiting for Clash of Clans to load..." & @CRLF, -1)
 - $Pixel = PixelGetColor(630*$x_ratio, 390*$y_ratio, $HWnD)
 - If Hex($Pixel,6) = 282828 Or $Pixel = 2962704 Then
 - ControlClick ($HWnD, "","", "left", "1", 293*$x_ratio, 329*$y_ratio)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(5000)
 - EndIf
 - $Pixel = PixelSearch(0,0,900,700,0xF8ED90,0,1,$HWnD)
 - If IsArray($Pixel) Then
 - ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 450*$y_ratio)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(5000)
 - EndIf
 - $Pixel = PixelSearch(0,0,900,700,$Attack,0,1,$HWnD)
 - While Not IsArray($Pixel)
 - $Pixel = PixelSearch(0,0,900,700,$Attack,0,1,$HWnD)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(200)
 - WEnd
 - ExitLoop
 - WEnd
 - EndFunc
 - Func Idle($s)
 - For $i = 1 to $s/60 Step 1
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Train()
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(45000)
 - Next
 - EndFunc
 - Func ReturnHome()
 - $Pixel = PixelSearch(0,0,900,700,0xF8ED90,0,1,$HWnD)
 - While Not IsArray($Pixel)
 - $Pixel = PixelSearch(0,0,900,700,0xF8ED90,0,1,$HWnD)
 - Sleep(200)
 - WEnd
 - Sleep(1000)
 - GUICtrlSetData("Return Home" & @CRLF, -1)
 - ControlClick ($HWnD, "","", "left", "1", 400*$x_ratio, 450*$y_ratio)
 - EndFunc
 - Func ZoomOut()
 - GUICtrlSetData($Results, "Zoom Out" & @CRLF, -1)
 - For $i = 1 To 20 Step 1
 - ControlSend($HWnD, "", "", "{DOWN}", 0)
 - If $RunState = False Then
 - ExitLoop
 - EndIf
 - Sleep(500)
 - Next
 - EndFunc
 - Func Button($hex)
 - $Count = 0
 - $Pixel = PixelSearch(0,0,900,700,$hex,0,1,$HWnD) ;Attack! button
 - While Not IsArray($Pixel) And $Count < 5
 - $Pixel = PixelSearch(0,0,900,700,$hex,0,1,$HWnD) ;Attack! button
 - Sleep(200)
 - $Count += 1
 - WEnd
 - If $Count < 5 Then
 - ControlClick ($HWnD, "","", "left", "1", $Pixel[0], $Pixel[1])
 - EndIf
 - Sleep(1000)
 - EndFunc
 - Func Terminate()
 - Exit
 - EndFunc
 - Func FindPos(ByRef $Pos)
 - Local $x = 1
 - While $x = 1
 - If _IsPressed("01") Then
 - $Pos = MouseGetPos()
 - $x = 0
 - EndIf
 - WEnd
 - EndFunc
 - #cs
 - Func Pause()
 - $Paused = NOT $Paused
 - While $Paused
 - Sleep(100)
 - TrayTip("Script Paused","SHIFT+1 to Unpause", 0, $TIP_ICONASTERISK)
 - WEnd
 - EndFunc
 - Func Restart()
 - ControlClick ($HWnD, "","", "left", "1", 125, 575)
 - Sleep(2000)
 - ControlClick ($HWnD, "","", "left", "1", 125, 577)
 - Sleep(2000)
 - ControlClick ($HWnD, "","", "left", "1", 205, 575)
 - Sleep(2000)
 - MouseClickDrag("left", 700, 300, 700, 120)
 - Sleep(2000)
 - ControlClick ($HWnD, "","", "left", "1", 290, 160)
 - Sleep(50000)
 - EndFunc
 - Func Initiate()
 - ControlClick ($HWnD, "","", "left", "1", 290, 150) ;Click BlueStacks
 - Sleep(60000)
 - ZoomOut()
 - Sleep(10000)
 - EndFunc
 - #ce
 - #EndRegion ##### MINI FUNCTION ######
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment