Jump to content

Recommended Posts

Posted (edited)

I have been playing around with both functions trying to figure out which one is less demanding on the CPU when used on a 7x7 pixel grid.

PixelGetColor seems to be a little more accurate (about 90%) where PixelSearch is faster but less accurate (30% faster with a 70% accuracy).

Here is an example of how I went about it:

I used an Java Script shooting duck type game (shoot it as it goes by) as a basis.

;+------------------------------+;
;| Script: Autofire v1.0    |;
;| Author: CodeMaster Rapture    |;
;+------------------------------+;


;+---------+;
;| Hotkeys |;
;+---------+;

HotKeySet("{NUMPAD1}", "Fire_Mode")
HotKeySet("{NUMPAD2}", "Method")
HotKeySet("{NUMPADSUB}", "Terminate")

;+-----------+;
;| Variables |;
;+-----------+;
$already_firing = 0;Boolean
$method = 1;Boolean
$color = 0

;+------------------+;
;| Main Script Loop |;
;+------------------+;
While 1
   If $method = 1 Then
      $color = PixelSearch (637,509 , 643,515, 0x0000FF, 10, 1)
      If Not @error Then Fire()
   Else
;Let's search a 7x7 grid using PixelGetColor
;Simple Loops, ugly to look at
      Do
         For $x = 637 to 643
            For $y = 509 to 515
               $color = PixelGetColor($x,$y)
               If $color = 255 Then ExitLoop
            Next
            If $color = 255 Then ExitLoop
         Next
      Until $color = 255
      Fire()
      $color = 0
   EndIf
   Sleep(10)
WEnd

;+-----------+;
;| Functions |;
;+-----------+;

Func Fire_Mode()
    $fire_mode = $fire_mode + 1
    If $fire_mode > 3 Then $fire_mode = 1
EndFunc

Func Method()
    $method = $method *-1
EndFunc

Func Fire()
    $already_firing = 1
    If $fire_mode = 1 Then
        MouseClick("left")
        Sleep(50)
    ElseIf $fire_mode = 2 Then
        MouseDown("left")
        Sleep(50)
        MouseUp("left")
        Sleep(50)
    EndIf
    $already_firing = 0
EndFunc

Func Terminate()
    Exit 0
EndFunc

;+-------------+;
;| End of File |:
;+-------------+;

The code may seem a little ugly, but both methods work. I'm just wondering why the accuracy is not above 90% for either one. My machine is an AMD Athlon XP 2200+ with 1 gig of DDR ram, so I know it can handle searching 49 pixels every 10th of a second. And I figure, a basic Javascript game runs at 30 FPS, so that's 1 frame every 20ms. I also know that windows threads can get a bit complicated, so I tossed another 10ms into the equation so it works out to about 1 pixel being searched every frame.

The math behind this logic is:

60 seconds / 30 FPS = 2 FPS = 1 frame per 500ms

This While loop takes 1-3 ms to complete + 1-3ms per thread (proccesses running)

My average loop time comes to 16ms (including the sleep).

If it finds the blue pixel, that jumps to 66ms-566ms (Sleep function calls).

With all that explained, I should be able to successfully search and click once per frame. The odd thing is, it doesn't. It will not find a blue pixel when there is one there. I thought that maybe the pixel would vary a few shades, but that wasn't it either. It just blatantly ignores a pixel that IS there.

So, I'm trying to find the best bang for my buck, even if I have to cut the search time down so it can search more often, thus being more accurate by average. Also, which of the mouse control functions do you suggest. I tried both with odd and unpredictable results.

What are your opinion(s) on these functions?

Thanx.

Edited by CodeMaster Rapture
Posted

I know you said that the blue wouldnt vary that much but try the darkest blue to the light blue using < > (less then greater then) variables.

Like this

If PixelGetColor($x + $y ) > 16777150 AND PixelGetColor($x + $y) < 16777214 Then
Posted

I know you said that the blue wouldnt vary that much but try the darkest blue to the light blue using < > (less then greater then) variables.

Like this

If PixelGetColor($x + $y ) > 16777150 AND PixelGetColor($x + $y) < 16777214 Then

<{POST_SNAPBACK}>

Hmm, didn't even think to try it that way. I'll give it a shot and let ya know how it turns out. But in order for that statement above to be more accurate, you would prolly go about it this way:

$color = PixelGetColor($x,$y)
If $color > 16777150 AND $color < 1677214 Then (yada yada yada)

It would insure that it is comparing the same color and save a little CPU time by reducing the amount of PixelGetColor() calls per loop.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...