small trouble with pixel search

12/19/2013 19:19 coolraiman#1
hay guys. i am making a bot for a small pay to win browser flash game.

everything go nicely but sometimesthe crafter discover a new recipie and the item i want to craft change position so i use pixelsearch because new recipe names are blue instead of white until you craft them once.

i took a picture of the game and with photoshop i got the hexa value of the colour. if i set any sensibility (like 1) it always detect even if i put a black background. if i set it to 0 he detect nothing
here it is:
Code:
Global $newItemX = 250, $newItemY = 280, $newItemWidth = 100, $newItemHeight = 25, $newItemSpace = 105 , $newItemColor1 = 0x085b91


Func SelectItem()
   Local $try = 0
   ;MouseMove($newItemX + $xGamePos + $try * $selectItemSpaceX, $newItemY + $yGamePos, 0)
   While 1
	  Sleep(1000)
	  Local $coord = PixelSearch($newItemX + $xGamePos + $try * $selectItemSpaceX, $newItemY + $yGamePos, $newItemWidth, $newItemHeight, $newItemColor1, 0)
	  If Not @error Then
		 $try = $try + 1
		 ConsoleWrite($newItemX + $xGamePos + $try * $selectItemSpaceX)
	  Else
		 ExitLoop
	  EndIf
	  
	  If $try > 5 Then
		 ExitLoop
	  EndIf
   WEnd
   
   MouseMove($selectItemX + $xGamePos + $selectItemSpaceX * $try, $selectItemY + $yGamePos, 0)
   ;MouseClick("left")
