Jump to content
Sign in to follow this  
eMOO

PixelSearch Problem

Recommended Posts

eMOO

I am having a problem... when I run the hotkey of the function _HealthCheck() I get a MsgBox with the "x, y" coords... Am I retarded / tired? I am pretty new to this, I was using autohotkey before and it was a little more dummy friendly. Thanks for any help in advance...

$i = 1

While $i = 1

HotKeySet( "{f11}", "_FindStatus" )
HotKeySet( "{f10}", "_HealthCheck" )

WEnd



Func _FindStatus()
    
    $mospos = MouseGetPos()
    $XtopLeft = $mospos[0]
    $YtopLeft = $mospos[1]
    $XbottomRight = $mospos[0] + 125
    $YbottomRight = $mospos[1] + 45
    
EndFunc

Func _HealthCheck()

    $hpBar = PixelSearch ( $XtopLeft, $YtopLeft, $XbottomRight, $YbottomRight, 0x1B1B88 , 3 )

    If Not @error Then
    MouseMove($hpBar[0], $hpBar[1], 3)
    EndIf

EndFunc

Share this post


Link to post
Share on other sites
FinalVersion

First of all lets clean this up.

HotKeySet( "{f11}", "_FindStatus" )
HotKeySet( "{f10}", "_HealthCheck" )

while 1
sleep(100)
wend

Func _FindStatus()
   
    $mospos = MouseGetPos()
    $XtopLeft = $mospos[0]
    $YtopLeft = $mospos[1]
    $XbottomRight = $mospos[0] + 125
    $YbottomRight = $mospos[1] + 45
   
EndFunc

Func _HealthCheck()

    $hpBar = PixelSearch ( $XtopLeft, $YtopLeft, $XbottomRight, $YbottomRight, 0x1B1B88 , 3 )

    If Not @error Then
    MouseMove($hpBar[0], $hpBar[1], 3)
    EndIf

EndFunc

And what game is this for?

Share this post


Link to post
Share on other sites
DrKovra

Don't hesitate ... try this puppy and look in the console windows of Scite ...

I just added a few thing like the Include and MustDeclareVars.... I had the oportunity to see the error when trying to access the $hp[0] and $hp[1] ... but now seems to go smoooooth ....

I hope this can help a bit .... ^_^

#include <Array.au3>

AutoItSetOption("MustDeclareVars", 1) 

Dim $XtopLeft
Dim $YtopLeft
Dim $XbottomRight
Dim $YbottomRight
Dim $i
Dim $mospos
Dim $hp0
Dim $hp1
Dim $var
Dim $pos


Dim $hpBar[2]=[0,0]
ConsoleWrite("******************************************" & @CRLF )
ConsoleWrite("Initial PixelSearch X: " & $hpBar[0] & @CRLF)
ConsoleWrite("Initial PixelSearch Y: " & $hpBar[1] & @CRLF)

$i = 1

HotKeySet( "{f11}", "_FindStatus" )
HotKeySet( "{f10}", "_HealthCheck" )

While $i = 1
    ConsoleWrite("******************************************" & @CRLF )
    Sleep(5000)
    $pos = MouseGetPos()
    MsgBox(0, "Mouse x,y:", $pos[0] & "," & $pos[1],1)
    $var = PixelGetColor( $pos[0] , $pos[1] )
    MsgBox(0,"The decmial color under mouse is: ", $var,1)
    MsgBox(0,"The hex color is under mouse is: ", Hex($var, 6),1)
    _FindStatus()
WEnd

ConsoleWrite("OOOPS ! exit")


Func _FindStatus()
    ConsoleWrite("_FindStatus"& @CRLF)
    $mospos = MouseGetPos()
    $XtopLeft = $mospos[0]
    $YtopLeft = $mospos[1]
    $XbottomRight = $mospos[0] + 125
    $YbottomRight = $mospos[1] + 45
    ConsoleWrite("TOPcoords: " & $XtopLeft & "-" & $YtopLeft & @CRLF & "BOTcoords: " & $XbottomRight & "-" & $YbottomRight & @CRLF)
    _HealthCheck()
    Sleep(1000)
