Press Space if color changes

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ExtaWee
Posts: 7
Joined: 07 Mar 2019, 17:35

Press Space if color changes

07 Mar 2019, 17:41

Hey guys, I was wondering if anyone could help me with a script for Pokemon Planet (browser game). When the color changes from brown to blue, the bot presses the space bar and repeats it over and over again.

I already have this but it doesn't work:
^n::
loop {
PixelGetColor, color1, 995, 602, RGB
PixelGetColor, color2, 995, 602, RGB
if(color1 != #56b5b7){
Send, {space}
} else {
Sleep, 80
}
if(color2 != #a98f68){
Send, {space}
} else {
Sleep, 80
}
}
return

Numpad9::exitapp

And please excuse my English, I'm from Germany :)
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: Press Space if color changes

08 Mar 2019, 03:58

Hi,

You'll need to change the color recognition of the if command. Use if(color = "0x -6DigitcolorCode- ")
Here is an example.

Code: Select all

^n::
loop {
PixelGetColor, color1, -1100, 850		; blue
PixelGetColor, color2, -1100, 850		; white
if(color1 = "0xFFFFFF")	            	; if white
	msgbox w
if(color2 = "0xFFE8E8")					; if blue
	msgbox b
}
; mousemove, -1100, 850					; check the right coordinates with mousemove or window spy
return
ExtaWee
Posts: 7
Joined: 07 Mar 2019, 17:35

Re: Press Space if color changes

08 Mar 2019, 04:55

Hey,

Thank you very much for the script but I actually have no idea how and where I get the right color code. Do I need Window Spy again or is there a website
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: Press Space if color changes

08 Mar 2019, 05:02

ExtaWee wrote:
08 Mar 2019, 04:55
Hey,

Thank you very much for the script but I actually have no idea how and where I get the right color code. Do I need Window Spy again or is there a website
There are lots of programs but since I'm lazy and almost never use pixelcolor I just use print screen and paste it in paint.net.
After this, use the pencil(?), don't know what it's called and click the color you want to get the color code from. Press more at the 'colors' window and then the hex code is shown.
Paint.PNG
Paint.PNG (11.1 KiB) Viewed 5746 times
***EDIT***
Window Spy works too :)
ExtaWee
Posts: 7
Joined: 07 Mar 2019, 17:35

Re: Press Space if color changes

08 Mar 2019, 05:47

Okay now i have this:

Code: Select all

^n::
loop {
PixelGetColor, color1, 996, 602		; blue
PixelGetColor, color2, 996, 602		; white
if(color1 = "0x56B5B7")	            	; if white
	msgbox {space}
if(color2 = "0xA98F68")					; if blue
	msgbox {space}
}
; mousemove, 996, 602					; check the right coordinates with mousemove or window spy
return
but nothing happens. Do i need to press something to let ist start?
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: Press Space if color changes

08 Mar 2019, 06:08

No, you'll have to modify the code. I posted just an example since I wasn't really sure what you want to do :)
Please take a look at the tutorial of AHK, you are able to fix the code yourself.
https://autohotkey.com/docs/Tutorial.htm

From what I understand from the code you posted you want to send a space when the color is brown or blue?
Than the code should look something like this.

Code: Select all

^n::							; press ctrl+n to start script
loop {
PixelGetColor, color1, 996, 602		; blue
PixelGetColor, color2, 996, 602		; brown
if(color1 = "blue")	            		; if blue (change hex code)
	send {space}				; press space
if(color2 = "brown")				; if brown (change hex code)
	send {space}				; press space
}
return

esc::ExitApp					; press escape to stop script
If this isn't what you want please be a bit more specific.
Do you want to press space only when the color changes from brown to blue? And also when the color changes from blue to brown?
Can the color only be blue and brown?
ExtaWee
Posts: 7
Joined: 07 Mar 2019, 17:35

Re: Press Space if color changes

08 Mar 2019, 07:20

so in this game, you have to mine stones these stones are blue, if you want to start mining you have to press Spacebar and after like 1 min you are finished with mining and the stone turns brown and returns blue after 10 sec and you are able to mine again. So the just have to recognize if the stone is blue or not and if it's blue press spacebar.
Attachments
FireShot Capture 003 -  - pokemon-planet.com.png
FireShot Capture 003 - - pokemon-planet.com.png (297.99 KiB) Viewed 5725 times
FireShot Capture 002 -  - pokemon-planet.com.png
FireShot Capture 002 - - pokemon-planet.com.png (258.72 KiB) Viewed 5726 times
FireShot Capture 001 -  - pokemon-planet.com.png
FireShot Capture 001 - - pokemon-planet.com.png (306.57 KiB) Viewed 5726 times
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: Press Space if color changes

08 Mar 2019, 07:50

Ok, try changing the code to this than. It presses space when the rock is blue (mineable) and does nothing when the stone is brown.
When the stone is brown it checks every second if the stone is still brown. If it turns blue again then the script presses space again.

Code: Select all

if(color1 = "blue")	            		; if blue (change hex code)
	send {space}				; press space
if(color2 = "brown")				; if brown (change hex code)
	sleep 1000				; wait 1 sec
