Sign in to follow this  
Followers 0
Dustin0550

PixelSearch Help Please

5 posts in this topic

Greetings. I have been having a lot of trouble with PixelSearch ever since I first attempted to use it.

I am trying to run a Diablo 3 single player bot, which begins in Act 1. The bot detects when the color of the healthpot is not present on the player belt,

and then begins walking down to Akara to be healed.

The problem I have is that the script will NOT select Akara. I continue to receive the following error:

D:\Computer Files\Autoit\Dust Bot\DustBot1.au3 (46) : ==> Subscript used with non-Array variable.:

MouseClick("left", $akara[0], $akara[1])

MouseClick("left", $akara^ ERROR

I have tried many methods, but the script will not seem to return an x or y coordinate value. Please help, with specific instructions? That would be really great.

Script:

$Active = Run("D:\Games\Diablo II\Diablo II\Diablo II.exe -w")

Sleep(1000)

;Window Move To Top Left Edge

WinMove("Diablo II", "", -3, -25)

Sleep(2000)

;Single Player Click

MouseClick("left", 397, 310, 2, 15)

;Character Slot 1 Selection

MouseClick("left", 179, 131, 2, 15)

Sleep(2000)

$BeltSlot1 = PixelGetColor(440, 582) ; empty color: 1315860

$BeltSlot2 = PixelGetColor(471, 582) ; 21053761

$BeltSlot3 = PixelGetColor(502, 582) ; 1052688

$BeltSlot4 = PixelGetColor(533, 582) ; 263172

While $BeltSlot1 <> 8925220

MouseClick("left", 766, 495, 1, 3)

Sleep(2500)

MouseClick("left", 766, 390, 1, 3)

Sleep(2500)

MouseClick("left", 766, 295, 1, 3)

Sleep(2500)

MouseClick("left", 769, 343, 1, 3)

Sleep(2500)

; I have tried with the While loop and error = 0, and have tried with no isarray function at all.

$akara = PixelSearch(182, 100, 745, 419, 381444, 8, 1)

if isarray($akara) then

MouseClick("Left",$akara[0],$akara[1], 1, 0)

EndIf

Sleep(1000)

; MouseMove($x, $y, 15)

MouseClick("left", $akara[0], $akara[1])

Sleep(10000)

WEnd

;PixelSearch(433, 580, 441, 589

$GameState = 1

If WinActive("Diablo II") = 0 Then

$GameState + 1

EndIf

While $GameState > 0

$RedHealth = PixelGetColor(86, 545)

;MsgBox(0,"The decimal color is", $var)

;6029312 is the red color in middle

$HealthLow = 0

While $HealthLow < 1

$RedHealthMiddle = PixelGetColor(86, 545)

If $RedHealthMiddle <> $RedHealth Then

Send("1")

Sleep(5000)

EndIf

WEnd

WEnd

Exit

post-54796-12606786636536_thumb.jpg

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Firstly, [autoit] tags please.

Try this out. You need to make sure that there isn't any error in the pixelsearch when you try to do mouseclick the second time too. Another option would be to put the whole sequence in an if statement if it is a single related piece of code.

$akara = PixelSearch(182, 100, 745, 419, 381444, 8, 1)
    If IsArray($akara) Then
        MouseClick("Left", $akara[0], $akara[1], 1, 0)


        Sleep(1000)
        ; MouseMove($x, $y, 15)
        MouseClick("left", $akara[0], $akara[1])
    EndIf
Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

;I think the color for your pixelsearch is messed up but if it works then awesome!
;I think it needs to be a hex value. Plus your skipping pixels i wouldnt do that.
;Doing control clicks you dont have to have the window active.
$handle = WinGetHandle("Diablo II")
$akara = PixelSearch(182, 100, 745, 419, 381444, 8, 1,$handle)
If Not @error Then
    ControlClick("","",$handle,"left",1,$akara[0],$akara[1]); or do something like this.
    Sleep(1000)
    ; MouseMove($x, $y, 15)
    ControlClick("","",$handle,"left",1,$akara[0],$akara[1])
    Sleep(10000)
EndIf

While 1 ;this loop will run forever. Need to fix this part.
    $RedHealth = PixelGetColor(86, 545,$handle)
    $HealthLow = 0
    While $HealthLow < 1
        $RedHealthMiddle = PixelGetColor(86, 545)
        If $RedHealthMiddle <> $RedHealth Then
        Send("1")
        Sleep(5000)
        EndIf
    WEnd
WEnd
Exit

Or you may want the loop there I guess.

Edited by smcombs

Share this post


Link to post
Share on other sites

Thanks for your help. I am still receiving a problem.

Here is my new code:

While $BeltSlot1 <> 8925220

MouseClick("left", 766, 495, 1, 3)

Sleep(2500)

MouseClick("left", 766, 390, 1, 3)

Sleep(2500)

MouseClick("left", 766, 295, 1, 3)

Sleep(2500)

MouseClick("left", 769, 343, 1, 3)

Sleep(2500)

;I think the color for your pixelsearch is messed up but if it works then awesome!

;I think it needs to be a hex value. Plus your skipping pixels i wouldnt do that.

;Doing control clicks you dont have to have the window active.

$handle = WinGetHandle("Diablo II")

$akara = PixelSearch(182, 100, 745, 419, 381444, 8, 1,$handle)

If Not @error Then

ControlClick("","",$handle,"left",1,$akara[0],$akara[1]); or do something like this.

Sleep(1000)

ControlClick("","",$handle,"left",1,$akara[0],$akara[1])

Sleep(10000)

EndIf

WEnd

The bot character ignores the request (error apparently = 1) to find Akara and click her, and continues the while loop again... clicking 4 times as it if were once again trying to reach Akara's location.

Any advice?

Share this post


Link to post
Share on other sites

Let's modify this pixelsearch. If $akara is your char on screen then I wouldnt skip even 1 pixel. People complain about pixelsearch being slow but those are critical statements its by like the milliseconds that its slow. Use this instead:

$akara = PixelSearch(182, 100, 745, 419, 381444, 8, 0,$handle)

Try running the script in Scite and you will see what line its erroring at instead of compiling it into an .exe first. The error -1 is just the common error that occurs. Also, are you only wanting to search the client area of the game? If so then you need to put in:

Opt("PixelCoordMode", 2)

And possible need to re-do your square in which your searching. Anyway, run the script in Scite and see what line your erroring at.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0