Jump to content

Pixel search problem


Recommended Posts

okey. im trying to make a bot to upgrade buildings in tribalwars, with autoit. what im trying to due is:

Search for the "Barrack" line and then click at "Expansion" at the same line!.

is it possible?

and one more question, is it possible to use pixel search for a bigger area, not just like 20 pixels, something like 200x200 pixels? and how do i do it? :D

i´ll be grateful for every answer i get and a apologize if my question is unclear.

Posted Image

Link to comment
Share on other sites

Well if you really need to search the Barrack in the screen, you should PickelCheckSum your redmarked rectangle first.

like:

$barrack = $PixelChecksum($x-top,y-top,x-bottom,y-bottom)

e.g.: $barrack = $PixelChecksum(377,630,493,670)

something like that will be the result: $barrack = 2492442939

create a new script:

CODE
$barrack = 2492442939

$x = 377 ; your coordinates

$y = 630

$xs = $x +(493-377) ; =$x + 116

$ys = $y +(670-630) ; = $y + 40

;- Search for the $barrack

; Check the part of the screen you would like to scan. Lets say we will check from 200,500 to 600, 700

$i = 200

$j = 500

while $i >= 600 And $search <> $barrack

$i = $i + 1

while $j <= 700 And $search <> $barrack

$j = $j +1

$search = PixelChecksum($i,$j,$i+116,$j+40)

WEnd

if $search <> $barrack Then

$j = 500

EndIf

WEnd

if $search == $barrack Then

MsgBox(0, "Coordinates:", $i & "," &j & " " &i+116 & "," &j+40)

EndIf

Edited by hendrikhe
Link to comment
Share on other sites

Well if you really need to search the Barrack in the screen, you should PickelCheckSum your redmarked rectangle first.

like:

$barrack = $PixelChecksum($x-top,y-top,x-bottom,y-bottom)

e.g.: $barrack = $PixelChecksum(377,630,493,670)

something like that will be the result: $barrack = 2492442939

create a new script:

CODE
$barrack = 2492442939

$x = 377 ; your coordinates

$y = 630

$xs = $x +(493-377) ; =$x + 116

$ys = $y +(670-630) ; = $y + 40

;- Search for the $barrack

; Check the part of the screen you would like to scan. Lets say we will check from 200,500 to 600, 700

$i = 200

$j = 500

while $i >= 600 And $search == 1

$i = $i + 1

while $j <= 700 And $search == 1

$j = $j +1

$search = PixelChecksum($i,$j,$i+116,$j+40)

WEnd

if $search == 1 Then

$j = 500

EndIf

WEnd

if $search <> 1 Then

MsgBox(0, "Coordinates:", $i & "," &j & " " &i+116 & "," &j+40)

EndIf

hehe, okey.

WHAT?

what does PixelCheksum do? i've looked in autoit help file but culdn't find somthing that i anderstand. "/

Edited by NalleDanne
Link to comment
Share on other sites

PixelChecksum return a checksum not PixelGetColor of everyone. It means it finds a checksum of 0,0 to 2,2 rectangle.

Edited by TerarinK

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

$pos = MouseGetPos()

$var = PixelCheckSum($pos[0],$pos[1], $pos[0] +100, $pos[1] +100)

search Mouse Location Pointer

script not by me

--------------

#include <GuiConstants.au3>
#include <date.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 4); set title matchmode to advanced

Global $xoffset = 37
Global $yoffset = 23
Global $wposx, $wposy, $DT, $cWIN, $xcalcL, $xcalcR, $ycalc, $cpos, $pos, $tpos, $hexV, $_color
Global $title = "Your Title Here"

HotKeySet("{ESC}", "Terminate"); a way out of this
HotKeySet("!f", "_color"); check for color

$pGUI = GUICreate($title, 150, 13, -1, -1, $WS_POPUP)
$startLAB = GUICtrlCreateLabel(" X: 0000, Y: 0000, C: 000000000", 0, 0, 150, 13)
GUICtrlSetBkColor($startLAB, 0xCCFFFF)

WinSetOnTop($pGUI, "", 1)

