Tracking colours of two pixels out of six.

Ask gaming related questions (AHK v1.1 and older)
Sanbenito
Posts: 4
Joined: 16 Dec 2018, 10:50

Tracking colours of two pixels out of six.

16 Dec 2018, 11:27

I need to track colours of six different pixels, if at least two of them (or more) are white, then do what needs to be done.
I have zero experience in coding, so I read tutorials and made this script. I can't figure out how to do it properly, so did this in a stupid way, I just wrote all 15 possible combinations of two pixels out of six. This script works, but think there are way better ways to do this.
Thanks in advance.

Code: Select all

#NoEnv
#singleinstance, Force
#Persistent
#InstallKeybdHook
#InstallMouseHook
#UseHook, On
SetBatchLines, -1
DetectHiddenWindows, On
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
CoordMode, Tooltip, Screen
SetTitleMatchMode, 3
ListLines, Off
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
#KeyHistory 0
#MaxThreads 20
#IfWinActive, Game Title Here
sendmode input

$*~space::
While GetKeyState("space","p"){
   PixelGetColor,pixel1,92,1355 
   PixelGetColor,pixel2,104,1355
   PixelGetColor,pixel3,116,1355
   PixelGetColor,pixel4,128,1355
   PixelGetColor,pixel5,140,1355
   PixelGetColor,pixel6,152,1355
    if (pixel1 = "0xFFFFFF" and pixel2 = "0xFFFFFF") or (pixel1 = "0xFFFFFF" and pixel3 = "0xFFFFFF") or (pixel1 = "0xFFFFFF" and pixel4 = "0xFFFFFF") or (pixel1 = "0xFFFFFF" and pixel5 = "0xFFFFFF") or (pixel1 = "0xFFFFFF" and pixel6 = "0xFFFFFF") or (pixel2 = "0xFFFFFF" and pixel3 = "0xFFFFFF") or (pixel2 = "0xFFFFFF" and pixel4 = "0xFFFFFF") or (pixel2 = "0xFFFFFF" and pixel5 = "0xFFFFFF") or (pixel2 = "0xFFFFFF" and pixel6 = "0xFFFFFF") or (pixel3 = "0xFFFFFF" and pixel4 = "0xFFFFFF") or (pixel3 = "0xFFFFFF" and pixel5 = "0xFFFFFF") or (pixel3 = "0xFFFFFF" and pixel6 = "0xFFFFFF") or (pixel4 = "0xFFFFFF" and pixel5 = "0xFFFFFF") or (pixel4 = "0xFFFFFF" and pixel6 = "0xFFFFFF") or (pixel5 = "0xFFFFFF" and pixel6 = "0xFFFFFF")
  {
     send {f10}
     sleep 100
  }
   else
  {
    send {f11}
    sleep 100
  } 
}
return
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Tracking colours of two pixels out of six.

16 Dec 2018, 12:50

Code: Select all

#NoEnv
#singleinstance, Force
#Persistent
#InstallKeybdHook
#InstallMouseHook
#UseHook, On
SetBatchLines, -1
DetectHiddenWindows, On
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
CoordMode, Tooltip, Screen
SetTitleMatchMode, 3
ListLines, Off
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
#KeyHistory 0
#MaxThreads 20
sendmode input

#IfWinActive, Game Title Here
$*~space::
While GetKeyState("space","p"){
	if atLeastTwoAreWhite()
		send {f10}
	else
		send {f11}
}
return

atLeastTwoAreWhite() {
	static X_COORDINATES := [92, 104, 116, 128, 140, 152]
	
	numWhite := 0

	for each, x in X_COORDINATES
	{
		PixelGetColor color, x, 1355, RGB

		if (color == 0xFFFFFF)
			++numWhite

		if (numWhite >= 2)
			return true
	}

	return false
}
Sanbenito
Posts: 4
Joined: 16 Dec 2018, 10:50

Re: Tracking colours of two pixels out of six.

16 Dec 2018, 15:47

Thanks a lot, will try this later.
Sanbenito
Posts: 4
Joined: 16 Dec 2018, 10:50

Re: Tracking colours of two pixels out of six.

17 Dec 2018, 20:25

Your script works perfectly, thanks again, however I have more questions.

I have another primitive script for another button which I managed to make, it is similar to the first one. Again, it works, but more pixels I add, the slower it gets. As far as i know from tutorials and other information on this forum I need to use arrays to make it faster, but I can't comprehend it yet. I could add more conditions, but it makes script getting slower. Since I need to track every pixelcolor individually, I can't figure out how to use arrays with it. I found this thread https://autohotkey.com/boards/viewtopic.php?t=40801 where similar problem is discussed, but i need to check multiple colors with different statements for every keystroke, I don't understand it yet and can't copy the code from there.

Code: Select all

#NoEnv
#singleinstance, Force
#Persistent
#InstallKeybdHook
#InstallMouseHook
#UseHook, On
SetBatchLines, -1
DetectHiddenWindows, On
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
CoordMode, Tooltip, Screen
SetTitleMatchMode, 3
ListLines, Off
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
#KeyHistory 0
#MaxThreads 20
sendmode input

#IfWinActive, Game Title Here
$*~numpad1::
While GetKeyState("numpad1","p"){
   PixelGetColor,spell1,8,1403
   PixelGetColor,spell2,20,1427
   PixelGetColor,spell3,8,1415
   PixelGetColor,spell4,144,1363
   PixelGetColor,spell5,20,1403
   PixelGetColor,spell6,32, 1415
  if (spell1 = "0xFFFFFF") and (spell3 != "0xE7C36B") and (spell4 != "0xFFFFFF")
 {
  send {f6} 
  sleep 100
 }
  else if ((spell5 = "0xFFFFFF") or (spell6 = "0xFFFFFF")) and (spell2 != "0x9FA589") and (spell4l != "0xFFFFFF")
 {
  send {f7} 
  sleep 100
 }
  else if (spell3 = "0xE7C36B") and (spell2 = "0x9FA589") and (spell4 != "0xFFFFFF")
 {
  send {f8} 
  sleep 100
 }
}
return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 59 guests