Sign in to follow this  
Followers 0
miketh2005

Making a bot with pixelsearch.

28 posts in this topic

#1 ·  Posted (edited)

Hello, I have made a simple program in AutoIT before, but I really don't know where to start on how about making a bot with pixel search.

First, how would I get the coordinates of a particular region. Like, say I wanted my whole screen (which is 1280 by 1024) to be searched. What would be the coords?

PixelSearch( coord, coord, coord, coord, B20000 )

Would be searching for a shade of red, which is B20000. Lets say I wanted it to search in a particular region. How would I get the coords for that region?

That is the first step. Now, I want it to double click at that area if it finds it. I have no idea how to do this...

$coord = PixelSearch( coord, coord, coord, coord, B20000 )
If Not @error Then
    MouseClick("primary", $coord[0], $coord[1], 2)
EndIf

This would work if the coords were in, right?

So, first half is basically done.

Now I want it to WAIT 5 seconds, then click at a particular place, which again, I need to know the x and y coords for.

$coord = PixelSearch( coord, coord, coord, coord, B20000 )
If Not @error Then
    MouseClick("primary", $coord[0], $coord[1], 2)
        Sleep(5000) ;five seconds
        MouseClick("primary", x, y)
EndIf

Now its basically done, except if it DOESN'T find something I want it to try again, until it finds something or I end the script. How will I do this? Like If @error Then restartlooop or something.

If it DOES find something, it will do the above, but I want it to restart at the beginning of the script, after it is done. I would imagine some type of loop de loop thing, but I don't have a clue where to start. How will I do this?

Thanks for all your help, guys!

Edited by miketh2005

Share this post


Link to post
Share on other sites



The parameters of PixelSearch() are left, top, right, bottom, color. So your entire 1280x1024 screen for that shade of red would be PixelSearch(0, 0, 1280, 1024, 0xB20000). Notice the 0x before your color. And you're right as to what PixelSearch() returns, so your MouseClick() is right. I hope that helps.


For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

The parameters of PixelSearch() are left, top, right, bottom, color. So your entire 1280x1024 screen for that shade of red would be PixelSearch(0, 0, 1280, 1024, 0xB20000). Notice the 0x before your color. And you're right as to what PixelSearch() returns, so your MouseClick() is right. I hope that helps.

What about the last 2 paragraphs? Thanks.

Share this post


Link to post
Share on other sites

Anyone? I really need help with the looping and stuff, please!

Share this post


Link to post
Share on other sites

How do I make it so that if it finds nothing after 30 seconds it do another function?

Ok, this script doesn't work at all. I don't know why:

Func Bot()
    $coord = PixelSearch(0, 0, 4, 187, 0xB20000)
    If Not @error Then
        MouseClick("primary", $coord[0], $coord[1], 2)
        Sleep(5000) ;five seconds
        MouseClick("primary", 1230, 167)
        Bot()
    EndIf

    If @error Then
        Bot()
    EndIf
EndFunc   ;==>Bot

Did all the helpful people leave? :D

*Last Post*

Share this post


Link to post
Share on other sites

How do I make it so that if it finds nothing after 30 seconds it do another function?

Ok, this script doesn't work at all. I don't know why:

Func Bot()
    $coord = PixelSearch(0, 0, 4, 187, 0xB20000)
    If Not @error Then
        MouseClick("primary", $coord[0], $coord[1], 2)
        Sleep(5000) ;five seconds
        MouseClick("primary", 1230, 167)
        Bot()
    EndIf

    If @error Then
        Bot()
    EndIf
EndFunc   ;==>Bot

Did all the helpful people leave? :D

*Last Post*

It should work for about 6 hours when it will then crash.

You can't have a function repeatedly recursively calling itself for ever. You need to provide a method to exit the function. Preferably you should use loop instead of recursion.


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

It should work for about 6 hours when it will then crash.

You can't have a function repeatedly recursively calling itself for ever. You need to provide a method to exit the function. Preferably you should use loop instead of recursion.

