Jump to content

Recommended Posts

Posted

Hello again. So i've been making a bot for a game called KalOnline, and it works really well. However, i'm running into one issue that i do need to tackle.

Basically, the script runs in a loop and for debugging purposes, i added in a bunch of MsgBox() calls to know where/when the script was not working. I would just add a timeout of 1 to the msgboxes to keep from having to continuously click. However, when i comment out or remove the MsgBox() calls, the script doesn't click, or do anything for that matter. In the code below, i tried replacing the MsgBox() calls with WinActivate() on the AutoIt window because i thought that maybe it was because the script program wasn't the active window, but i still have the same problem. Any advice on this?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=first.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Run_AU3Check=n
#AutoIt3Wrapper_Tidy_Stop_onerror=n
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/cs 1 /cn 1 / cf 1 /cv 1
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.3.0.0
    Author:         Gogeta70
    
    Script Function:
    KalOnline Pixel Bot
    
#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

if NOT FileExists(@ScriptDir & "\splash.jpg") Then
    MsgBox(0, "No-Go", "The splash image must remain in order to use this bot.")
    ProcessClose(@AutoItPID)
EndIf


$y = @DesktopHeight/2-200
$x = @DesktopWidth/2-200
SplashImageOn("", @ScriptDir & "\splash.jpg", 400, 400, $x, $y, 1)
sleep(5000)
SplashOff()
$title = AutoItWinGetTitle()

$handle = ControlGetHandle("KalOnline", "", "")

MsgBox(64, "Instructions", "Put your mouse over the area" & @CRLF & "of your health bar that when reached," & @CRLF & "the bot will auto-pot. When done, press enter.")
$hcoord = MouseGetPos()
$healthcolor = PixelGetColor($hcoord[0], $hcoord[1])

MsgBox(64, "Instructions", "Now do the same thing, except put it over the demon/monster that you want to kill, and press enter.")
$dcoord = MouseGetPos()
$demoncolor = PixelGetColor($dcoord[0], $dcoord[1])

MsgBox(64, "Instructions", "Ok, now one more time. This time, click on a demon but don't attack, just click off. Now hold your mouse" & @CRLF & " over the very left of the demon's health bar (still on the red part). When you do that, press enter.")
$dhcoord = MouseGetPos()
$demonhealth = PixelGetColor($dhcoord[0], $dhcoord[1])

$attacking = $dhcoord
$attacking[0] = $attacking[0]+110
$atk = PixelGetColor($attacking[0], $attacking[1])
If $atk <> $demonhealth Then
    
    $isred = False
    While $isred == False
        $attacking[0] = $attacking[0]-5
        $atk = PixelGetColor($attacking[0], $attacking[1])
        
        if $atk == $demonhealth Then
            $isred = True
        EndIf
        
    WEnd

EndIf

MsgBox(0, "OK!", "Ok, now we have the coordinates of your health bar, the demon health bar, and the color of the demons." & @CRLF & "If you want to behead monsters, set it as your active skill.")

WinSetOnTop("KalOnline", "", 0) 
    

Dim $behead[7][7]

$winpos = WinGetPos("KalOnline")
$winx = $winpos[0]
$winy = $winpos[1] + 100
$winy2 = $winpos[1] + 200
$width = $winpos[2]-10
$height = $winpos[3] - 100
$battle = "no"
$right = $winx + $width
$bottom = $winy + $height

$behead[0][0] = "404" + $winx
$behead[0][1] = "405" + $winy - 100
$behead[1][0] = "366" + $winx
$behead[1][1] = "351" + $winy - 100
$behead[2][0] = "406" + $winx
$behead[2][1] = "351" + $winy - 100
$behead[3][0] = "446" + $winx
$behead[3][1] = "351" + $winy - 100
$behead[4][0] = "403" + $winx
$behead[4][1] = "316" + $winy - 100
$timeset = False


$dummy = 1

