PixelGetColor Or PixelSearch for a game Topic is solved

Ask gaming related questions
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

PixelGetColor Or PixelSearch for a game

03 Jan 2021, 15:27

Hello guys, i tried to do a simple script for this minigame.

Image

When the blue line will cover the grey "E" just to simple execute E. The problem is it doesn't work and i don't understand if it's about the area range or ... ?

Code: Select all

PixelGetColor, Color1, 807, 1108
		if Color1 = 0X3B3C3B
	{
		Send E
	}
return
Thanks !
Last edited by gregster on 03 Jan 2021, 15:32, edited 2 times in total.
Reason: Picture fixed again. Editing will break it again...
User avatar
Epialis
Posts: 722
Joined: 02 Aug 2020, 22:44

Re: PixelGetColor Or PixelSearch for a game

03 Jan 2021, 15:45

Hi

I don't know much yet on pixel colors or the syntax, but shouldn't the

Code: Select all

if Color1 = 0X3B3C3B
Have () around them?

Code: Select all

if (Color1 = 0X3B3C3B)
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

03 Jan 2021, 16:00

Still don't work
User avatar
Xtra
Posts: 2060
Joined: 02 Oct 2015, 12:15

Re: PixelGetColor Or PixelSearch for a game

03 Jan 2021, 17:15

Set CoordMode for how you intend to use it by default its window and not screen.

If the E changes color then check when its not equal ( != ) to gray and send E etc.
(this may help when the color covering the E are not a consistent color of blue)
User avatar
mikeyww
Posts: 5358
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

03 Jan 2021, 17:29

You are searching for gray or blue?
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

03 Jan 2021, 18:09

mikeyww wrote:You are searching for gray or blue?
I'm searching for gray, blue it's the moving line.
Xtra wrote:
03 Jan 2021, 17:15
Set CoordMode for how you intend to use it by default its window and not screen.

If the E changes color then check when its not equal ( != ) to gray and send E etc.
(this may help when the color covering the E are not a consistent color of blue)
It's not changing color when it's overlay. I will stay in a position with a black background to see the perfect gray.
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

03 Jan 2021, 18:12

@Xtra Also, you want to say to use CoordMode, Pixel, Screen to work on full screen ? Btw the game it's GTA 5
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

03 Jan 2021, 18:13

@mikeyww i'm searching for grey, because the blue bar it's a moving line. And I will position the camera, to have a black background to see the perfect gray.
User avatar
mikeyww
Posts: 5358
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

03 Jan 2021, 18:23

Here is an easy way to debug.

Code: Select all

x := 807, y := 1108
MouseMove, x, y
PixelGetColor, color, x, y
MsgBox, 64, Color, Color at (%x%,%y%) is %color%
If (color = 0x3B3C3B)
 Send E
And yes: how did you determine the coordinates?
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

03 Jan 2021, 20:10

