Jump to content
Sign in to follow this  
Jason786

Could someone help me out with this please :)

Recommended Posts

Jason786

Hey, basically I'm trying to make a auto that when I press a button, it scans the screen for that pixel and clicks on it where ever it is, the pixel location changes randomly

At the moment I have this, but it doesn't do anything, and I'm pretty sure it will fail to compile

Any help would be great, like explaining what I've done wrong etc

HotKeySet("{a}", "_Start")
HotKeySet("{s}", "_Pause")
HotKeySet("{d}", "_Exit")

Global $Active = 0

While 1
    If $Active = 1 Then
        $SquarePosition = PixelSearch(0, 0, 0, 0, 0x941616)
        If IsArray($SquarePosition) Then
            MouseMove($SquarePosition) Then
            MouseClick("left")
        EndIf
    EndIf
WEnd

Func _Start()
    $Active = 1
EndFunc   ;==>_Start

Func _Pause()
    $Active = 0

EndFunc   ;==>_Pause

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Share this post


Link to post
Share on other sites
omikron48

The way you this set up, you are scanning a single pixel for the color value, at the top left most pixel too.

PixelSearch works on a bounded rectangle. You give it the coordinates defining the bounds. The coordinate system works kinda like this.

#0123456...X
0
1
2 Q----Q
3 |    |
4 Q----Q
5
6
.
.
.
Y

If you want to search the rectangle bound by the Q(s), you need to use these parameters:

PixelSearch(1, 2, 6, 4, 0x941616)

Also, you don't need to move the mouse before you do a click. MouseClick can also accept coordinates so it will click at a specified location.

MouseMove($SquarePosition)
MouseClick("left")

Is equivalent to:

MouseClick("left", $SquarePosition[0], $SquarePosition[1])

Lastly, the reason your code does not compile is because you have a syntax error in the body of your If...Then...EndIf code block.

While 1
    If $Active = 1 Then
        $SquarePosition = PixelSearch(0, 0, 0, 0, 0x941616)
        If IsArray($SquarePosition) Then
            MouseMove($SquarePosition) Then ;<- Syntax Error
            MouseClick("left")
        EndIf
    EndIf
WEnd

The correct syntax would be this. (Also added a Sleep in there since it's not a good idea to make an infinite loop without a Sleep stuck in because it makes your script eat up processor cycles like crazy):

While 1
    If $Active = 1 Then
        $SquarePosition = PixelSearch(0, 0, 0, 0, 0x941616)
        If IsArray($SquarePosition) Then
            MouseMove($SquarePosition) ;Removed the 'Then'
            MouseClick("left")
        EndIf
    EndIf
    Sleep(10) ;Added small sleep to prevent hogging of processor
WEnd
Edited by omikron48

Share this post


Link to post
Share on other sites
Jason786

Thanks a lot! It worked, but I found out there are sometimes different pixels

How would I go about scanning for 3-4 different pixels? Only 1 appears up at a certain time

HotKeySet("{a}", "_Start")
HotKeySet("{s}", "_Pause")
HotKeySet("{d}", "_Exit")

Global $Active = 0

While 1
    If $Active = 1 Then
        $SquarePosition = PixelSearch(0, 0, 1696, 1036, 0x941616)
        If IsArray($SquarePosition) Then
            MouseClick("left", $SquarePosition[0], $SquarePosition[1])
        EndIf
    EndIf
    Sleep(10)
WEnd

Func _Start()
    $Active = 1
EndFunc   ;==>_Start

Func _Pause()
    $Active = 0

EndFunc   ;==>_Pause

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Edited by Jason786

Share this post


Link to post
Share on other sites
omikron48

You can just do four PixelSearches and check which results into a returned array, then process it with the MouseClick.

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.