Detecting a specific color on a specific position and running a script depeding on it. Topic is solved

Ask gaming related questions (AHK v1.1 and older)
2kmentality
Posts: 16
Joined: 21 Apr 2021, 15:21

Detecting a specific color on a specific position and running a script depeding on it.

21 Apr 2021, 18:16

Hi, guys. I'm fairly new to scripting so please bear with me. :?

I made a simple script so I can afk farm a dungeon. However, an automated event messes things up as the server warps players within the area back into town every 2-3 hours.

Is it possible to detect a specific color ONLY on that specific position? Say, the mini-map for example. Can I warp my character back into the dungeon as soon as a small portion of it changes into a specific color?


Here's the first part of my script (for afk farming):

Code: Select all

#MaxThreadsperHotkey 2
~f1::

Previouskey:= !PreviousKey

loop
{

if PreviousKey
{
sleep, 400
mousemove 405, 325
send, {f1}
sleep, 150
mouseclick, left
sleep, 400
send, {f3}
}
else

break

}
return

...and the 2nd part (after getting warped back into town):

Code: Select all

send, {enter}@warp prontera 162 165{enter}
sleep, 3000
mousemove 500, 320
sleep, 3000
mouseclick, left
sleep, 3000
send, {enter}

I hope that you guys understand what I'm trying to say, and I hope someone's willing to make the code for me. It'll help me out a lot.

I've already tried a couple of things myself but it didn't worked out.
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Detecting a specific color on a specific position and running a script depeding on it.

21 Apr 2021, 19:04

You can use PixelSearch to get a color's location, or PixelGetColor to get a location's color.
2kmentality
Posts: 16
Joined: 21 Apr 2021, 15:21

Re: Detecting a specific color on a specific position and running a script depeding on it.

22 Apr 2021, 02:51

Hello! Thank you for the reply.

I've already tried using PixelSearch and PixelGetColor. But honestly, I don't know how to integrate it with the two codes I provided.
This is actually the first time I made a script. Can you give me any idea how to do it?

Thanks in advance!
2kmentality
Posts: 16
Joined: 21 Apr 2021, 15:21

Re: Detecting a specific color on a specific position and running a script depeding on it.

22 Apr 2021, 04:29

This is what I came up with, but it still doesn't work.

Code: Select all

#MaxThreadsperHotkey 2
NumPadAdd::Suspend

~F1::
PixelSearch, Px, Py, 946, 95, 0x618EB5, 1, RGB
if ErrorLevel
{
Previouskey:= !PreviousKey

loop
{

if PreviousKey
{
Sleep, 400
MouseMove 405, 325
Send, {f1}
Sleep, 150
MouseClick, Left
Sleep, 400
Send, {f3}
}
else

break
}
}

else
{
Send, {Enter}@warp prontera 162 165{Enter}
Sleep, 3000
MouseMove 500, 320
Sleep, 3000
MouseClick, Left
sleep, 3000
Send, {Enter}
}
return
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Detecting a specific color on a specific position and running a script depeding on it.

22 Apr 2021, 05:47

Since your script does not work, reduce it to a single line for testing: the pixel search. Syntax is below.

PixelSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID [, Variation, Mode]

Do the search, and then display the ErrorLevel.

If you need the variation option and you care about only a single pixel, you can set the two coordinates to be the same-- but you still need to specify both of them in the command.

Explained: PixelSearch
2kmentality
Posts: 16
Joined: 21 Apr 2021, 15:21

Re: Detecting a specific color on a specific position and running a script depeding on it.

22 Apr 2021, 06:12

Thank you so much! I somewhat managed to make my code work with this.
But it detects the pixelcolor only once as it continues on with the loop.
How can I make the code detect the pixelcolor with every loop instead?

Here's the revised code:

Code: Select all

#MaxThreadsperHotkey 2
NumPadAdd::Suspend

~F1::
PixelSearch, Px, Py, 946, 946, 95, 95, 0x618EB5, 1, Fast
if ErrorLevel
{
Previouskey:= !PreviousKey

loop
{

if PreviousKey
{
Sleep, 400
MouseMove 405, 325
Send, {F1}
Sleep, 150
MouseClick, Left
Sleep, 400
Send, {F3}
}
else

break

}
}

else
{
Send, {Enter}@warp prontera 162 165{Enter}
Sleep, 3000
MouseMove 500, 320
Sleep, 3000
Mouseclick, Left
Sleep, 3000
Send, {Enter}
}
return
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Detecting a specific color on a specific position and running a script depeding on it.

22 Apr 2021, 07:09

Putting a pixel search inside a loop is fair game.
2kmentality
Posts: 16
Joined: 21 Apr 2021, 15:21

Re: Detecting a specific color on a specific position and running a script depeding on it.

22 Apr 2021, 10:36

Can you give an example? I'm really new to this and its pretty overwhelming to understand most of it.
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Detecting a specific color on a specific position and running a script depeding on it.  Topic is solved

22 Apr 2021, 10:53

Code: Select all

#MaxThreadsperHotkey 2
SoundBeep, 1500
x := 946, y := 95 ; Coordinates relative to the active window

F1::
find := !find
While find {
 PixelSearch,,, x, y, x, y, 0x618EB5, 1, Fast ; Blue, green, red
 If ErrorLevel
  Send Not found`n
 Else Send Found`n
 Sleep, 300
}
Return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 54 guests