Originally Posted by elmarcia
Hi, in fact is really simple to do, u need some math, here is a full example for u to DIY.
Compile this script to use the pixelSearch example below
Game HP bar Example:
(This code is for the example code to work (DON'T READ IT LOOKS BAD), the code used for the search is the one below, but you can use some of it for your separated gui HP/MP bar)
Code:
#include <GDIPlus.au3>
#include <Misc.au3>
$hGui = GUICreate("game",300,300)
GUISetState(@sw_show,$hGui)
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(300,300,$hGraphic)
$hBackBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hBrush = _GDIPlus_BrushCreateSolid()
$hPen = _GDIPlus_PenCreate(0xFF000000,2)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
$tLayout = _GDIPlus_RectFCreate(50, 15, 225, 25)
$hpValue = 100
_GDIPlus_StringFormatSetAlign ( $hFormat, 1 )
;_GDIPlus_GraphicsTranslateTransform($hBackbuffer,0,100)
$hpValue = 1232
$mpValue = 2221
$maxHP = 1232
$maxMP = 2221
While Sleep(15)
if GUIGetMsg() == -3 Then
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hBackBuffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_PenDispose($hPen)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_FontDispose($hFont)
_GDIPlus_Shutdown()
Exit 0
EndIf
render()
if(_IsPressed("01")) Then
$hpValue -= 1
EndIf
if(_IsPressed("02")) Then
$mpValue -= 1
EndIf
WEnd
Func render()
_GDIPlus_GraphicsTranslateTransform($hBackbuffer,0,70)
_GDIPlus_GraphicsClear($hBackbuffer,0xFFFFFFFF)
_GDIPlus_BrushSetSolidColor($hBrush,0xFF000000)
_GDIPlus_GraphicsDrawString($hBackBuffer,"HP",15,15,"arial",12)
_GDIPlus_BrushSetSolidColor($hBrush,0xFFFF0000)
_GDIPlus_GraphicsFillRect($hBackBuffer,50,12,225 * ($hpValue/$maxHP),25,$hBrush)
_GDIPlus_GraphicsDrawRect($hBackBuffer,50,12,226,25,$hPen)
_GDIPlus_BrushSetSolidColor($hBrush,0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hBackBuffer,$hpValue, $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_GraphicsTranslateTransform($hBackbuffer,0,50)
_GDIPlus_GraphicsDrawString($hBackBuffer,"MP",15,15,"arial",12)
_GDIPlus_BrushSetSolidColor($hBrush,0xFF0000FF)
_GDIPlus_GraphicsFillRect($hBackBuffer,50,12,225 * ($mpValue/$maxMP),25,$hBrush)
_GDIPlus_GraphicsDrawRect($hBackBuffer,50,12,226,25,$hPen)
_GDIPlus_BrushSetSolidColor($hBrush,0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hBackBuffer,$mpValue, $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_GraphicsDrawString($hBackBuffer,"[LEFT CLICK] Decrease HP",15,80)
_GDIPlus_GraphicsDrawString($hBackBuffer,"[RIGHT CLICK] Decrease MP",15,100)
_GDIPlus_GraphicsDrawImage($hGraphic,$hBitmap,0,0)
_GDIPlus_GraphicsResetTransform($hBackBuffer)
EndFunc
PixelSearch HP tracker example:
Execute the game.exe (compiled script from above), and run this script
Code:
AutoItSetOption("PixelCoordMode",2) ;relative to client window
$hwnd = WinGetHandle("game")
$maxHP = 1232
$xOffset = 50; bar left X value equals to sx
$ex = 275 ;bar end X value, right most x position
$barSize = $ex - $xOffset
$barBackColor = 0xFFFFFF
;currentSize -> size in pixels of current HP bar, is the bar that is decreased every time you loose some hp
;barSize -> size in pixels of the whole HP bar, is equal to currentSize bar when HP is full, constant value
;hpValue -> numeric value of current HP
;maxHP -> numeric value of maxium ammount of HP
;barBackColor -> color of the bar that is behind the HP bar
;FORMULA
;currentSize = barSize * ($hpValue/$maxHP)
;$maxHP * (currentSize/barSize) = $hpValue
$hpValue = "Unknown"
While Sleep(15)
if Not WinExists("game") Then ExitLoop
if Not WinActive($hwnd) Then ContinueLoop
;82 and 105 are y coordinates of search area, use autoitwindow info
$search = PixelSearch($xOffset,82,$ex,105,$barBackColor ,0,1,$hwnd)
If Not @error Then
$currentSize = $search[0]
;because is a pixel search, currentSize is an integer, then HP value may have some error
$hpValue = $maxHP * (($currentSize - $xOffset)/$barSize)
EndIf
ToolTip($hpValue,0,0)
WEnd
Image of code comments to know what all that means
[Only registered and activated users can see links. Click Here To Register...]
A tip, use autoitwindow info with these options to help you find the correct
search area position
[Only registered and activated users can see links. Click Here To Register...]
|