Thanks.

How about this? I made it so that it exits if nothing happens within 30 seconds :D

HotKeySet("{PGUP}", "Bot")

Func Bot()
    $var = 0
    $coord = PixelSearch(0, 0, 4, 187, 0xB20000)
    If Not @error Then
        MouseClick("primary", $coord[0], $coord[1], 2)
        Sleep(5000) ;five seconds
        MouseClick("primary", 1230, 167)
        Bot()
    EndIf

    If @error Then
        Sleep(1000) ;one second
        $var = $var + 1
        Bot()
    EndIf

    If $var = 30 Then
        Exit
    EndIf
EndFunc   ;==>Bot

It still doesn't work, though, it exits by itself, I didn't even hit the hotkey yet... :D Please help, this is confusing.

Edited by miketh2005

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

$bot = 0 ;Define bot

if "{PGUP}" Then 
    $bot = 1 ;when you press pageup make bot = 1
    Endif
if "{PGDN}" Then
    $bot = 0 ;when you press pagedown make bot = 0
    Endif

While $bot = 1 ;a simple loop, that is always on when bot = 1
    $coord = PixelSearch(0, 0, 4, 187, 0xB20000)
    If @error Then ;it's better to do, if it fails first
    $Start = TimerInit() ;a timer that starts when it doesn't count the pixel
    Else ;Else function, meaning if that doesn't happen, then do this
            MouseClick("primary", $coord[0], $coord[1], 2)
        Sleep(5000) ;five seconds
        MouseClick("primary", 1230, 167)
    EndIf

    If TimerDiff($Start) > 30 Then ;when the timer is over 30 the script will exit
        Exit
    EndIf
WEnd ;Ending the While loop

I noted it, read what I wrote.

Edited by Metigue

Share this post


Link to post
Share on other sites

$bot = 0 ;Define bot

if "{PGUP}" Then 
    $bot = 1 ;when you press pageup make bot = 1
    Endif
if "{PGDN}" Then
    $bot = 0 ;when you press pagedown make bot = 0
    Endif

While $bot = 1 ;a simple loop, that is always on when bot = 1
    $coord = PixelSearch(0, 0, 4, 187, 0xB20000)
    If @error Then ;it's better to do, if it fails first
    $Start = TimerInit() ;a timer that starts when it doesn't count the pixel
    Else ;Else function, meaning if that doesn't happen, then do this
            MouseClick("primary", $coord[0], $coord[1], 2)
        Sleep(5000) ;five seconds
        MouseClick("primary", 1230, 167)
    EndIf

    If TimerDiff($Start) > 30 Then ;when the timer is over 30 the script will exit
        Exit
    EndIf
WEnd ;Ending the While loop

I noted it, read what I wrote.

Thanks, I learned alot, but... it still doesn't wanna work! :D I started it, but it just ends without doing anything. Does it work for you?

Share this post


Link to post
Share on other sites

Thanks, I learned alot, but... it still doesn't wanna work! :D I started it, but it just ends without doing anything. Does it work for you?

It would end without doing anything lol.

It's not finding the pixel and My timerdiff = 30,

thats 30 MS not 30 seconds, lol

30000 MS = 30 seconds

Share this post


Link to post
Share on other sites

I changed it to: If TimerDiff($Start) > 30000 Then ;when the timer is over 30 the script will exit

And it still ends right away. I didnt even press the PgUP button.

Share this post


Link to post
Share on other sites

I changed it to: If TimerDiff($Start) > 30000 Then ;when the timer is over 30 the script will exit

And it still ends right away. I didnt even press the PgUP button.

Thats odd, it's fine for me.

Share this post


Link to post
Share on other sites

HMM! That IS weird! What version are you using?

Share this post


Link to post
Share on other sites

HMM! That IS weird! What version are you using?

I don't even know rofl

try doing this instead of my if statements at the top:

