Jump to content

Need Help With Colour Recognition


Recommended Posts

OK guys, basically, I'm trying to make a script that will monitor a health bar in a game I play, and when it reaches a certain level (1/2 health in this case) it will spot this via the GetPixelColor command, and subsequently use a health potion. Secondly, it then monitors the mana bar, and when it reaches a certain level (1/5 mana in this case) it will spot this etc...

Here's a screenshot of the portion of the screen with the relevant things in:

http://img80.imageshack.us/img80/2808/hpfp0wx.jpg

Should be a fairly simple script - so I thought when I started anyway!

Here's my script:

Dim $active

HotKeySet("+![", "Go") ;Script works as a loop, so these commands are necessary to stop overloading

HotKeySet("+!]", "Stop")

Func Go ( )

$active = 1

EndFunc

Func Stop ( )

$active = 0

EndFunc

While $active = 0 ;When it ISNT active

Sleep ( 100 )

WEnd

;HEREs where it gets annoying... When it's active....

While $active = 1

$hpcolour = Hex(PixelGetColor( 161 , 19 ), 6) ;Gets the hex value of the colour at the point of the health bar shown in the screenshot in white

If $hpcolour = "A51E1E" Then ;If it's the correct colour (red) then do nothing...

Else ;If not, then hit a health potion (the key is held down to stop irritating lag effects in game...

Send ("{F9 down}")

Sleep ( 200 )

Send ("{F9 up}")

EndIf

$fpcolour = Hex(PixelGetColor( 100 , 34 ), 6) ;Rinse and repeat with the white place on the mana bar

If $fpcolour = "0808CE" Then ;If it's blue, do nothing

Else ;If not, hit a mana potion

Send ("{F10 down}")

Sleep ( 200 )

Send ("{F10 up}")

EndIf

Sleep ( 200 )

WEnd

This all seems fine to me in theory... My problem however, is that as soon as I trigger the macro using "go", it starts using both potions... I checked this out by putting in a msg box command before using the potions, returning the value of $hpcolour and $fpcolour and they're completely different to what they should be... In fact, they have a colour value from the part of the screenshot LEFT of the health/mana bars, showing "31" in the blue surround... Any ideas on what is going on here? Am I doing something wrong? Or could I do something different?

Link to comment
Share on other sites

worse... your two while loops will not work

Dim $active

HotKeySet("+![", "Go");Script works as a loop, so these commands are necessary to stop overloading
HotKeySet("+!]", "Stop")

While 1
    If $active = 1 Then
        $hpcolour = Hex(PixelGetColor(161, 19), 6);Gets the hex value of the colour at the point of the health bar shown in the screenshot in white
        If $hpcolour = "A51E1E" Then;If it's the correct colour (red) then do nothing...
            
        Else;If not, then hit a health potion (the key is held down to stop irritating lag effects in game...
            Send("{F9 down}")
            Sleep(200)
            Send("{F9 up}")
        EndIf
        
        $fpcolour = Hex(PixelGetColor(100, 34), 6);Rinse and repeat with the white place on the mana bar
        If $fpcolour = "0808CE" Then;If it's blue, do nothing
            
        Else;If not, hit a mana potion
            Send("{F10 down}")
            Sleep(200)
            Send("{F10 up}")
        EndIf
    EndIf
    Sleep(100)
WEnd
    
Func Go()
    $active = 1
EndFunc  ;==>Go 

Func Stop()
    $active = 0
EndFunc  ;==>Stop

8)

NEWHeader1.png

Link to comment
Share on other sites

Ta for the heads up on the loops - not really used them before...

As for the colours, I'm using adobe photoshop to get the pixel colours... What method would you suggest instead? And could you explain "try doing a mousemove....", didnt make sense to me :) Maybe its just late lol.

Cheers.

Link to comment
Share on other sites

What I meant was to do MouseMove to the coordinates you're using to check for the colors.

Code snippet:

$hpcolour = Hex(PixelGetColor(161, 19), 6)
MouseMove (161, 19); this is the line I'm adding to see if it's moving to the correct place.
        If $hpcolour = "A51E1E" Then
           ; nothing
        Else
            Send("{F9 down}")
            Sleep(200)
            Send("{F9 up}")
        EndIf

The mousemove allows you to see where the pixel check is happening - if it isn't anywhere where you want it to be, you know you have the wrong coords and you need to fix them.

Link to comment
Share on other sites

OK, coordinates are fine, as is the colour choice... It seems to work 80% of the time (I got it to return the hex colour value to a variable, and tried it like 250 times)... The other 20% it comes up with a colour somewhere in the range of yellowy black... If i make it take a screenshot at the time of taking the pixel colour, it has the correct colour I'm expecting to in the place I'm searching, which seems odd... If I then do a pixelcoord search, and make it search the top left area of the screen (like the posted screenshot), there is always one pixel with the returned hex colour nearby... But the colour isnt where it should be searching... Does anyone have any idea what could cause this bug/error? Or a way to work around it?

Link to comment
Share on other sites

Well I just did a PixelSearch on the screenshot, and didn't find either of the colors you have.

Some of the colors I did find:

red - D05557, 9C2123, CE0000, CD0200, DE110C, FF322D, E96F7A, BE444F

blue - 6857E3, 908BF2, 645FC6, 0709CD, 0709CE, 0155E9, 1B70FF, 30A6FF, 30A6FE

Link to comment
Share on other sites

  • Moderators

Well I just did a PixelSearch on the screenshot, and didn't find either of the colors you have.

Some of the colors I did find:

red - D05557, 9C2123, CE0000, CD0200, DE110C, FF322D, E96F7A, BE444F

blue - 6857E3, 908BF2, 645FC6, 0709CD, 0709CE, 0155E9, 1B70FF, 30A6FF, 30A6FE

It would stand to reason that you wouldnt' find the same/correct colors, he has a .jpq as a screenshot, it would have to be a .bmp.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Makes sense.. I didn't even look at that.

No worries, I don't think I would have noticed it if you hadn't mentioned that you didn't find the same colors.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

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