Sign in to follow this  
Followers 0
mrnoob

AutoIT Game Playing

10 posts in this topic

Hey guys, maybe you can help me with my fairly simple problem. I just started using AutoIT and I wanted to make a script that plays a very simply online flash game.

Basically, there is ball that falls from the top of the screen and you have to click it to prevent it from hitting the ground. My code checks a line of pixels at about the middle of the screent which the ball must pass through to hit the ground, when it sees that a pixel changed colors, it clicks at that coordinant. I have most of the code, the only thing I'm wrestling with is storing the coordinant that the pixel changed color to use for the mouse click. Any suggestions?

$answer = MsgBox(1, "Confirm", "Zurroball AI?")

If $answer = 2 Then
    Exit
EndIf

$Checksum = PixelChecksum (25,140, 520,140, 2)

While $Checksum = PixelChecksum (25,140, 25,140,2)
    Sleep(10)
WEnd

MouseClick("Left", 0, 0, 2, 0)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

From the help file for PixelChecksum:

Remarks

Performing a checksum of a region is very time consuming, so use the smallest region you are able to reduce CPU load. On some machines a checksum of the whole screen could take many seconds!

A checksum only allows you to see if "something" has changed in a region - it does not tell you exactly what has changed.

When using a step value greater than 1 you must bear in mind that the checksumming becomes less reliable for small changes as not every pixel is checked.

Does the ball always pass the same place? if so PixelGetColor may be more of what your looking for.

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Acutally if it is a "Line", rather than using PixelGetColor() because you'll have to do many instances or put it in a loop, or PixelCheckSum() not a speedy choice, if the colour is constant, use PixelSearch(), has the ability to find a colour from point "A" to point "B" with coords.

Example:

Opt("PixelCoordMode", 2); may be different if screen or window coords
While 1
    $PixSearch = PixelSearch(100, 0, 100, 0, 0xFF0000); straight line across
    If Not @error Then
        MouseClick("Left", $PixelSearch[0], $PixelSearch[1], 1, 1)
    EndIf
    Sleep(60)
Wend

Good Luck!


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks to both of you, I'm much better off now. Just one little problem left. When AutoIt detects the ball, it moves the mouse and clicks, but outside the box. Im sure its just a simple problem with the Coords and their settings.

Somthing else I anticipated also began to happen, the script cannot detect the passing of the ball fast enough to click. I think Ill make two scripts that work in tandem, each covering half the line.

$answer = MsgBox(1, "Confirm", "Zurroball AI?")

If $answer = 2 Then
    Exit
EndIf

Opt("PixelCoordMode", 2); may be different if screen or window coords
While 1
    $PixelSearch = PixelSearch(0, 100, 500, 100, 0x52DF98, 15); straight line across
    If Not @error Then
        MouseClick("Left", $PixelSearch[0], $PixelSearch[1], 2, 0)
    EndIf
Wend
Edited by mrnoob

Share this post


Link to post
Share on other sites

It has to do with the area your searching, the PixelSearch box is to large. So if you made to seperate scripts that could help. Also play around with the speed of the mouse.

speed [optional] the speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.

Im dealing with this problem with my cheat...


[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Share this post


Link to post
Share on other sites

What game is this? Could you post (or PM me) the link? I'd like to test a theory I had.

My idea is this - by the time you catch the pixel the ball will have moved past the line.. well how about making the mouse click a little below the line? Or even, use a quick calculation to determine exactly where the ball will be and click there. Just an idea that I'd like to test....

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Yes, I thought that might be a problem as well, but I still have to get the mouse to click in the correct spot before I can test this.

I think now the coding is working properly, it is really now a matter of getting it to work in the real world. The problem with simply offsetting the MouseClick is that the ball does not have a uniform velocity. Sometimes it may need to be set down 5 pixels, sometimes 40.

Well, if I had 500 scripts running at the same time, I could have them each click one pixel every 1Ms =D

http://www.neopets.com/games/zurroball.phtml

Edited by mrnoob

Share this post


Link to post
Share on other sites

I made this script for fun, it definitely doesn't do all the clicking for you perfectly, but instead simply clicks as fast as it can wherever your mouse is as long as you have the space bar held down. Of course, you could remove the space bar requirements and just have it clicking constantly, but I figured I'd let you have it wait around just in case.

#include <misc.au3>

HotKeySet ("{ESC}", "quitgame")
HotKeySet ("g", "goclicky")


Func goclicky()
    While 1
        If _IsPressed ('20') Then
            MouseClick ("left", MouseGetPos (0), MouseGetPos (1), 1, 0)
        EndIf
    WEnd
EndFunc

Func quitgame()
    Exit
EndFunc

While 1
    Sleep (100)
WEnd

You press ESC to quit the script, and "g" to start the click checking. _IsPressed('20') checks for the spacebar.

If you don't want that, just remove the if/endif lines.

Share this post


Link to post
Share on other sites

The thing about that is, the ball color is not constant over the entire ball, and on each turn it changes color (slightly). Plus, the old balls just sit on the ground, so any pixel searching could pick them up and miss the real ball in the air.

Share this post


Link to post
Share on other sites

Actually.... Try this - At the top of your script (Replace the "2's" with 0 or 1 if you're using window or screen coords (Look under: Options/Coord Mode in AutoInfo tool to see what your settings are)

Opt("PixelCoordMode", 2)
Opt("MouseCoordMode", 2)

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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