HotKeySet("{PGUP}", $Bot = 1)
HotKeySet("{PGDN}", $Bot = 0)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Hello, I have made a simple program in AutoIT before, but I really don't know where to start on how about making a bot with pixel search.

First, how would I get the coordinates of a particular region. Like, say I wanted my whole screen (which is 1280 by 1024) to be searched. What would be the coords?

PixelSearch( coord, coord, coord, coord, B20000 )

Would be searching for a shade of red, which is B20000. Lets say I wanted it to search in a particular region. How would I get the coords for that region?

That is the first step. Now, I want it to double click at that area if it finds it. I have no idea how to do this...

$coord = PixelSearch( coord, coord, coord, coord, B20000 )
If Not @error Then
    MouseClick("primary", $coord[0], $coord[1], 2)
EndIf

This would work if the coords were in, right?

So, first half is basically done.

Now I want it to WAIT 5 seconds, then click at a particular place, which again, I need to know the x and y coords for.

$coord = PixelSearch( coord, coord, coord, coord, B20000 )
If Not @error Then
    MouseClick("primary", $coord[0], $coord[1], 2)
        Sleep(5000) ;five seconds
        MouseClick("primary", x, y)
EndIf

Now its basically done, except if it DOESN'T find something I want it to try again, until it finds something or I end the script. How will I do this? Like If @error Then restartlooop or something.

If it DOES find something, it will do the above, but I want it to restart at the beginning of the script, after it is done. I would imagine some type of loop de loop thing, but I don't have a clue where to start. How will I do this?

Thanks for all your help, guys!

i havent seen any posts that are actually helpful to you.. i've worked a lot with this script myself so here's a few ideas for you:

Global $ON = False
Global $color = 0xB20000
Global Const $SM_VIRTUALWIDTH = 78
Global Const $SM_VIRTUALHEIGHT = 79

$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
$VirtualDesktopHeight = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT)
$VirtualDesktopHeight = $VirtualDesktopHeight[0]

$x1 = Number($VirtualDesktopWidth/2)
$y1 = Number($VirtualDesktopHeight/2)
$x2 = $x1-175
$y2 = $x1+125
$x3 = $y1-300
$y3 = $y1+300

    If $ON = True Then
        $coord = PixelSearch($x2, $x3, $y2, $y3, $color, 10, 2)
        If IsArray($coord) = 1 Then
            MouseClick("left", coord[0], coord[1], 2)
                        Sleep(500) << thats 5 seconds.. Sleep(5000) << thats 50 seconds
        EndIf

this is to define the scanbox using the resolution of the active window.. to define better where your scanbox is you need to edit the $x and $y variables.. the current set for them creates a box 300 pixels wide and 600 pixels tall around the center of your screen

Global $ON = False
Global $color = 0xB20000

$x1 = @DesktopWidth/2
$y1 = @DesktopHeight/2
$x2 = $x1-175
$y2 = $x1+125
$x3 = $y1-300
$y3 = $y1+300

    If $ON = True Then
        $coord = PixelSearch($x2, $x3, $y2, $y3, $color, 3, 2)
        If IsArray($coord) = 1 Then
            MouseClick("left", coord[0], coord[1], 2)
            Sleep(500)
        EndIf

this is to define the box using the resolution of your desktop.. again its the same as the first one just edit the $x and $y variables

the one thing i've seen repeated is the same mistake over and over in this thread.. 100 MS = 1 S.. in other words 1000 milliseconds = 10 seconds.. you need 500 milliseconds for 5 seconds.. 50,000 or 30,000 for the timer isn't for 50 or 30 seconds, those say 500 and 300 seconds.. basically however many seconds you need like 5, you add ONLY 2 zero's at the end to make it in milliseconds.. 30 seconds is 3000 milliseconds, not 30000

Edited by demandnothing

Share this post


Link to post
Share on other sites

1 millisecond = 0.001 seconds so actually 1 second is 1000 milliseconds

