Advertisement
NJ5SkwAg

pixelsearch script

Apr 22nd, 2019
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5. #SingleInstance Force
  6.  
  7. searchQuadrantA() {
  8.     global
  9.     sleep, 250
  10.     ;This should be a function so i can loop until it ends
  11.     MouseMove, x1%a%, y1%a% ;The search square x1, y1
  12.     sleep, 500
  13.     MouseMove, x2%a%, y2%a% ;The search square x2, y2
  14.     sleep, 500
  15.     PixelSearch, Fx%a%, Fy%a%, x1%a%, y1%a%, x2%a%, y2%a%, 0xFFFFFF, 1, Fast
  16.     If (ErrorLevel == 1)
  17.         Return
  18.     If (ErrorLevel == 0) {
  19.         sleep, 1000
  20.         MouseMove, Fx%a%, Fy%a%
  21.         ;Here is where the function should be, for what you want to happen in the pixel or image
  22.         ControllerA%a% := 1 ;Activate controllers that check if quadrants exist or if pixel is in one of the edge of the screen.
  23.         ControllerC%a% := 1
  24.         ;If Fx1 is the start and the area (10), then it means it we have no A quadrant only b and c
  25.         If (Fx%a% <= x1%a%)
  26.             ControllerA%a% := 0
  27.         If (Fx%a% >= x2%a%)
  28.             ControllerC%a% := 0
  29.         MsgBox % "SearchQuadrant A `n"
  30.         . "ControllerA%a% " ControllerA%a% "`n"
  31.         . "ControllerC%a% " ControllerC%a% "`n"
  32.         . "Fx " Fx%a% "`n"
  33.         . "Fy " Fy%a% "`n"
  34.         . "x1 " x1%a% "`n"
  35.         . "y1 " y1%a% "`n"
  36.         . "x2 " x2%a% "`n"
  37.         . "y2 " y2%a% "`n"
  38.         . "Number " a "`n"
  39.         sleep, 500
  40.  
  41.         ;#################### SEARCH A.A. QUADRANT A FROM QUADRANT A #####################
  42.         If (ControllerA%a% == 1) {
  43.             PreFx := Fx%a% ;save "previous" ( or current coordinates into variables so i can operate with the new ones)
  44.             PreFy := Fy%a%
  45.             Prex1 := x1%a%
  46.             Prey1 := y1%a%
  47.             Prex2 := x2%a%
  48.             Prey2 := y2%a%
  49.             a++ ;increases the number of a so that we can record the next coordinates for the next search
  50.             MsgBox % "after a ++ a is now " a "`n" ;lets the use know a new search will be performed
  51.             x1%a% := Prex1 ;x 190
  52.             y1%a% := PreFy + 2 ;1 below ; if the reading of pixels is from left to right
  53.             x2%a% := PreFx
  54.             y2%a% := Prey2
  55.             MsgBox % "SearchQuadrantA from another Quadrant A`n" ;This is to let the user know a search will be conducted on a quadrant A coming from a quadrant A
  56.             searchQuadrantA()
  57.             a-- ;After the search is done, we go to the previous values, so to perform a search on the C quadrant now.
  58.             MsgBox % "after a-- a is now " a "`n"
  59.         }
  60.  
  61.         ;#################### SEARCH A.C. QUADRANT A FROM QUADRANT C #####################
  62.         If (ControllerC%a% == 1) {
  63.             PreFx := Fx%a% ;save previous (current coordinates into variables so i can operate with the new ones)
  64.             PreFy := Fy%a%
  65.             Prex1 := x1%a%
  66.             Prey1 := y1%a%
  67.             Prex2 := x2%a%
  68.             Prey2 := y2%a%
  69.             a++
  70.             MsgBox % "after a++ a is now " a "`n"
  71.             x1%a% := PreFx + 2 ;its to the right of last Found pixel
  72.             y1%a% := PreFy ;its on the same line
  73.             x2%a% := Prex2 ;its to the right
  74.             y2%a% := Prey2
  75.             MsgBox % "SearchQuadrantC from A`n"
  76.             searchQuadrantC()
  77.             a--
  78.             MsgBox % "after a -- a is now " a "`n"
  79.         }
  80.     }
  81. }
  82.  
  83. searchQuadrantC() {
  84.     global
  85.     sleep, 500
  86.     MouseMove, x1%a%, y1%a%
  87.     sleep, 500
  88.     MouseMove, x2%a%, y2%a%
  89.     sleep, 500
  90.     PixelSearch, Fx%a%, Fy%a%, x1%a%, y1%a%, x2%a%, y2%a%, 0xFFFFFF, 1, Fast
  91.     If (ErrorLevel == 1)
  92.         Return
  93.     If (ErrorLevel == 0) {
  94.         sleep, 1000
  95.         MouseMove, Fx%a%, Fy%a%
  96.         MsgBox % "Found a Pixel in C"
  97.         ControllerA%a% := 1  ;Activate controllers that check for quandrant, no need you can simply do ++, but anyways
  98.         ControllerC%a% := 1
  99.         If (Fx%a% <= x1%a% )
  100.             ControllerA%a% := 0 ;If Fx1 is the start and the area (10), then it means it we have no A quadrant only b and c
  101.  
  102.         ;#################### SEARCH C.A. QUADRANT C FROM QUADRANT A #####################
  103.         If (ControllerA%a% == 1) {
  104.             PreFx := Fx%a% ;save previous (current coordinates into variables so i can operate with the new ones)
  105.             PreFy := Fy%a%
  106.             Prex1 := x1%a%
  107.             Prey1 := y1%a%
  108.             Prex2 := x2%a%
  109.             Prey2 := y2%a%
  110.             a++
  111.             MsgBox % "after a ++ a is now " a "`n"
  112.             x1%a% := Prex1
  113.             y1%a% := PreFy + 2
  114.             x2%a% := PreFx
  115.             y2%a% := Prey2
  116.                     MsgBox % "SearchQuadrant A from Quadrant C`n"
  117.             searchQuadrantA()
  118.             a--
  119.             MsgBox % "after a-- a is now " a "`n"
  120.         }
  121.         ;And here you should make a loop to check Quadrant A that will break at Ay2 and continue to the next quadrants
  122.  
  123.         ;#################### SEARCH C.C. QUADRANT C FROM QUADRANT C #####################
  124.         If (ControllerC%c% == 1) {
  125.             PreFx := Fx%a% ;save previous (current coordinates into variables so i can operate with the new ones)
  126.             PreFy := Fy%a%
  127.             Prex1 := x1%a%
  128.             Prey1 := y1%a%
  129.             Prex2 := x2%a%
  130.             Prey2 := y2%a%
  131.             a++
  132.             MsgBox % "after a++ a is now " a "`n"
  133.             x1%a% := PreFx + 1 ;its to the right
  134.             y1%a% := PreFy + 1 ;its on the same line
  135.             x2%a% := Prex2 ;its to the right
  136.             y2%a% := Prey2
  137.             MsgBox % "SearchQuadrant C from Quadrant C`n"
  138.             searchQuadrantC()
  139.             a--
  140.             MsgBox % "after a-- a is now " a "`n"
  141.         }
  142.         a--
  143.         MsgBox % "after a -- a is now " a "`n"
  144.     }
  145. }
  146. ;########################################################
  147. ;###################  ACTUAL START ######################
  148. ;########################################################
  149. ;«::
  150. f1::
  151. CoordMode, Mouse, screen
  152. CoordMode, Pixel, screen
  153. Cropx1 := 100
  154. Cropy1 := 100
  155. Area := 50
  156. x11 := 0 + Cropx1
  157. y11 := 0 + Cropy1
  158. a := 0
  159. ;725
  160. x21 := A_ScreenWidth - Cropx1
  161. y21 := A_ScreenHeight - 175 - Cropy1 ;counting with the game gui ;725 - 900 = 175 + 100 = 275
  162. ;################################################################
  163. ;##################### FIRST PIXEL SEARCH #######################
  164. ;################################################################
  165. a++
  166. PixelSearch, Fx%a%, Fy%a%, x1%a%, y1%a%, x2%a%, y2%a%, 0xFFFFFF, 1, Fast ;Fx1 f stands for found is the main and first pixel found
  167.  
  168. If (ErrorLevel == 0) {
  169.     sleep, 250
  170.     MouseMove Fx%a%, Fy%a% ; pixel detected, move
  171.     ControllerA%a% := 1  ;Activate controllers that check for quandrant
  172.     ControllerC%a% := 1
  173.     If (Fx%a% <= x1%a% + 1)
  174.         ControllerA := 0
  175.     If (Fx%a% >= x2%a% - 1)
  176.         ControllerC%a% := 0
  177.     MsgBox % "SearchQuadrant A `n"
  178.     . "ControllerA%a% " ControllerA%a% "`n"
  179.     . "ControllerC%a% " ControllerC%a% "`n"
  180.     . "Fx " Fx%a% "`n"
  181.     . "Fy " Fy%a% "`n"
  182.     . "x1 " x1%a% "`n"
  183.     . "y1 " y1%a% "`n"
  184.     . "x2 " x2%a% "`n"
  185.     . "y2 " y2%a% "`n"
  186.     . "a " a "`n"
  187.     sleep, 500
  188.     If (ControllerA%a% == 1) {
  189.         PreFx := Fx%a% ;save "previous" (current coordinates into variables so i can operate with the new ones)
  190.         PreFy := Fy%a%
  191.         Prex1 := x1%a%
  192.         Prey1 := y1%a%
  193.         Prex2 := x2%a%
  194.         Prey2 := y2%a%
  195.         a++
  196.         x1%a% := Prex1
  197.         y1%a% := PreFy + 1
  198.         x2%a% := PreFx
  199.         y2%a% := Prey2
  200.         searchQuadrantA()
  201.     }
  202.     If (ControllerC%a% == 1) {
  203.         PreFx := Fx%a% ;save previous (current coordinates into variables so i can operate with the new ones)
  204.         PreFy := Fy%a%
  205.         Prex1 := x1%a%
  206.         Prey1 := y1%a%
  207.         Prex2 := x2%a%
  208.         Prey2 := y2%a%
  209.         a++
  210.         x1%a% := PreFx
  211.         y1%a% := PreFy
  212.         x2%a% := Prex2
  213.         y2%a% := Prey2
  214.         searchQuadrantC()
  215.         a--
  216.     }
  217. }
  218. return
  219.  
  220. +r::
  221. reload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement