--_--xxXXXxx--_-- Posted April 1, 2006 Posted April 1, 2006 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.jpgShould be a fairly simple script - so I thought when I started anyway!Here's my script:Dim $activeHotKeySet("+![", "Go") ;Script works as a loop, so these commands are necessary to stop overloadingHotKeySet("+!]", "Stop")Func Go ( ) $active = 1EndFuncFunc Stop ( ) $active = 0EndFuncWhile $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 )WEndThis 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?
greenmachine Posted April 1, 2006 Posted April 1, 2006 Are you sure the pixels are in the right places? Try doing a mousemove after the color check to see where you're checking. Also - using Au3Info.exe I looked at the colors of the bars and couldn't get either of the colors you mentioned...
Valuater Posted April 1, 2006 Posted April 1, 2006 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)
--_--xxXXXxx--_-- Posted April 1, 2006 Author Posted April 1, 2006 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.
greenmachine Posted April 1, 2006 Posted April 1, 2006 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.
--_--xxXXXxx--_-- Posted April 2, 2006 Author Posted April 2, 2006 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?
Valuater Posted April 2, 2006 Posted April 2, 2006 have you checked the Opt("PixelCoordMode", 1) ;1=absolute, 0=relative, 2=client ?? 8)
greenmachine Posted April 2, 2006 Posted April 2, 2006 It might also help us if you post a screenshot of the whole screen (not just that bar), because I have no idea where on the screen that is, and I can only guess how to fix it.
--_--xxXXXxx--_-- Posted April 2, 2006 Author Posted April 2, 2006 The game has to run in full screen mode, which means mode 0 has no function - it's the same as mode 1. The game has no "active client area" as such, so mode 2 is also meaningless to this script.... Any other thoughts? Ta.
--_--xxXXXxx--_-- Posted April 2, 2006 Author Posted April 2, 2006 Fullscreen screenshot:http://img239.imageshack.us/img239/4627/ne...01noname4qi.jpgThe area in observation is in the top left corner...Any help would be greatly appreciated
greenmachine Posted April 2, 2006 Posted April 2, 2006 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
Moderators SmOke_N Posted April 2, 2006 Moderators Posted April 2, 2006 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, BE444Fblue - 6857E3, 908BF2, 645FC6, 0709CD, 0709CE, 0155E9, 1B70FF, 30A6FF, 30A6FEIt 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.
greenmachine Posted April 2, 2006 Posted April 2, 2006 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.Makes sense.. I didn't even look at that.
Moderators SmOke_N Posted April 2, 2006 Moderators Posted April 2, 2006 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now