While $dummy == 1



    $pcoords = PixelSearch($winx, $winy2, $right, $bottom, $demoncolor, 25)

    If @error Then
        ;MsgBox(0, "Nothin'", "No demons nearby...", 1)
        WinActivate($title)
        $nothing = "nope"
        $pcoords = PixelSearch($winx, $winy, $right, $bottom, $demoncolor, 25)
    EndIf
    
    
    
    If @error Then
        ;MsgBox(0, "Nothin'", "Nothing here...", 1)
        WinActivate($title)
        $nothing = "nope"
    Else
        $nothing = "yep"
    EndIf


    If $nothing = "yep" Then

        ;MsgBox(0, "Located", "Found one!", 1)
        WinActivate($title)
        
        If $pcoords[1]-$winy > 300 Then
            $pcoords[1] = $pcoords[1]+5
        
        EndIf
        
        MouseClick("main", $pcoords[0], $pcoords[1], 1, 30)
        Sleep(1000)
        $tdh = PixelGetColor($dhcoord[0], $dhcoord[1])
        Sleep(1000)
    
        
        If $tdh = $demonhealth Then

            $battle = "yes"
            

        Else
            
            ;MsgBox(0, "Oops", "Misclick...", 1)
            WinActivate($title)
            MouseClick("main", $behead[2][0], $behead[2][1], 1, 30)
            
            Sleep(2000)

        EndIf

    EndIf

    $myhealth = PixelGetColor($hcoord[0], $hcoord[1])
    If $myhealth <> $healthcolor Then

        ControlSend("KalOnline", "", $handle, "4")
        Sleep(1000)
    EndIf

    If $battle == "yes" Then
    
    If $timeset = False Then
        $begint = TimerInit()
    EndIf
    
    $timeset = True
    
        
        While $battle == "yes"
        
        $tcheck = TimerDiff($begint)
        
            If $timeset = true And $tcheck > 30000 Then
                MsgBox(0, "Uh-Oh", "Assuming Misclick...", 1)
                $battle = "no"
                ControlSend("KalOnline", "", $handle, "{LEFT down}")
                Sleep(3000)
                ControlSend("KalOnline", "", $handle, "{LEFT up}")
                Sleep(1000)
                $timeset = False
                ExitLoop
            EndIf
            
            
            $myhealth = PixelGetColor($hcoord[0], $hcoord[1])
            If $myhealth <> $healthcolor Then
                ControlSend("KalOnline", "", $handle, "4")
                Sleep(1000)
            EndIf

            $demonh = PixelGetColor($dhcoord[0], $dhcoord[1])
            If $demonh <> $demonhealth Then

                MsgBox(0, "Dead", "He's dead...", 1)
                $deadleft = $winx+200;
                $deadright = $winx+600
                $deadbottom = $winy+$width-100
                $winy3 = $winy2 + 50
                Dim $find_dead[5][5]
                $find_dead = PixelSearch($deadleft, $winy3, $deadright, $deadbottom, $demoncolor, 10)
                
                
                If NOT @error Then
                    $find_dead[0] = $find_dead[0] + 10
                    MouseClick("secondary", $find_dead[0], $find_dead[1], 1, 30)
                    Sleep(1000)
                Else
                
                    MouseClick("secondary", $behead[0][0], $behead[0][1], 1, 30)
                    MouseClick("secondary", $behead[1][0], $behead[1][1], 1, 30)
                    MouseClick("secondary", $behead[2][0], $behead[2][1], 1, 30)
                    MouseClick("secondary", $behead[3][0], $behead[3][1], 1, 30)
                    MouseClick("secondary", $behead[4][0], $behead[4][1], 1, 30)
                    MouseClick("secondary", $pcoords[0], $pcoords[1], 1, 30)
                EndIf
                
                ControlSend("KalOnline", "", $handle, "{SPACE}")
                Sleep(1000)
                ControlSend("KalOnline", "", $handle, "{SPACE}")
                Sleep(1000)
                ControlSend("KalOnline", "", $handle, "{SPACE}")
                Sleep(1000)
                ControlSend("KalOnline", "", $handle, "{SPACE}")
                Sleep(1000)
                $battle = "no"

            EndIf


        WEnd
        
        $timeset = False

    EndIf

    If $nothing = "nope" Then
        ControlSend("KalOnline", "", $handle, "{LEFT down}")
        Sleep(2000)
        ControlSend("KalOnline", "", $handle, "{LEFT up}")
        Sleep(1000)
    EndIf


WEnd
Posted

My guess would be is your timing doesn't work out without that 1 second delay caused by the MsgBox's timeout, maybe try adding a sleep for 1000 ms in place of your MsgBoxes?

Sleep (1000)
Posted

Exodius, i just tried the Sleep(1000) in place of the msgbox function but it didn't work. Still not clicking unless i make a MsgBox before the mouseclick function...

Any other ideas?

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
  • Recently Browsing   0 members

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