GUISetState(@SW_SHOW)

While 1
    _checkWIN()
    _nMGP()
WEnd

Func _nMGP()
    Sleep(0010)
    $pos = MouseGetPos()
    If not IsArray($pos) then return 
    $_color = PixelGetColor($pos[0],$pos[1])
    GUICtrlSetData($startLAB, ' X: ' & $pos[0] & ', Y: ' & $pos[1] & ', C: ' & $_color)
    If $DT = 1 Then
        $xcalcR = .95 * @DesktopWidth
        $xcalcL = .05 * @DesktopWidth
        $ycalc = .90 * @DesktopHeight
        If $pos[1] > $ycalc Then
            $wposy = $pos[1] - $yoffset * 2; If too close to bottom of screen position above mouse pointer
        Else
            $wposy = $pos[1] + $yoffset; Position label beneath the mouse pointer
        EndIf
        If $pos[0] > $xcalcR Then; If too close to right side of screen move it
            $wposx = $pos[0] - $xoffset * 3
        ElseIf $pos[0] < $xcalcL Then; If too close to left side of screen move it
            $wposx = $pos[0] + 10
        Else
            $wposx = $pos[0] - $xoffset; Use normal offsets for positioning label
        EndIf
    Else
        _clientmouse()
    EndIf
    WinMove($title, "", $wposx, $wposy); Move the label appropriate to follow the mouse
EndFunc  ;==>_nMGP
Func _checkWIN()
    $cWIN = WinGetTitle("[ACTIVE]")
    If $cWIN <> $title Then
        TrayTip("", $cWIN, 30)
        Opt("MouseCoordMode", 0)
        $DT = 0
    Else
        TrayTip("", "DESKTOP", 30)
        Opt("MouseCoordMode", 1)
        $DT = 1
    EndIf
EndFunc  ;==>_checkWIN

Func _clientmouse()
    Opt("MouseCoordMode", 1)
    $tpos = MouseGetPos()
    $_color = PixelGetColor($tpos[0],$tpos[1])
    Global $cpos = WinGetPos($cWIN)
    If not IsArray($cpos) then return 
    $xcalcR = .95 * $cpos[2]
    $xcalcL = .05 * $cpos[2]
    $ycalc = .90 * $cpos[3]
    If $tpos[1] > $ycalc Then
        $wposy = $tpos[1] - $yoffset * 2; If too close to bottom of screen position above mouse pointer
    Else
        $wposy = $tpos[1] + $yoffset; Position label beneath the mouse pointer
    EndIf
    If $tpos[0] > $xcalcR Then; If too close to right side of screen move it
        $wposx = $tpos[0] - $xoffset * 3
    ElseIf $tpos[0] < $xcalcL Then; If too close to left side of screen move it
        $wposx = $tpos[0] + 10
    Else
        $wposx = $tpos[0] - $xoffset; Use normal offsets for positioning label
    EndIf
EndFunc  ;==>_clientmouse

Func _color()
    Local $_cpos = MouseGetPos()
    Local $pcolor
    $pcolor = PixelGetColor($_cpos[0],$_cpos[1])
    $hexV = "0x" & Hex($pcolor,6)
    Local $fOpen = FileOpen(@ScriptDir & "\color.txt",1) 
   ;FileWrite($fOpen,@CRLF & _NowDate() & " " & _NowTime() & " : " & "X: " & $_cpos[0] & _ 
    ;   "," & "Y: " & $_cpos[1] & " | " & "Hex: " & $hexV & " Color: " & $pcolor)
    ;FileWrite($fOpen,@CRLF & "(PixelGetColor(" & $_cpos[0] & "," & $_cpos[1] & ") = " & $pcolor) & ")")
        FileWrite($fOpen,@CRLF & "(PixelGetColor(" & $_cpos[0] & "," & $_cpos[1] & _
        ") = " & $pcolor & ")")
    FileClose($fOpen)
EndFunc

Func Terminate()
    Exit 0
EndFunc  ;==>Terminate

http://sites.google.com/site/autoitprogramming/

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...