EndFunc
the position he scan is good.
thanks for your help
12/19/2013 21:02 alpines#2
This is definitely not the whole script. Post your whole script maybe there's the error.
12/19/2013 21:05 coolraiman#3
Code:
#include <Timers.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include < Misc.au3 >
;constant
Global $TimerDay
Global $hGUI
Global $dayTimer, $fastTimer = 26000, $shortTimer, $mediumTimer, $longTimer, $veryLongTimer
Global $worker1, $worker2, $worker3
Global $starterTimer
Global $xGamePos, $yGamePos
;anti popup (may be moved in popupFunction
Global $endBuildingX = 700, $endBuildingY = 350, $endBuildingWidth = 100, $endBuildingHeight = 30, $endBuildingColor = 0x0094df
Global $endDaySuccesX = 470, $endDaySuccesY = 490, $endDaySuccesWidth = 15, $endDaySuccesHeight = 10, $endDaySuccesColor = 0x0093dd
;detect new recipie
Global $newItemX = 250, $newItemY = 280, $newItemWidth = 100, $newItemHeight = 25, $newItemSpace = 105 , $newItemColor1 = 0x085b91

Global $openShopX = 880 , $openShopY = 550
Global $workerX = 25, $workerY = 425, $workerSpace = 65
Global $selectItemX = 280, $selectItemY = 250, $selectItemSpaceX = 105

main()

Func main()
   ;local button
   Local $start, $xMousePos, $yMousePos, $xGamePosGUI, $yGamePosGUI
   ;gui init
   $hGUI = GUICreate("sword and potion bot",300,400)
   $start = GUICtrlCreateButton("start", 10, 10, 50, 40)
   ;mouse pos
   $xMousePos = GUICtrlCreateLabel("",80, 10,40,30)
   $yMousePos = GUICtrlCreateLabel("",80, 30,40,30)
   ;game pos
   $xGamePosGUI = GUICtrlCreateEdit("xGame",140,10, 60,40, $ES_NUMBER)
   $yGamePosGUI = GUICtrlCreateEdit("yGame",140,80, 60,40, $ES_NUMBER)
   
   $workerNumber = GUICtrlCreateEdit("workerNumber",140,140, 60,40, $ES_NUMBER)
   
   
   
   GUISetState(@SW_SHOW)
   
   while 1
	  Local $mousePos
	  $mousePos = MouseGetPos()
	  GUICtrlSetData($xMousePos, $mousePos[0])
	  GUICtrlSetData($yMousePos, $mousePos[1])
	  $msg = GUIGetMsg()
	  Switch $msg
		 Case $GUI_EVENT_CLOSE
			ExitLoop
		 Case $start
			;get game pos data
			$xGamePos = GUICtrlRead($xGamePosGUI)
			$yGamePos = GUICtrlRead($yGamePosGUI)
			bot()
	  EndSwitch
   WEnd
   ConsoleWrite("Killed All Timers? " & _Timer_KillAllTimers($hGUI) & @CRLF)
   GUIDelete()
EndFunc

Func bot()
   SelectItem()
EndFunc

Func StartDay()
   $dayTimer = _Timer_SetTimer($hGUI,100000,"EndDay")
   MouseMove($openShopX,$openShopY,0)
   MouseClick("left")
   Sleep(1000)
   $starterTimer = _Timer_SetTimer($hGUI,3000,"SelectWorker",-1)
EndFunc

Func test()
   MouseMove($openShopX,$openShopY,0)
   MouseClick("left")
EndFunc

Func EndDay($hWnd, $Msg, $iIDTimer, $dwTime)
   #Forceref $hWnd   , $Msg   , $iIDTimer   , $dwTime
   ConsoleWrite("Killed All Timers? " & _Timer_KillAllTimers($hGUI) & @CRLF)
   MouseMove($openShopX,$openShopY,0)
   MouseClick("left")
   
EndFunc

Func SelectWorker($hWnd, $Msg, $iIDTimer, $dwTime)
   #Forceref $hWnd   , $Msg   , $iIDTimer   , $dwTime
   _Timer_KillTimer($hGUI, $worker1)
   _Timer_KillTimer($hGUI, $starterTimer)
   MouseMove($selectWorkerX, $selectWorkerY - 0 * $spaceBetweenWorkerY,0)
   MouseClick("left")
   Sleep(500)
   SelectItem()
   
   $worker1 = _Timer_SetTimer($hGUI,$fastTimer,"SelectWorker")
EndFunc

Func SelectItem()
   Local $try = 0
   ;MouseMove($newItemX + $xGamePos + $try * $selectItemSpaceX, $newItemY + $yGamePos, 0)
   While 1
	  Sleep(1000)
	  Local $coord = PixelSearch($newItemX + $xGamePos + $try * $selectItemSpaceX, $newItemY + $yGamePos, $newItemWidth, $newItemHeight, $newItemColor1, 0)
	  If Not @error Then
		 $try = $try + 1
		 ConsoleWrite($newItemX + $xGamePos + $try * $selectItemSpaceX)
	  Else
		 ExitLoop
	  EndIf
	  
	  If $try > 5 Then
		 ExitLoop
	  EndIf
   WEnd
   
   MouseMove($selectItemX + $xGamePos + $selectItemSpaceX * $try, $selectItemY + $yGamePos, 0)
   ;MouseClick("left")
EndFunc

Func antiPopup()
   Local $errorFound = True
   While $errorFound
	  $errorFound = False
	  Sleep(1000)
	  Local $coord1 = PixelSearch($endBuildingX + $xGamePos, $endBuildingY + $yGamePos, $endBuildingWidth, $endBuildingHeight, $endBuildingColor, 0)
	  If Not @error Then
		 ;MouseMove($endBuildingX + $xGamePos, $endBuildingY + $yGamePos, 0)
		 ;MouseClick("left")
		 $errorFound = True
		 ConsoleWrite("1")
	  EndIf
	  Local $coord2 = PixelSearch($endDaySuccesX + $xGamePos, $endDaySuccesY + $yGamePos, $endDaySuccesWidth, $endDaySuccesHeight, $endDaySuccesColor, 0)
	  If Not @error Then
		 ;MouseMove($endBuildingX + $xGamePos, $endBuildingY + $yGamePos, 0)
		 ;MouseClick("left")
		 $errorFound = True
		 ConsoleWrite("2")
	  EndIf
   WEnd
EndFunc
12/19/2013 21:20 alpines#4
Code:
Func bot()
   SelectItem()
EndFunc
Wtf?

Does it crash in reason of recursion level reached?
12/19/2013 21:26 lolkop#5
Quote:
Originally Posted by alpines View Post
Code:
Func bot()
   SelectItem()
EndFunc
Wtf?

Does it crash in reason of recursion level reached?
where's the recursion in that example? o0
12/19/2013 21:47 coolraiman#6
no, most of the function are not completed, and some are in test state.
the bot func is simply the start point of the bot when you press start
12/19/2013 21:55 lolkop#7
Quote:
Originally Posted by coolraiman View Post
no, most of the function are not completed, and some are in test state.
the bot func is simply the start point of the bot when you press start
the bot function should not be placed in any control check but in the main function...

beside that i still don't get your problem... the problem you're tryin to explain doesn't make no sense...

try to do your actions in a small example script first
Code:
While Sleep(10)
	PixelSearch(250+$xGamePos, 280+$yGamePos, 100, 25, 0x085b91, 0)
	If Not @error Then ConsoleWrite('Found!'&@CRLF)
WEnd
replace the variables with your values...

the script should work with various pixel variations... if it doesn't it get's blocked by another application.
12/19/2013 22:03 coolraiman#8
can flash block the pixelSearch.
my problem is that it always detect even if the color is not in the area or it detect nothing
12/19/2013 22:16 lolkop#9
Quote:
Originally Posted by coolraiman View Post
can flash block the pixelSearch.
my problem is that it always detect even if the color is not in the area or it detect nothing
flash can't block anything...

try this, to check if pixelsearch works for you @ all

Code:
$gui = GUICreate('', 20, 20, 0, 0, 0x90000000)
GUISetBkColor(0) ;black
GetColor()
GUISetBkColor(0xFFFFFF) ;white
GetColor()
GUISetBkColor(0xFF0000) ;red
GetColor()
GUISetBkColor(0xFF00) ;green
GetColor()
GUISetBkColor(0xFF) ;blue
GetColor()
GUISetBkColor(0) ;black
GetColor()

Func GetColor()
	; White
	PixelSearch(1,1,19,19,0xFFFFFF)
	If Not @error Then ConsoleWrite('Guicolor: White'&@CRLF)
	; Red
	PixelSearch(1,1,19,19,0xFF0000)
	If Not @error Then ConsoleWrite('Guicolor: Red'&@CRLF)
	; Green
	PixelSearch(1,1,19,19,0xFF00)
	If Not @error Then ConsoleWrite('Guicolor: Green'&@CRLF)
	; Blue
	PixelSearch(1,1,19,19,0xFF)
	If Not @error Then ConsoleWrite('Guicolor: Blue'&@CRLF)
	; Black
	PixelSearch(1,1,19,19,0)
	If Not @error Then ConsoleWrite('Guicolor: Black'&@CRLF)
EndFunc
12/20/2013 14:34 coolraiman#10
your exemple worked.
but how cant this wont work?
im about to blow my head off.
he get the color in a position, then he scan the same zone and he cant find it.
i am also aiming to a white background with a basic FEFEFE color... i have to put the search sensibility over 9000 because he cant find it.

is it because the color i am searching is not on my gui but on my browser so i need something for him to detect his color?
i really dont know what to do now
Code:
Global $color

getColor()
ColorTest()

Func getColor()
   $color = Hex(PixelGetColor(50,100),6)
   ConsoleWrite($color)
EndFunc

Func ColorTest()
   Local $coord = PixelSearch(40,90,20,20, $color,50);wtf even at 50 it say NOPE
   If Not @error Then
	  ConsoleWrite("yup")
   Else
	  ConsoleWrite("nope")
   EndIf
   sleep(500)
   MouseMove(40,90)
EndFunc
btw, i also have a small question. do sleep also pause _TIMER ?
12/20/2013 17:47 KDeluxe#11
Sleep() will pause your entire Script. Use a lower "shade-variation" value to solve your problem. The value of the "shade-variation" parameter should be in range from 0 to 255. If you want an exact match, you have to use 0 (see lolkops script). If you're using a value above 254, PixelSearch() will always succeed.
12/21/2013 01:18 lolkop#12
Quote:
Originally Posted by coolraiman View Post
your exemple worked.
but how cant this wont work?
im about to blow my head off.
he get the color in a position, then he scan the same zone and he cant find it.
i am also aiming to a white background with a basic FEFEFE color... i have to put the search sensibility over 9000 because he cant find it.

is it because the color i am searching is not on my gui but on my browser so i need something for him to detect his color?
i really dont know what to do now
Code:
Global $color

getColor()
ColorTest()

Func getColor()
   $color = Hex(PixelGetColor(50,100),6)
   ConsoleWrite($color)
EndFunc

Func ColorTest()
   Local $coord = PixelSearch(40,90,20,20, $color,50);wtf even at 50 it say NOPE
   If Not @error Then
	  ConsoleWrite("yup")
   Else
	  ConsoleWrite("nope")
   EndIf
   sleep(500)
   MouseMove(40,90)
EndFunc
btw, i also have a small question. do sleep also pause _TIMER ?
first of all, sleep pauses your whole script... i don't know exactly what the _TIMER function does, but i would allways prefer native autoit functions (timerinit, timerdiff)...

pixelsearch doesn't care for the target, since it scans your actual displaycontent for the color.... if you fail @ finding the color, your color (or position) seems to be wrong...