Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > AutoIt
You last visited: Today at 00:56

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



small trouble with pixel search

Discussion on small trouble with pixel search within the AutoIt forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2013
Posts: 9
Received Thanks: 0
small trouble with pixel search

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
coolraiman is offline  
Old 12/19/2013, 21:02   #2
 
alpines's Avatar
 
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
This is definitely not the whole script. Post your whole script maybe there's the error.
alpines is offline  
Old 12/19/2013, 21:05   #3
 
elite*gold: 0
Join Date: Dec 2013
Posts: 9
Received Thanks: 0
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
coolraiman is offline  
Old 12/19/2013, 21:20   #4
 
alpines's Avatar
 
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
Code:
Func bot()
   SelectItem()
EndFunc
Wtf?

Does it crash in reason of recursion level reached?
alpines is offline  
Old 12/19/2013, 21:26   #5
 
lolkop's Avatar
 
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
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
lolkop is offline  
Old 12/19/2013, 21:47   #6
 
elite*gold: 0
Join Date: Dec 2013
Posts: 9
Received Thanks: 0
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
coolraiman is offline  
Old 12/19/2013, 21:55   #7
 
lolkop's Avatar
 
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
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.
lolkop is offline  
Old 12/19/2013, 22:03   #8
 
elite*gold: 0
Join Date: Dec 2013
Posts: 9
Received Thanks: 0
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
coolraiman is offline  
Old 12/19/2013, 22:16   #9
 
lolkop's Avatar
 
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
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
lolkop is offline  
Old 12/20/2013, 14:34   #10
 
elite*gold: 0
Join Date: Dec 2013
Posts: 9
Received Thanks: 0
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 ?
coolraiman is offline  
Old 12/20/2013, 17:47   #11
 
elite*gold: 0
Join Date: Mar 2009
Posts: 7,260
Received Thanks: 33,149
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.
KDeluxe is offline  
Old 12/21/2013, 01:18   #12
 
lolkop's Avatar
 
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
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...
lolkop is offline  
Reply


Similar Threads Similar Threads
Pixel Search
05/07/2012 - AutoIt - 1 Replies
Hey, mit welchen Programm bekomme ich nochmal diese Werte her? PixelSearch(12, 174, 1028, 700, 0x59571A, 10) Danke
[Release]Small Weapon Pixel-Bot
03/05/2012 - S4 League Hacks, Bots, Cheats & Exploits - 142 Replies
Update: Works only on 64-Bit at the moment, am working on a 32 bit version (there seems to be a problem with the dc) Ok Guyes, here is my new Bot :awesome: http://img9.abload.de/img/blahsrwf.png Features: - Clicks with the mousebutton if you hover a enemy mit a normal gun - Let the mousebutton off if you hover a enemy with a sniper gun - Works in Fullscreen and Windows Mode
Pixel search
02/23/2008 - Guild Wars - 18 Replies
hallihallo bin immoment dabei einen meiner eigenen bots zu optimieren und wollte ne Pixelsearchfunktion einbauen. Leider weiß ich nicht genau wie man das macht vorallem mit den farben. mein ziel: 3 verschiedene punkte im gw fenster(mit: x1;y1;;x2;y2;;x3;y3) sollen geprüft werden ob sie in GRÜN sind. falls x1;y1 grün ist -> (dollerzeichen)folge = 1 falls x2;y2 grün ist -> (dollerzeichen)folge = 2 falls x3;y3 grün ist -> (dollerzeichen)folge = 3



All times are GMT +1. The time now is 00:58.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.