Well it is very easy to coil your lich if you don't want to be too smart about it (i.e. just tell AHK to move the mouse to the 2nd hero portrait location without checking if a hero is there or if that hero is the lich). For a simple script like this you don't really need these smart features, but someday you may have a really cool script concept and may want (or need) to use pixel colors.
This code will select your first hero and attempt to cast whatever is bound to 'a' on your second hero. It is smart only in the sense that it will abort the casting if it doesn't find a second hero (advanced tooltips must be turned on for the script to work at all). If you don't want to have the "hero check" feature (or don't want to turn advanced tooltips on) delete the PixelGetColor and If(...) statements. You can also delete the ColorEqual() function in this case.
Code:
ColorEqual(x,y,t)
{
x += 0
y += 0
x1 := Floor(x/65536)
y1 := Floor(y/65536)
x2 := Floor((x-x1*65536)/256)
y2 := Floor((y-y1*65536)/256)
x3 := (x-x1*65536-x2*256)
y3 := (y-y1*65536-y2*256)
z1 := x1-y1
z1 := x2-y2
z1 := x3-y3
if (Abs(z1) <= t) and (Abs(z2) <= t) and (Abs(z2) <= t)
return 1
else
return 0
}
v::
SendPlay, {F1}
MouseGetPos, X1, Y1
MouseMove, 32, 127, 0 ; move to 2nd hero icon at the upper left
PixelGetColor, color, 745, 540 ; look for the tooltip on the bottom right
if(ColorEqual(color,0x238AAC,3) == 1)
Send, a{LButton}
Sleep, 10
MouseMove, %X1%, %Y1%, 0
return
Notes:
-I see AHK has its own ColorEqual() function which does the exact same thing as this one, I just haven't had time to play around with it yet.
-The 'next level' of automation as it were - automatically finding your Lich among all 3 hero portraits - is quite involved. The way I would do this is by using something like pixel matrix search (it has its own thread if you are really interested) to distinguish the 3 portraits.
Whenever you want to work with pixel positions or pixel colors the code may have to be changed from user to user. Screen resolution will affect pixel positions while video cards and color settings may affect pixel colors (*may* affect, the only thing I know for sure about pixel colors is that the in-game gamma setting doesn't affect PixelGetColor).
If you have to, you can find the right numbers using AHK itself. Use the following script as a tool for finding pixel coordinates and colors. Press u to retrieve the data from the pixel your mouse is currently over and press shift u to read the data.
Code:
u::
MouseGetPos, X1, Y1
PixelGetColor, color1
return
+u::
MsgBox Mouse X,Y was: %X1%, %Y1% Color was: %color1%
return
Getting *tooltip* colors and positions is a little trickier since they only appear when your mouse is in a certain location (in this case, over a hero portrait). Taking screenshots of the game helps here. Like I said before, for a simple script like this though you might just not bother with pixel colors at all.