Multiple image search

Ask gaming related questions
Alexandra
Posts: 1
Joined: 04 Apr 2019, 02:26

Multiple image search

04 Apr 2019, 04:10

Hello,

I would like to ask for a help.
I'm a noob and came across AHK thanks to one game and one of my team mates.
He provided me with a script which worked perfectly fine until now.

The game however changed it's logic regarding a "collect button". Sometimes appears the old one (collect_button1.png), sometimes a new one(collect_button2.png).

I've tried to figure out how to add the new collect button into the below function so that in case the new button appears, the script will recognise it as well and click on it (exactly as by the old button), but unfortunately without any success.

Could someone please help me to add the new button (collect_button2.png) into the below function?


Here is the original function for the collect button (collect_button1.png - in green).


collectThrophy() {
; wait for victory or defeat flag
wait = 1
max_try = 0
while wait {
; exit loop if we made 100 tries (30s)
if max_try >= 100
return 0

; search for defeat
ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, images/flag_defeat.png
wait = %ErrorLevel%
; if we are defeated, don't click on 1st trophy location
if wait = 0
{
Click X, Y
return 0
}
Sleep, 300

ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, images/flag_victory.png
wait = %ErrorLevel%
max_try += 1
}

; wait for collect button
wait = 1
max_try = 0
while wait {
; exit loop if we made 20 tries (16s)
if max_try >= 20
return 0

; click on first throphy
Click 510, 465
Sleep, 500
; collect button
ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, images/collect_button1.png
wait = %ErrorLevel%
Sleep, 300
max_try += 1
}
; if image was found move cursor on the button and click
MouseMove X + 20, Y + 7
Click

; search for out of slot flag
Sleep, 500
ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, images/flag_not_enough_slots.png
; if out of slots flag was found exit
if ErrorLevel = 0
{
return 1
}
}


Many thanks in advance.
A.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 42 guests