Help With ImageSearch/PixelSearch PLEASE!

Ask gaming related questions (AHK v1.1 and older)
Jakk_Uber_Noob
Posts: 18
Joined: 19 Sep 2017, 04:14

Help With ImageSearch/PixelSearch PLEASE!

19 Sep 2017, 04:47

Hi guys i am relatively new to this all so sorry if this seems very nooby,
Here is my test scripts for checking to see if the ImageSearch/PixelSearch is actually on screen and then clicking it if found.

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
F1::

ImageSearch, foundX, foundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, C:\Users\ME\Desktop\AHK\example.bmp
If ErrorLevel = 0
{
MouseMove, %foundX%, %foundY% 
Sleep, 66, 666
Click
}

If ErrorLevel = 1
{
MsgBox, O Damn - Cant find Image/Pixel
}
Return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;; OR ;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
F2::


PixelSearch, tX, tY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x111828, 3, Fast 
If ErrorLevel = 0
{
MouseMove, %tX%, %tY%
Sleep, 66, 666
Click
}

If ErrorLevel = 1
{
MsgBox, O Damn - Cant find Image/Pixel
}
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Question 1:
My problem is the fact that each and every time it find the image and clicks on it, it is clicking the EXACT SAME PIXEL every time, and as this is being used for an online game this is very much not ideal. Is there any way to click a Random spot WITHIN the image defined OR Click a random color defined pixel, instead of just finding image/color and clicking same pixel everytime? The idea would be that on the MouseMove to the location (whether it be PixelSearch or ImageSearch) it will then click at a random slightly off center position each time.

Now assuming that Question 1 has been solved, my next problem is as follows :-

Question 2:
Lets say on my screen i have 3 "rocks/images/pixelcolor" on screen, and when pressing F1:: due to the way it searches from top left to right then down it Is ALWAYS clicking the top left "rock/Image". How can i make it select from any one of the 3 found "rock/Images/pixelcolor" randomly?

Any help and ideas are welcome! Please let me know if my intentions are not clear and i will try to explain further,
Last edited by Jakk_Uber_Noob on 19 Sep 2017, 06:57, edited 5 times in total.
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: Help With ImageSearch/PixelSearch PLEASE!

19 Sep 2017, 05:26

Answer 1:

Code: Select all

RngClick(100, 200, 100, 200)

RngClick(xmin, xmax, ymin, ymax) {
	Random, x, % xmin, xmax
	Random, y, % ymin, ymax
	Click, % x " " y
}
Answer 2:
I am sorry but I don't have time right now, but I guess that you could split the screen into segments and search each one.
Please excuse my spelling I am dyslexic.
Jakk_Uber_Noob
Posts: 18
Joined: 19 Sep 2017, 04:14

Re: Help With ImageSearch/PixelSearch PLEASE!

19 Sep 2017, 05:43

Capn Odin wrote:Answer 1:

Code: Select all

RngClick(100, 200, 100, 200)

RngClick(xmin, xmax, ymin, ymax) {
	Random, x, % xmin, xmax
	Random, y, % ymin, ymax
	Click, % x " " y
}
Ooh interesting, I am completely unfamiliar with this command and cant find it on google :/? How would i go about implementing this in this code here

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;; OR ;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
F2::


PixelSearch, tX, tY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x111828, 3, Fast 
If ErrorLevel = 0
{
MouseMove, %tX%, %tY%
Sleep, 66, 666
Click
}

If ErrorLevel = 1
{
MsgBox, O Damn - Cant find Image/Pixel
}
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Heres a visual on my situation and what i mean if it helps, (Should help for both questions) https://imgur.com/nn0ut3n & https://imgur.com/c14Ey8O ... You see how when the camera angle changes the 'Rocks' (the 3 rocks around my character) also change their positions on the screen. I have managed to confine the search to just the middle of the screen so that it doesn't click rocks too far away from me but the problem still lies in the fact its always choosing the top rock in view AND Clicking the exact same pixel.
Jakk_Uber_Noob
Posts: 18
Joined: 19 Sep 2017, 04:14

Re: Help With ImageSearch/PixelSearch PLEASE!

19 Sep 2017, 06:49

[quote="Capn Odin"]Answer 1:

Code: Select all

RngClick(100, 200, 100, 200)

RngClick(xmin, xmax, ymin, ymax) {
	Random, x, % xmin, xmax
	Random, y, % ymin, ymax
	Click, % x " " y
}
Ok so i have looked into this and i am pretty sure this is the same as this right?

MouseMove, % Random(998,1019), % Random(465,486)
Random(min,max)
{
Random, out, %min%, %max%
return out
}
Jakk_Uber_Noob
Posts: 18
Joined: 19 Sep 2017, 04:14

Re: Help With ImageSearch/PixelSearch PLEASE!

19 Sep 2017, 06:52

Hey everyone i have an idea, is there anyway that after the MouseMove i can get the current mouse position and then make it move randomly but slightly from its mousegetpos position? Something like :
; Move the mouse slowly (speed 50 vs. 2) by 20 pixels to the right and 30 pixels down
; from its current location:
MouseMove, 20, 30, 50, R

But instead moving it randomly? so it chooses the 20,30 at random between a predefined set of values.?
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: Help With ImageSearch/PixelSearch PLEASE!

19 Sep 2017, 07:02

To use relative mouse movements use the option R.

Code: Select all

MouseMove, -10, -10, , R
Please excuse my spelling I am dyslexic.
Jakk_Uber_Noob
Posts: 18
Joined: 19 Sep 2017, 04:14

Re: Help With ImageSearch/PixelSearch PLEASE!

20 Sep 2017, 07:08

Capn Odin wrote:To use relative mouse movements use the option R.

Code: Select all

MouseMove, -10, -10, , R
:D :D I think we're on track here! How do i give the two values show above (-10, -10) a random value say Value1= a range of -100,100 and Value2= a range of -100,100? so some sort of code like

Code: Select all

MouseMove, %Value1%, %Value2%, , R
So that each time it executes it chooses to move the mouse randomly within the defined range instead of exactly -10, -10 , , R (10 pixels to the left && 10 pixels up)

Thank you for your time in trying to help me here! I REALLY APPRECIATE IT :D!!!! THANK YOU!!!! The kindness of strangers is a beautiful thing, honest kindness/help without strings attached is becoming a rarity these days unfortunately :/

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: BernardDwess and 82 guests