Hi
17kimv
Your post became starting point for learning script language with my students. (There no faster way to take focus of yang brain like game.)
I never play League of Legend - so my comments possibly will be curios.
Comment 1:
Code: Select all
ImageSearch, x, y, 0, 0, 1920, 1080, health.png
;1920, 1080 throw script to be used in only this resolution
ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, health.png
;Any resolution is possible
Comment 2: In second ImageSearch
Code: Select all
ImageSearch, X, Y, 0, 0, 1920, 1080, health.png
;Here no IF ErrorLevel check that make ImageSearch nonsense
;The code below will be executed no matter of ImageSearch result and if FAIL x and y became ""
;I think that code must depends from ErrorLevel
xa := x+42
ya := y+100
mousemove, %xa%, %ya%, 0
Comment 3: It is known like DRY (Don`t Repeat Yourself) principle.
Code: Select all
send, {w down}
sleep 100
send, {w up}
;Here 3 times used this construction
It is better to be made function that will repeat the same code with low mistakes.
Code: Select all
slowSend(key, wait) {
send {%key% down}
sleep %wait%
send {%key% up}
}
The result in my opinion:
Code: Select all
#SingleInstance force
;autor : 17kimv
;original: https://autohotkey.com/boards/viewtopic.php?f=19&t=15425
XButton2::
ImageSearch, x, y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, health.png
if !ErrorLevel { ;if not ErrorLevel
mousemove, %x%+42, %y%+100, 0 ;xa and xb omited
slowSend("w", 100) ;avoid writing the same code
slowSend("e", 50)
sleep 30
ImageSearch, x, y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, health.png
if !ErrorLevel { ;if not ErrorLevel
mousemove, %x%+42, %y%+100, 0
slowSend("q", 10)
} }
return
#!Q::ExitApp
slowSend(key, wait) {
send {%key% down}
sleep %wait%
send {%key% up}
}
Please test the code and comment it.
Thanks in advance.
Edit:
In connection of
https://autohotkey.com/board/topic/9324 ... ntry587806Code: Select all
#SingleInstance force
;autor : 17kimv
;original: https://autohotkey.com/boards/viewtopic.php?f=19&t=15425
SendMode Event ;AHKv2.0 needed for SetKeyDelay
SetKeyDelay, 30, 80 ;{down} sleep 80 {up} sleep 30
#Z:: ;for easy test
ImageSearch, x, y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, health.png
if !ErrorLevel { ;if not ErrorLevel
mousemove, %x%+42, %y%+100, 0 ;xa and xb omited
send we
ImageSearch, x, y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, health.png
if !ErrorLevel { ;if not ErrorLevel
mousemove, %x%+42, %y%+100, 0
send q
} }
return
#!Q::ExitApp