Share this post


Link to post
Share on other sites

i havent seen any posts that are actually helpful to you.. i've worked a lot with this script myself so here's a few ideas for you:

Global $ON = False
Global $color = 0xB20000
Global Const $SM_VIRTUALWIDTH = 78
Global Const $SM_VIRTUALHEIGHT = 79

$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
$VirtualDesktopHeight = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT)
$VirtualDesktopHeight = $VirtualDesktopHeight[0]

$x1 = Number($VirtualDesktopWidth/2)
$y1 = Number($VirtualDesktopHeight/2)
$x2 = $x1-175
$y2 = $x1+125
$x3 = $y1-300
$y3 = $y1+300

    If $ON = True Then
        $coord = PixelSearch($x2, $x3, $y2, $y3, $color, 10, 2)
        If IsArray($coord) = 1 Then
            MouseClick("left", coord[0], coord[1], 2)
                        Sleep(500) << thats 5 seconds.. Sleep(5000) << thats 50 seconds
        EndIf

this is to define the scanbox using the resolution of the active window.. to define better where your scanbox is you need to edit the $x and $y variables.. the current set for them creates a box 300 pixels wide and 600 pixels tall around the center of your screen

Global $ON = False
Global $color = 0xB20000

$x1 = @DesktopWidth/2
$y1 = @DesktopHeight/2
$x2 = $x1-175
$y2 = $x1+125
$x3 = $y1-300
$y3 = $y1+300

    If $ON = True Then
        $coord = PixelSearch($x2, $x3, $y2, $y3, $color, 3, 2)
        If IsArray($coord) = 1 Then
            MouseClick("left", coord[0], coord[1], 2)
            Sleep(500)
        EndIf

this is to define the box using the resolution of your desktop.. again its the same as the first one just edit the $x and $y variables

the one thing i've seen repeated is the same mistake over and over in this thread.. 100 MS = 1 S.. in other words 1000 milliseconds = 10 seconds.. you need 500 milliseconds for 5 seconds.. 50,000 or 30,000 for the timer isn't for 50 or 30 seconds, those say 500 and 300 seconds.. basically however many seconds you need like 5, you add ONLY 2 zero's at the end to make it in milliseconds.. 30 seconds is 3000 milliseconds, not 30000

Thanks for your help, but you just made the script very complicated, and as I see it, it does the same thing, (I'm only using it on my own computer so i dont need all that) but it still doesn't work on my computer :D Even after I fixed a few mistakes.

Also, 1000 milliseconds = 1 second. Google it.

I don't know what to do, why isn't this script working for me???

Share this post


Link to post
Share on other sites

I don't even know rofl

try doing this instead of my if statements at the top:

HotKeySet("{PGUP}", $Bot = 1)
HotKeySet("{PGDN}", $Bot = 0)

When I do that it says:

>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "C:\rce_aw_Wierd\bot.au3"

C:\rce_aw_Wierd\bot.au3 (3) : ==> Unknown function name.:

HotKeySet("{PGUP}", $bot = 1)

When I did your other one it said:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\rce_aw_Wierd\adflasherbot.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams

+>21:21:44 Starting AutoIt3Wrapper v.2.0.0.1 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 3 CPU:X64 OS:X86)

>Running AU3Check (1.54.14.0) from:C:\Program Files\AutoIt3

+>21:21:44 AU3Check ended.rc:0

>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "C:\rce_aw_Wierd\adflasherbot.au3"

+>21:21:45 AutoIT3.exe ended.rc:0

+>21:21:46 AutoIt3Wrapper Finished

>Exit code: 0 Time: 3.015

Share this post


Link to post
Share on other sites

Hotkeys link keys to functions. You would have to do this.

HotKeySet("{PGUP}", "pageup")

Func pagedown()
    $Bot = 1
EndFunc

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

Thanks, but it still doesn't work, it ends right away... ? What should I do? Does it work for you?

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  
Followers 0