EndFunc

Func _HealthCheck()
    ConsoleWrite("_HealthCheck"& @CRLF)
    $hp0=_ArrayToString ( $hpBar, "",0,0)
    $hp1=_ArrayToString ( $hpBar, "",1,1)
    $hpBar = PixelSearch ( $XtopLeft, $YtopLeft, $XbottomRight, $YbottomRight, 0xFFFFFF,3)
    ConsoleWrite("PixelSearch: " & $hp0 & "," & $hp1 & @CRLF)
    ConsoleWrite("ERROR: " & @error& @CRLF)
    If Not @error Then
        MouseMove($hp0, $hp1, 3)
    EndIf

EndFunc

[s][font="Impact"]░▒▓▓►DrKovra◄▓▓▒░[/font][/s]The only thing I [sup]know [/sup]is that I don't know [sub]nothing[/sub]--------------- __________------------------------------ __________---------------

Share this post


Link to post
Share on other sites
eMOO

its for darkfall online...

The mouse move was a simple test... it serves no real purpose at this point...

Why was I getting a popup of the "x, y" coords? doesnt make any sense...

Oh and let me explain it... to my knowledge pixel search, searches from left to right and the health bar moves from right to left and leaves a darker red then when the bar is full, i will be searching for that darker red color.

the bar is exactly 116 pixels across so i just did a little math equation so it can be set as a percentage so that later I can make a statement that

If _HealthCheck() < .05 Then

     Rest()

Next

I can post all my code if that helps... thanks

Share this post


Link to post
Share on other sites
Valuater

PixelGetColor() searches "a" pixel. Not from left to right or reverse

I made this to search from right to left

Global $GUI

Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client
Opt("PixelCoordMode", 2) ;1=absolute, 0=relative, 2=client

While 1
    Progress()
    $Percent = GetPercent(20, 50, 250, 0x28D22B, 5)
    MsgBox(4096, "Info", "Percentage = " & $Percent  & "%  ", 5)
    Sleep(1000)
WEnd

Func GetPercent($x, $y, $xx, $color, $adjust = -5)
    Local $unit = (($xx - $x) / 100), $icnt
    For $go = $xx To $x Step -$unit
        $icnt +=1
        MouseMove($go + $x,$y + $adjust) ; visual effect only
        If PixelGetColor($go + $x, $y) = $color Then Return $icnt
    Next
EndFunc   ;==>GetPercent

Func Progress()
    GUIDelete($GUI)
    $GUI = GUICreate("Color Bar",  290, 150, 200, 200)
    GUICtrlCreateLabel("", 20, 50, 250, 20) 
    GUICtrlSetBkColor( -1, "")
    $random = Random(20, 250, 1)
    GUICtrlCreateLabel("", 20, 50, $random, 20)
    GUICtrlSetBkColor( -1, 0x28D22B)
    GUISetState()
    WinSetOnTop("Color Bar", "", 1)
EndFunc   ;==>Progress

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
eMOO

maybe i didnt explain myself well... although thanks for all the code and like i said, im pretty new at all this autoit stuff.

PixelSearch() searches for a single pixel in a specified area from Left to Right, Up to Down... by knowing this I can assume that while it searches it will find the part of the health bar that both the Bright Red (actual hp) and Dark Red (missing hp, or max hp) meets.

The Point that is depicted by the "|". Anything to the left of the "|" would be Bright Red, anything right of it would be Dark Red.

Health Bar Example: [----------|-----]

After a pixelsearch I can perform a "IF statement" from the outputvar of the PixelSearch() saying that if that pixel is too far left along the Health Bar to Rest().

Here is what I have so far, once again thanks for all the help in advance...

