ImageProcessing on a random place qte

Ask gaming related questions
vanker
Posts: 9
Joined: 12 Oct 2017, 17:01

ImageProcessing on a random place qte

12 Oct 2017, 17:24

So, 1st time poster been a lurker for the most part, but now I'm stuck in this particular issue, let me explain for you guys.

So in the game dead by daylight you have Image those, those are called "Skill Checks" where if you press space bar inside the white block you get a great skill check(rewarding you with more points).

So with all my reading from the forums and the docs I found ImageProcessing to be the function that I need and this is what I came up so far:

Code: Select all

Loop 
{
CoordMode Pixel 
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight,*110, C:\Users\AHKFORUM\Pictures\tiny6.png

if ErrorLevel = 2
{
    MsgBox Could not conduct the search.
break 

}
else if ErrorLevel = 1
{
 

}
else {
    MsgBox The icon was found at %FoundX%x%FoundY%. ; Here I'll swap with send space hotkey, for now it's just for testing purposes
	break
}

}

My logic here was pretty primitive, I took the tiny white part along with the red line (where indicates where is your cursor) and made the script look for that, but 9/10 fails to find a match and maybe it's because this skill check can occur at any time in any direction (Image) and my "Image" it's not a good representative of a constant in skill check.


Now, I don't know how to proceed, do you guys have any ideas, insights on what to do next?

Thanks in Advance, also sorry for any mistakes this may have I'm not a native speaker.

Keep on scriptin'
TygerByte
Posts: 96
Joined: 12 Aug 2016, 05:22

Re: ImageProcessing on a random place qte

13 Oct 2017, 09:06

A good read for you https://autohotkey.com/boards/viewtopic.php?t=4544 and in that read it mentions reducing the size/area of where you search.. You have it searching the whole screen which is a waste. My suggestion is to search the area around the circle only, but look for a solid white square big enough to not be mistaken for anything else except the skill check spot. Once you find the skill check spot, as in have the X and Y coords, check for the color red with a pixelgetcolor.
vanker
Posts: 9
Joined: 12 Oct 2017, 17:01

Re: ImageProcessing on a random place qte

13 Oct 2017, 17:48

TygerByte wrote:A good read for you https://autohotkey.com/boards/viewtopic.php?t=4544 and in that read it mentions reducing the size/area of where you search.. You have it searching the whole screen which is a waste. My suggestion is to search the area around the circle only, but look for a solid white square big enough to not be mistaken for anything else except the skill check spot. Once you find the skill check spot, as in have the X and Y coords, check for the color red with a pixelgetcolor.

Code: Select all

plot(x1, y1, a, r, byref x2, byref y2) {    
rad := (a * 0.01745329252)
x2 := (x1 - sin(rad) * r)
y2 := (y1 + cos(rad) * r)
}

loop {
;MouseMove, 810,440
plot(808, 452, a_index * 8, 50, x2, y2)
pixelgetcolor c, x2, y2, rgb
MouseMove, x2, y2
} until (c = 0xFFFFFF) || (c = 0xFBFDFF) || (c = 0xFCFCFF) || (c = 0xFAFFFF) || (c = 0xFEFFFC) || (c = 0xFBFCFF) || (c = 0xFEFFF)


loop {
pixelgetcolor c, x2, y2, rgb
MouseMove, x2, y2   
sleep 100
} until (c = 0xC00004)

I managed to do this with the help of some guys, but the problem I'm having is that I can make it work while looking at a printscreen or a video, cause I can set the X and Y coordinates accordingly AND check with mouse move if it's following the expected path. However when it comes to the actual game I can't see mouse movement (game disables mouse cursor) so I don't know if it's searching the wrong pos or I have to add more colors to the search.


Edit :

Got it working using PixelSearch, but still needed to be a little faster..

Code: Select all

plot(x1, y1, a, r, byref x2, byref y2) {    
rad := (a * 0.01745329252)
x2 := (x1 - sin(rad) * r)
y2 := (y1 + cos(rad) * r)
}


xMid :=  A_ScreenWidth //2
yMid :=  A_ScreenHeight //2

