0
votes

I am using the AutoHotKey program and I have a script that monitors a certain pixel and it's color, and if it changes it will do something to make the color go back. So let's say it is looking at the pixel 100, 100 and the color is 0xFFFFFF, if the color changes to anything other than 0xFFFFFF the script will hit the number 5 key and it will go back to 0xFFFFFF. This works perfectly, now what I am here for is some help in getting one script to monitor TWO x,y positions and TWO separate colors, and using TWO different keys to change said colors back to the monitored color. This script is mainly used for playing online computer games like Ragnarok Online or WoW.

Here is the code for monitoring the ONE x,y and ONE color

#Persistent 
CoordMode, Pixel, Relative 

X := 100
Y := 100
SetColor := 0xC48559

SetTimer, WatchLife, 100
Return

WatchLife: 
Pixelgetcolor, Color, %X%, %Y%
if (Color = SetColor)
    Return 
    Else 
  Send, 5
  Sleep 20
Return

This script watches the HP bar and it get's below a certain area it will automatically press the number 5 key to use a HP Potion to get the HP bar back up. This helps gamers a lot so they don't have to pay that much attention to their HP and focus more on attacking a player or a monster.

Now I need a way to have one script that does this twice, the AutoHotKey program doesn't allow some lines to be repeated so you can't just copy paste this twice in one script, and yes you can use this script twice by changing the x,y's and color code, but having more than one script running at a time can mess with other scripts, I'v seen this happen and has happend to me a few times while running this script with another script.

I have tried this code;

#Persistent 
CoordMode, Pixel, Relative 

X := 100
Y := 100
SetColor := 0xC48559

X := 100
Y := 80
SetColor := 0xF0DED7

SetTimer, WatchLife, 100
Return

WatchLife: 
Pixelgetcolor, 0xC48559, 100, 100
if (Color = SetColor)
   Return 
Else 
   Send, 5
   Sleep 20
Pixelgetcolor, 0xF0DED7, 100, 80
if (Color = SetColor)
   Return 
Else 
   Send, 6
   Sleep 20
Return

I would assume this would work but it just spams the keys for the healing items of both HP and MP when the color in the pixel is there. I have searched on the main website and on the forums of AutoHotKey but I haven't seen anything about having this script.

Please help, this script would help out anyone who plays any online computer game that is similar to WoW or Ragnarok Online.

2

2 Answers

1
votes

How about this. I modified the first script so I could test it in my environment.

You generated a lot of send instructions because you did not define the variable where the PixelGetColor should be stored, so the If statement was always false. You also had a return after the first If, so the 2nd If was only executed if the first If was false (which was the case in your script, but not supposed to).

Persistent 
CoordMode, Pixel, Relative 

X1 := 200
Y1 := 200
SetColor1 := 0x999999

X2 := 200
Y2 := 1000
SetColor2 := 0xFFFFFF

SetTimer, WatchLife, 500
Return

WatchLife:
    Pixelgetcolor, Color, %X1%, %Y1%
    if (Color <> SetColor1)
        SoundBeep, 500, 200
    Pixelgetcolor, Color, %X2%, %Y2%
    if (Color <> SetColor2)
        SoundBeep, 1000, 200
Return

If you want to wait after the keystroke has been sent, then you should include the wait inside the If statement, like this.

Persistent 
CoordMode, Pixel, Relative 

X1 := 100
Y1 := 100
SetColor1 := 0xC48559

X2 := 100
Y2 := 80
SetColor2 := 0xF0DED7

SetTimer, WatchLife, 500
Return

WatchLife:
    Pixelgetcolor, Color, %X1%, %Y1%
    if (Color <> SetColor1)
    {
        Send, 5
        Sleep, 20
    }
    Pixelgetcolor, Color, %X2%, %Y2%
    if (Color <> SetColor2)
    {
        Send, 6
        Sleep, 20
    }
Return
1
votes

Could you try this first. Open a Notepad (white background) and and minimize all other applications (just the desktop). Move the Notepad window so that the white space is either over non of the two mouse positions, over both or over one of the two. You can exit with Ctrl+q, since you can't really use your mouse to exit the AHK.

Depending on the situation, you will hear no sound beeps, just one soundbeep (high OR low) or two soundbeeps (high AND low). The mouse will point where the pixel is located.

#Persistent 
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen 

X1 := 100
Y1 := 100
SetColor1 := 0xFFFFFF

X2 := 600
Y2 := 100
SetColor2 := 0xFFFFFF

SetTimer, WatchLife, 6000
Return

WatchLife:
    MouseMove, %X1%, %Y1%
    Pixelgetcolor, Color, %X1%, %Y1%
    TrayTip,, %Color%
    if (Color <> SetColor1)
    {
        SoundBeep, 500, 200
    }
    Sleep, 1000
    MouseMove, %X2%, %Y2%
    Pixelgetcolor, Color, %X2%, %Y2%
    TrayTip,, %Color%
    if (Color <> SetColor2)
    {
        SoundBeep, 1000, 200
    }
Return


^q::
ExitApp