@mikeyww Yeah, i had some problem with coordinates but with this script i could get what i needed.
Spoiler
Now with your script, I was able to get the color that interested me and it stabilized the best (3B3B3B when it's in a black background).



At 0:03, after i activated your script, the "mouse"(screen) went down aggressively (anyway that's not a problem). Now i need just to press pe E key when the blue line it's in the grey area cuz, the gray space it's not a stable location. Thanks !
Last edited by Giani123 on 04 Jan 2021, 17:06, edited 1 time in total.
User avatar
mikeyww
Posts: 5358
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

03 Jan 2021, 20:31

You can test with the following.

Code: Select all

x := 807, y := 1108, targetColor := 0x3B3B3B
CoordMode, Mouse
MouseMove, x, y
SetTimer, Check, 200
Check:
PixelGetColor, thisColor, x, y
SoundBeep, 1500, 30
If (thisColor != targetColor)
 Return
SetTimer, Check, Off
Send E
Return

Esc::
SoundBeep, 1000, 30
ExitApp
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 08:14

I also tried this script but without success. The coordinates look for my gray box only in a certain position, even if it does not always appear in the same place. Even if we say that it happens to fall in the fixed coordinates, it still doesn't do anything. (Press E)
User avatar
mikeyww
Posts: 5358
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 08:17

Question #1: Is the mouse moving to the correct location?

Question #2: What is the actual color at that location?

If you are not using a certain position, then you will want a PixelSearch.
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 08:25

Thanks for the reply.
1. The mouse it's moving to correct location.
2. Color is the same, i already tested again and it's still. 3B3B3B
Hmm with PixelSearch can i get an example for the above question? Thanks
User avatar
mikeyww
Posts: 5358
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 08:49

So: it sounds like your PixelGetColor succeeds, right? Change the Send to a MsgBox so that you can confirm that.

If you need the broader search, the link provided has an example at the bottom of the page.
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 10:54

Yeah, i tried with PixelSearch, i already found the color when the blue will cover the grey area. I used that example to debug and see if it's okay and when the colors will overlay, and i got succed.
Now I need to execute my E key when it first finds the color. Need some help there :) Thanks

Code: Select all

#NoEnv  			; Recommended for performance and compatibility with future AutoHotkey releases.
SetWorkingDir %A_ScriptDir%  	; Ensures a consistent starting directory.
#SingleInstance, Force

SetKeyDelay, 50,50

#IfWinActive ahk_class grcWindow  ; Disables hotkeys when alt-tabbed or GTA is closed.


g::
PixelSearch, Px, Py, 790, 885, 1080, 920, 0x49423A, 3, Fast
if (ErrorLevel=0)
{
Send E
}
User avatar
mikeyww
Posts: 5358
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 11:32

Strategies for debugging your script:

1. While you are testing, you can use MsgBox instead of Send. Add one to see if the "g" triggers, and a second one to see if your color is found. If not found when expected, then you can see what the actual pixel value is.

2. How did you determine the coordinates? Issue a MouseMove to the same coordinates (e.g., top left), to double-check.

3. How did you determine the new color?

Multi-line hotkey routines should end in Return.
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 12:11

2,3 I determine the coordinates with CoordMode and your script
Spoiler
I tried multiple times changing x and y until I finally saw that they were ok. I checked with MouseMove and it's okay (also Top Left and Bot.Right)
I also set the color with the script above, changing x and y until I realized that when I catch the color it is always the same.

1. This is a problem, i don't understand how to do a msgbox to see if "g" triggers?!
And the second one i already did with the example where it's says :

Code: Select all

    
    g::
    Px, Py, 790, 885, 1080, 920, 0x49423A, 3, Fast
    if ErrorLevel
    MsgBox, That color was not found.
else
    MsgBox, Color was found at X%Px% Y%Py%.
When I pressed g normally, it told me that the color was not present (before overlap). And when the area was covered, it detects it. (overlap)
User avatar
mikeyww
Posts: 5358
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 12:25

So it's working, right?

Send sends to the active window. If your target window is not activated, you can use WinActivate first.

Your last script is missing both a search command and a Return. Aren't you seeing an error at line 3?
Giani123
Posts: 21
Joined: 03 Jan 2021, 15:19

Re: PixelGetColor Or PixelSearch for a game

04 Jan 2021, 12:39

It's not working yet... I'm not into programming, i'm trying my best :)
I set the coordinates ok, the color it's okay, but the script itself it does not do what he should. I press G to start the script and he never press E when he detect the color

Code: Select all

#NoEnv  			; Recommended for performance and compatibility with future AutoHotkey releases.
SetWorkingDir %A_ScriptDir%  	; Ensures a consistent starting directory.
#SingleInstance, Force
SetKeyDelay, 50,50
#IfWinActive ahk_class grcWindow  ; Disables hotkeys when alt-tabbed or GTA is closed.

g::
PixelSearch, Px, Py, 790, 885, 1080, 920, 0x49423A, 3, Fast
if ErrorLevel
Send E

Return

Return to “Gaming”

Who is online

Users browsing this forum: Bing [Bot], mikeyww and 9 guests