Dim $maxPixels = 116 ;pixels in bar
Dim $p = 5 ;percent of hp to rest
Dim $perBase = .01 * 116  ;pixel percentage conversion
Dim $perCheck = $p * $perBase ;percent to check
Dim $finCheck = $mospos[0] + $perCheck

Dim $XtopLeft
Dim $YtopLeft
Dim $XbottomRight
Dim $YbottomRight

Dim $cWep = 1

Func _FindStatus()
    
    $mospos = MouseGetPos()
    $XtopLeft = $mospos[0]
    $YtopLeft = $mospos[1]
    $XbottomRight = $mospos[0] + 125
    $YbottomRight = $mospos[1] + 45
    
EndFunc

Func _HealthCheck()
    
    $hpBar = PixelSearch ( $XtopLeft, $YtopLeft, $XbottomRight, $YbottomRight, 0x1B1B88 , 255 )
    
    If Not @error And $hpBar[0] < $finCheck Then
        MsgBox( 0, "success", "Pixel found." & $perCheck) ;debug use only
        Rest()
    EndIf
    
    If @error Then
        MsgBox( 0, "error", "No pixel found.") ;debug use only
    EndIf
    
EndFunc
Edited by eMOO

Share this post


Link to post
Share on other sites
Qousio

maybe i didnt explain myself well... although thanks for all the code and like i said, im pretty new at all this autoit stuff.

PixelSearch() searches for a single pixel in a specified area from Left to Right, Up to Down... by knowing this I can assume that while it searches it will find the part of the health bar that both the Bright Red (actual hp) and Dark Red (missing hp, or max hp) meets.

The Point that is depicted by the "|". Anything to the left of the "|" would be Bright Red, anything right of it would be Dark Red.

Health Bar Example: [----------|-----]

After a pixelsearch I can perform a "IF statement" from the outputvar of the PixelSearch() saying that if that pixel is too far left along the Health Bar to Rest().

Here is what I have so far, once again thanks for all the help in advance...

Dim $maxPixels = 116 ;pixels in bar
Dim $p = 5 ;percent of hp to rest
Dim $perBase = .01 * 116  ;pixel percentage conversion
Dim $perCheck = $p * $perBase ;percent to check
Dim $finCheck = $mospos[0] + $perCheck

Dim $XtopLeft
Dim $YtopLeft
Dim $XbottomRight
Dim $YbottomRight

Dim $cWep = 1

Func _FindStatus()
    
    $mospos = MouseGetPos()
    $XtopLeft = $mospos[0]
    $YtopLeft = $mospos[1]
    $XbottomRight = $mospos[0] + 125
    $YbottomRight = $mospos[1] + 45
    
EndFunc

Func _HealthCheck()
    
    $hpBar = PixelSearch ( $XtopLeft, $YtopLeft, $XbottomRight, $YbottomRight, 0x1B1B88 , 255 )
    
    If Not @error And $hpBar[0] < $finCheck Then
        MsgBox( 0, "success", "Pixel found." & $perCheck) ;debug use only
        Rest()
    EndIf
    
    If @error Then
        MsgBox( 0, "error", "No pixel found.") ;debug use only
    EndIf
    
EndFunc
This is all completly unnecesary ^_^ You could write a script that does exactly what you want in as little as 5 lines.

$Woot = PixelSearch($a, $b, $c, $d, $x)
If IsArray($Woot) then
MouseMove(Where you want the mouse to move)
MsgBox( 0, "Your health is", $Woot[0]*0.86206897 )
endif

where $a=left of the health bar. $b=top of the bar, $c=right, $d=bottom. $x = colour of the healthbar when youre health is not full.

The health is shown in percents, if it says your health is 50, that means its at 5o%. Obviously if your healthbar doesnt start at x=0, then you should substract that distance from $Woot[0]. So if your healthbar starts at x=200, then change $Woot[0]*0.86206897 to $Woot[0]-200*0.86206897

Edited by Qousio

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.