BTW, can't you just spam spacebar all the time even though the stone is brown? Or won't the stone reset to blue then?
Complete code will look like this.
Spoiler
ExtaWee
Posts: 7
Joined: 07 Mar 2019, 17:35

Re: Press Space if color changes

08 Mar 2019, 08:18

Which of these coordinates should I pick?

And if you start mining and press space again it will stop mining

edit: Okay It's still doesn't work and I think that the color codes are incorrect.
Attachments
2019.03.08-14.15.png
2019.03.08-14.15.png (411.01 KiB) Viewed 5715 times
AviationGuy
Posts: 188
Joined: 17 Jan 2019, 10:13

Re: Press Space if color changes

08 Mar 2019, 10:34

If the mining time and the waiting time are the same each time you could also skip the PixelGetColor function.
Just write a script that holds space for x sec, wait x sec and repeat.
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: Press Space if color changes

08 Mar 2019, 11:09

Remember that paint outputs in RGB and pixelgetcolor default is BGR Also you don't need to do pixelgetcolor twice, do it only once and compare the same output twice with if and else if. You need to set the proper coordmode for the coords you wrote.
If the timing is exactly like what you say "press spacebar, wait 1 minute for it to stop mining, wait 10 seconds for it to turn blue again, repeat" then you can simply do that with sleeps

Code: Select all

loop
{
	sendinput {space}
	sleep, 71000 ; 71 seconds
	sendinput {space}
}
or using settimer

Code: Select all

settimer, mine, 71000
return

mine:
sendinput {space}
return
ExtaWee
Posts: 7
Joined: 07 Mar 2019, 17:35

Re: Press Space if color changes

09 Mar 2019, 05:30

AviationGuy wrote:
08 Mar 2019, 10:34
If the mining time and the waiting time are the same each time you could also skip the PixelGetColor function.
Just write a script that holds space for x sec, wait x sec and repeat.
The mining and waiting times are randomly between 1.3 min and 5 sec
ExtaWee
Posts: 7
Joined: 07 Mar 2019, 17:35

Re: Press Space if color changes

09 Mar 2019, 05:45

kyuuuri wrote:
08 Mar 2019, 11:09
Remember that paint outputs in RGB and pixelgetcolor default is BGR Also you don't need to do pixelgetcolor twice, do it only once and compare the same output twice with if and else if. You need to set the proper coordmode for the coords you wrote.
If the timing is exactly like what you say "press spacebar, wait 1 minute for it to stop mining, wait 10 seconds for it to turn blue again, repeat" then you can simply do that with sleeps

Code: Select all

loop
{
	sendinput {space}
	sleep, 71000 ; 71 seconds
	sendinput {space}
}
or using settimer

Code: Select all

settimer, mine, 71000
return

mine:
sendinput {space}
return
Okay now it works with the BGR colors but it is like the bot spams the spacebar, but it should be just one time
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: Press Space if color changes

09 Mar 2019, 13:57

ExtaWee wrote:
09 Mar 2019, 05:45
kyuuuri wrote:
08 Mar 2019, 11:09
Remember that paint outputs in RGB and pixelgetcolor default is BGR Also you don't need to do pixelgetcolor twice, do it only once and compare the same output twice with if and else if. You need to set the proper coordmode for the coords you wrote.
If the timing is exactly like what you say "press spacebar, wait 1 minute for it to stop mining, wait 10 seconds for it to turn blue again, repeat" then you can simply do that with sleeps

Code: Select all

loop
{
	sendinput {space}
	sleep, 71000 ; 71 seconds
	sendinput {space}
}
or using settimer

Code: Select all

settimer, mine, 71000
return

mine:
sendinput {space}
return
Okay now it works with the BGR colors but it is like the bot spams the spacebar, but it should be just one time
Add more delay after it presses spacebar
justin02
Posts: 2
Joined: 14 Sep 2019, 20:29

Re: Press Space if color changes

14 Sep 2019, 21:44

Hey, sorry for necroing this thread.

Code: Select all

^n::
loop {
PixelGetColor, color1, 800, 300
if (color1 = "0xFFFFFF")
{
	send {space}
}
else
{
	sleep 20
}

return
}
^m::ExitApp
I'm trying to make AHK press space when color at pixel X800, Y300 is completely white.
If it isn't, it should wait a little and check again after 20ms.

The script doesn't work, what am I doing wrong ?
Sid4G
Posts: 48
Joined: 02 Apr 2016, 19:11

Re: Press Space if color changes

15 Sep 2019, 03:52

Please change autohotkey.com title to autocheatforum.com @devs
justin02
Posts: 2
Joined: 14 Sep 2019, 20:29

Re: Press Space if color changes

15 Sep 2019, 09:51

I got it working. For anyone else interested:

Code: Select all

F1::									; F1 starts script
loop {
PixelGetColor, color1, 700, 300			; red
PixelGetColor, color2, 700, 300			; green
if(color1 = "0x0000FF")	            	; if red > press space
	SendInput {space}
	sleep 500							; wait 0.5s before looping, otherwise if color = red, it'll start spamming space
if(color2 = "0x00FF00")					; if green > wait 0.5s
	sleep 500
}
return									; goes back to start
F2::ExitApp								; F2 ends script

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk, Spawnova, toddhere, USS_Sandhu and 301 guests