f1::
    coordmode mouse
    coordmode pixel
    setformat floatfast, 0
    mousegetpos x, y
    arc := 5, radius := 53, time := a_tickcount
    loop {
            plot(xMid, yMid, a_index * arc, radius, x2, y2)
          
			PixelSearch, oX, oY, x2, y2, x2, y2, 0xFFFFFF , 100 ,FAST
			
			if !ErrorLevel
				Break

	mousemove Ox, Oy
	

loop{
PixelSearch, oX1, oY1, Ox, Oy, Ox, Oy, 0xCD0009 , 150 ,FAST
 if !ErrorLevel
	Break

}
mousemove oX1, oY1
msgbox red found at %oX1% and %oY1%
return
TygerByte
Posts: 96
Joined: 12 Aug 2016, 05:22

Re: ImageProcessing on a random place qte

13 Oct 2017, 21:06

Wow. The next improvement you can read about on https://autohotkey.com/boards/viewtopic.php?t=6413 but I think you only need to add the following.

Code: Select all

#NoEnv
ListLines Off
Process, Priority, , A
SetBatchLines, -1
Also take notice of his note #10 about pixelsearch. Try reducing the shade variation too.

The last think I can think of is for you to pick up GDIP because pixelsearch takes a picture everytime you are looking for a picture. So it would help in finding the white spot faster, but I'm not sure about the red spot bud. What part needs to be faster though? Have you tried having it hit spacebar on the red detection?

Maybe the math you used to narrow down the search area is even slowing it down. Try my original idea of imagesearching a white square picture to locate the white area. Just set the area to be the middle of the screen in a small square enough to cover the QTE. If you can get away with it pixelsearch is ok too, but I'm worried you may get too many hits with it since you are no longer searching only in a circle.
vanker
Posts: 9
Joined: 12 Oct 2017, 17:01

Re: ImageProcessing on a random place qte

13 Oct 2017, 21:25

My final code looks something like this :

Code: Select all

#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input

plot(x1, y1, a, r, byref x2, byref y2) {    
rad := (a * 0.01745329252)
x2 := (x1 - sin(rad) * r)
y2 := (y1 + cos(rad) * r)
}


xMidScrn :=  A_ScreenWidth //2
yMidScrn :=  A_ScreenHeight //2

f1::
loop{
    coordmode mouse
    coordmode pixel
    setformat floatfast, 0
    mousegetpos x, y
    arc := 15, radius := 53, time := a_tickcount
    loop {
            plot(xMidScrn, yMidScrn, a_index * arc, radius, x2, y2)
			PixelSearch, oX, oY, x2, y2, x2, y2, 0xFFFFFF , 100, Fast
			;mousemove x2,y2 ;this is just here to check if the radius being searched is the correct one.
			if !ErrorLevel
				Break
	}
    
	
	
loop{
PixelSearch, oX1, oY1, Ox, Oy, Ox, Oy, 0xCD0009 , 145, Fast
 if !ErrorLevel
	Break

}
Send {Space down}
sleep 10
Send {Space up}

}
return
Thing is, it's too much color variation that I've to use as the background is the game so if I'm up against a white wall or something like that It will trigger at random or sometimes do not trigger at all.


And another problem is, sometimes it finds the white, and it doesn't find the red (should put a timeout if it doesn't find the red in X seconds try to find white again).

PixelSearch is more of a workaround than a actual fix, sometimes the QTE happens to fast and too close so the pixelsearch cannot follow it.
TygerByte
Posts: 96
Joined: 12 Aug 2016, 05:22

Re: ImageProcessing on a random place qte

13 Oct 2017, 22:23

Yea I'm outta ideas bud. Might be at the limits of what we can do, but need someone who knows the finer things to chime in. As far as a function with timeout and pixelgetcolor you can try the following function https://github.com/MasterFocus/AutoHotk ... PixelColor
vanker
Posts: 9
Joined: 12 Oct 2017, 17:01

Re: ImageProcessing on a random place qte

14 Oct 2017, 09:58

Using this :

Code: Select all

f1::
loop{
    coordmode mouse
    coordmode pixel
    setformat floatfast, 0
    mousegetpos x, y
    arc := 3, radius := 53, time := a_tickcount
    loop {
            plot(xMidScrn, yMidScrn, a_index * arc, radius, x2, y2)
			PixelSearch, oX, oY, x2, y2, x2, y2, 0xFFFFFF , 100, Fast RGB
			;mousemove x2,y2 ;this is just here to check if the radius being searched is the correct one.
	if !ErrorLevel{
			mousemove oX, oY
			pixelgetcolor white, oX, oY, rgb
				Break
	}
	
	}
	
	loop
	{
		pixelgetcolor c, oX, oY, rgb
		
		if c <> white 
		{
			MsgBox first loop block was %white% - Second was %c%
				;Send {Space down}
				;Sleep 10
				;Send {Space up}
				break
		}
			
	}
	

}
return
However, there must be a flaw in

Code: Select all

if c <> white
Cause even if it's the same, it triggers the IF statement.
I tried something with image search again just finding a small white block but I had little no none success with that as well.
ac1234
Posts: 5
Joined: 21 Oct 2019, 04:32

Re: ImageProcessing on a random place qte

21 Oct 2019, 20:26

did anyone manage to get this script working for the skill checks?

Return to “Gaming”

Who is online

Users browsing this forum: NewbCoder and 44 guests