This is written for AutoIt. Something similar would also work in AutoHotKey.
It's also not much of a tutorial, the code is short and straight forward. If you can get something out of it, great. This is more or less an example of something you can do that's pretty easy but useful.
Below I break it up into three sections with comments for pretty much everything, at the bottom is the code without any comments at all.
This only works on character with less than 100 health. If over 100 health you would have to increase $lifebar[0] and change the "36" at the bottom if you want to test this on a character with over 100 health.
Lets declare variables.
Code:
;Declare our variables, we'll put them into global scope. Global $colorhex,$variation,$percent,$lifebar[3] ;The hex code of the pixel color we're search for. $colorhex = 0xCD398D ;x coord start of life bar. I'm pretty sure it really starts at 162 on my screen. ;Hower we dont start searching till after the health text, in this example we're ;starting at x coord 198, this will vary if your health is higher than the character ;I used in this example. $lifebar[0] = 198 ;Y coord of life bar. $lifebar[1] = 736 ;X coord end of life bar. Not the actual end which is more like 262. 258 is the last pixel that can max our $colorhex. $lifebar[2] = 258 ;How much variation to use in PixelSearch, we want no variation so we set to 0. $variation = 0
Code:
;Switch to your game screen. WinActivate("Mabinogi : Dragon") ;x.X sleep(2000) ;Call our function. _lifecheck() ;Just a little msg box displaying your health percent, - 1% in my limited testing. msgbox(0,"Health Percent",$percent)
Code:
;Start of our function code. Func _lifecheck() ;Loop our search Do PixelSearch($lifebar[0],$lifebar[1],$lifebar[0],$lifebar[1],$colorhex,$variation) ;PixelSearch sets @error so that if @error is defined our pixel wasn't found. If Not @error Then ;Found our $colorhex so we'll increase our X Coord by 1 to search in a line. $lifebar[0] +=1 ElseIf @error Then ;Our $colorhex was not found which means our health bar is not full. EndIf ;We loop until we don't match our pixel color ;or we reach the end of the bar. Until @error or $lifebar[0] = $lifebar[2] If $lifebar[0] = $lifebar[2] Then ;Health bar was full, give or take. :p $percent = 100 Else ;Oh noes. $percent = 36 + ($lifebar[0]-198) ;If our health bar starts at 162 and ends at 262 thats 100 pixels. ;We start at 198 or 36 pixels in. So that 36 plus the difference between ;where our search ended minus the starting point equals our percentage. EndIf EndFunc
Code:
Global $colorhex,$variation,$percent,$lifebar[3] $colorhex = 0xCD398D $lifebar[0] = 198 $lifebar[1] = 736 $lifebar[2] = 258 $variation = 0 WinActivate("Mabinogi : Dragon") sleep(2000) _lifecheck() msgbox(0,"Health Percent",$percent) Func _lifecheck() Do PixelSearch($lifebar[0],$lifebar[1],$lifebar[0],$lifebar[1],$colorhex,$variation) If Not @error Then $lifebar[0] +=1 ElseIf @error Then EndIf Until @error or $lifebar[0] = $lifebar[2] If $lifebar[0] = $lifebar[2] Then $percent = 100 Else $percent = 36 + ($lifebar[0]-198) EndIf EndFunc