search for a pixel inside a spesific rectangle
search for a pixel inside a spesific rectangle
Hello guys, I'm pretty new and I just wanted some help to figure out how I would go about searching for a color in specific rectangle inside my game, instead of searching in just 1 single spot or the whole game window I wanted it to just search for the color red in this part see picture below
https://imgur.com/mSAC830
https://imgur.com/mSAC830
Re: search for a pixel inside a spesific rectangle
See PixelSearch. There is an example on that page.
Re: search for a pixel inside a spesific rectangle
This is my script so far, everything works fine except pressing the E key when it finds the red color in that rectangle
Code: Select all
F3::
CoordMode, pixel,screen
Loop
{
PixelSearch,,, 809, 799, 809, 799, 0xE6E6E5,, Fast RGB
AisWhite := !ErrorLevel
PixelSearch,,, 816, 793, 816, 793, 0x2F6F32,, Fast RGB
BisGreen := !ErrorLevel
PixelSearch,,, 809, 759, 1111, 800, 0x653130,, Fast RGB
CisRed := !ErrorLevel
Switch AisWhite BisGreen CisRed
{
Case True True False:
sleep 25
Case False False False:
Send, {e down}
sleep 25
Send, {e up}
Case True True True:
Send, {e down}
sleep 25
Send, {e up}
}
}
return
~F4::ExitApp
Re: search for a pixel inside a spesific rectangle
The only thing that I think that I'm doing wrong is capturing that rectangle because I tried to edit it to msgbox, do 1 if it finds the color red in that rectangle and it's not capturing it.
I put the x1 and y1 top left corner of the rectangle and then x2 and y2 as bottom right of the rectangle and then choose the hex of the color.
I beg anyone to help me fix this, been trying to learn how to do it from scratch for a while now without any success
I put the x1 and y1 top left corner of the rectangle and then x2 and y2 as bottom right of the rectangle and then choose the hex of the color.
I beg anyone to help me fix this, been trying to learn how to do it from scratch for a while now without any success
Re: search for a pixel inside a spesific rectangle
Display the ErrorLevel in your script. If pixel is not found, use PixelGetColor to see what is really there. You will then know. MouseMove to that pixel.
Code: Select all
x = 809
y = 759
CoordMode, Pixel
CoordMode, Mouse
MouseMove, x, y
PixelSearch,,, x, y, x, y, 0x653130,, Fast RGB
If ErrorLevel {
WinGetActiveTitle, title
PixelGetColor, rgb, x, y, RGB
MsgBox, 64, Nope, Found %rgb%`n`nwhen active window is`n`n%title%
} Else MsgBox, 64, Yep, Found!
Return
Re: search for a pixel inside a spesific rectangle
Thank you for your reply, that isn't much help because there's a short time like 2 seconds, while the color is visible in that rectangle and it doesn't always appear exactly in the same place, it appears anywhere in between the rectangle.mikeyww wrote: ↑30 Sep 2022, 08:55Display the ErrorLevel in your script. If pixel is not found, use PixelGetColor to see what is really there. You will then know. MouseMove to that pixel.
Code: Select all
x = 809 y = 759 CoordMode, Pixel CoordMode, Mouse MouseMove, x, y PixelSearch,,, x, y, x, y, 0x653130,, Fast RGB If ErrorLevel { WinGetActiveTitle, title PixelGetColor, rgb, x, y, RGB MsgBox, 64, Nope, Found %rgb%`n`nwhen active window is`n`n%title% } Else MsgBox, 64, Yep, Found! Return
Re: search for a pixel inside a spesific rectangle
I think I might know why it's not working, the color I'm trying to detect (red) has different shading depending on the time of the day inside the game, if it's night or day, it changes.
Is there anyway that I can put a bunch of different hex shades of red, without doing PixelSearch for each shade? So let's say I did something like
And then in PixelSearch I would do
Would this work? Sorry for the noob questions
Is there anyway that I can put a bunch of different hex shades of red, without doing PixelSearch for each shade? So let's say I did something like
Code: Select all
Red := "0xED1B24|0x23B14D|0x3F47CC|0xFEF200|0x000000|0xFFFFFF"
Code: Select all
PixelSearch,,, x, y, x, y, Red,, Fast RGB
Re: search for a pixel inside a spesific rectangle
PixelSearch has a specific parameter to deal with color variation, so it would be better to try it:
where:
Code: Select all
PixelSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID , Variation, Mode
Variation
A number between 0 and 255 (inclusive) to indicate the allowed number of shades of variation in either direction for the intensity of the red, green, and blue components of the color (can be an expression). For example, if 2 is specified and ColorID is 0x444444, any color from 0x424242 to 0x464646 will be considered a match. This parameter is helpful if the color sought is not always exactly the same shade. If you specify 255 shades of variation, all colors will match. The default is 0 shades.
Re: search for a pixel inside a spesific rectangle
This was very helpful, thank you will try to edit this tonight might actually be exactly what I needed without having to try get every single shade one by one and writing a massive script.sofista wrote: ↑30 Sep 2022, 11:06PixelSearch has a specific parameter to deal with color variation, so it would be better to try it:
where:Code: Select all
PixelSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID , Variation, Mode
Variation
A number between 0 and 255 (inclusive) to indicate the allowed number of shades of variation in either direction for the intensity of the red, green, and blue components of the color (can be an expression). For example, if 2 is specified and ColorID is 0x444444, any color from 0x424242 to 0x464646 will be considered a match. This parameter is helpful if the color sought is not always exactly the same shade. If you specify 255 shades of variation, all colors will match. The default is 0 shades.
Will report back whenever I have tested.
With the script, there's no issues though right? The way it's written should be able to achieve what I need? Pretty new and I am also not sure if I'm going about this the right way.
Re: search for a pixel inside a spesific rectangle
I do not see a specific problem with the approach.