Auto combination script. Need help to add image search...

Ask gaming related questions (AHK v1.1 and older)
Dooodge
Posts: 10
Joined: 06 Aug 2018, 08:39

Auto combination script. Need help to add image search...

06 Aug 2018, 11:43

Hello, I created simple script for combine items in game.
I looking for improve it.
Script work:
Here are 80 different jobs to do, mouse move to coordinate and double click, when send Space key 15 time with 2 sec sleep each time, when starts next job, here are different mouse move coordinates, but same 15 send space key.
i need help to be able skip job if i press [hotkey],
Or insert Image search (by coordinate) to script, (search starts at first send SPACE KEY, if image found> continue, if image not found> skip job and go to next job.)

This is how my code looks, i share first 3 jobs, all rest same, just different coordinate to mouse move.

Code: Select all

   
   
=:: ;Start script

Loop, 1 ;loop only 1 time

{
	SetDefaultMouseSpeed, 2
								; Bellow is job nr 1.======================
	MouseMove 1290, 300
	Click
	Click
	MouseMove 1255, 300
	Click
	Click
	send {Space}
	sleep 2000
	Click
	Click
								; Here i like to have image search, if image found> continue, else> skip, or skip this job any time i press programmed hotkey.
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	
								;Above job nr1 ended ==============
								;Continue to jon nr2. =============
	
	MouseMove 1320, 300
	Click
	Click
	MouseMove 1255, 300
	Click
	Click
	send {Space}
	sleep 2000
	Click
	Click
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	
								;Job nr2 ended =====================
								;Job nr3 start ======================
	
	MouseMove 1360, 300
	Click
	Click
	MouseMove 1255, 300
	Click
	Click
	send {Space}
	sleep 2000
	Click
	Click
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
									; Continuing  jobs...  4-5-6....... til job 80 end.
	
   
pro100andrik94
Posts: 27
Joined: 08 Aug 2018, 07:27

Re: Auto combination script. Need help to add image search...

08 Aug 2018, 12:31

it's not perfect solution, but i think it's not so bad

Code: Select all

Numpad0:: num++

=:: 
num := 1

Loop, 1 ;loop only 1 time

{

	SetDefaultMouseSpeed, 2

job1:
	MouseMove 1290, 300
	Click
	Click
	MouseMove 1255, 300
	Click
	Click
	send {Space}
	sleep 2000
	Click
	Click
  
    goto sendspace
    return
    
job2:
	MouseMove 1320, 300
	Click
	Click
	MouseMove 1255, 300
	Click
	Click
	send {Space}
	sleep 2000
	Click
	Click
   
    goto sendspace
    return
    
job3:
	MouseMove 1320, 300
	Click
	Click
	MouseMove 1255, 300
	Click
	Click
	send {Space}
	sleep 2000
	Click
	Click
   
    goto sendspace
    return
    
job4:
	MouseMove 1320, 300
	Click
	Click
	MouseMove 1255, 300
	Click
	Click
	send {Space}
	sleep 2000
	Click
	Click
   
    goto sendspace
    return

job5:
;  ...
job80:
	MouseMove 1320, 300
	Click
	Click
	MouseMove 1255, 300
	Click
	Click
	send {Space}
	sleep 2000
	Click
	Click

return

sendspace:
    num++
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000

    if (num == 81)
    return
    goto, job%num%
    
return
}
if you press Numpad0 once you can skip one job, twice = two jobs etc.
pro100andrik94
Posts: 27
Joined: 08 Aug 2018, 07:27

Re: Auto combination script. Need help to add image search...

08 Aug 2018, 12:56

and with imagesearch

Code: Select all

=:: 
num := 1

Loop, 1 ;loop only 1 time

{

	SetDefaultMouseSpeed, 2

job1:
	MouseMove 1290, 300
	Click, 2
	MouseMove 1255, 300
	Click, 2
	send {Space}
	sleep 2000
	Click, 2
  
    goto sendspace
    return
    
job2:
	MouseMove 1320, 300
	Click, 2
	MouseMove 1255, 300
	Click, 2
	send {Space}
	sleep 2000
	Click, 2
   
    goto sendspace
    return
    
job3:
	MouseMove 1320, 300
	Click, 2
	MouseMove 1255, 300
	Click, 2
	send {Space}
	sleep 2000
	Click, 2
   
    goto sendspace
    return
    
job4:
	MouseMove 1320, 300
	Click, 2
	MouseMove 1255, 300
	Click, 2
	send {Space}
	sleep 2000
	Click, 2
   
    goto sendspace
    return

job5:
;  ...
job80:
	MouseMove 1320, 300
	Click, 2
	MouseMove 1255, 300
	Click, 2
	send {Space}
	sleep 2000
	Click, 2

return

sendspace:
    num++

    ImageSearch, , , X1, Y1, X2, Y2, ImageFile	 ; The X1 and Y1 coordinates of the upper left corner of the rectangle to search
                                          				 ; The X2 and Y2 coordinates of the lower right corner of the rectangle to search
    if (ErrorLevel == 1)
    {
        num++
        goto nxt
    }
    	send {Space}
    	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000

nxt:
    if (num == 81)
    return
    goto, job%num%
    
return
}
but i'm not shure that will work corectly because i can't test it, because i don't know what the game is it and how imagesearch will act with it.
and you can use "Click, 2' for double click
Dooodge
Posts: 10
Joined: 06 Aug 2018, 08:39

Re: Auto combination script. Need help to add image search...

09 Aug 2018, 02:12

Oh great, thank you :)
Game name is "Rappelz" old one but im fan, and it still running official servers.
I play in private server, much more fun.
So about imagesearch, i will test it.
In combine window are many slots, but using only 2, for item and material. Image can be item or material to search, i can place combine window in same fixt position on same resolution, and use active window coordinate.
The script manual skip job and image search is for same job to do. But with image i can fully automate the combination work for 80 items.
As combination have chance to make item from +1 to +5 in single try, this is why i need skip job if my item allready made +20.
So it can take as low as 4 combination or as many as 20.
When combination reach max +20, items disaper, combine window empty, so imagesearch not find a image, and go to next job. After each combination and vaiting 2 sec, imagesearch have to look if item still in combine slot, if yes, continue send space and sleep 2 sec. If not find image, go to next job.
I think to much details :)
Thank you
pro100andrik94
Posts: 27
Joined: 08 Aug 2018, 07:27

Re: Auto combination script. Need help to add image search...

09 Aug 2018, 03:20

Yes, if you have only one image to search than you can do screenshot and crop it to item what you need to search. But from my experience when I try to automate invite to game from my friend in steam imagesearch won't search image of "play" button that I was saved before, but on full screenshot saved as image imagesearch can find it. I do not know what this is about, maybe because steam opens like overlay and imagesearch can't search on overlay, but can only on game. On this basis I was forced to use pixelsearch which worked correctly with steam overlay. But one more thing. After I ran script and pres hotkey to do this "accept script" first time it works perfect, but for the second and subsequent times script don't want to moove my cursor without reloading full script. So I do it in another file and if I need to use it i just run this file from my main script, this file do the job and close, so I can use it couple times without reloadind my main script.

Hope this little hints can help you with problems you can stumble in future.
Dooodge
Posts: 10
Joined: 06 Aug 2018, 08:39

Re: Auto combination script. Need help to add image search...

09 Aug 2018, 03:53

I use Windows mode game pay, here is no game guard to prevent using any program. i like the way you compressed my script :) i find some problems when i try different computer with different resolutions, when coordinates not mach, but main computer i use fix windows mode resolution, so all my scrips work same well, no matter were i move game on screen. maybe later i add to find active window, so if i by accident minimize game, script go to pause. it can make big mess on desktop xD.
now i go to test image search, and write a results.
Dooodge
Posts: 10
Joined: 06 Aug 2018, 08:39

Re: Auto combination script. Need help to add image search...

09 Aug 2018, 04:29

image search not working, if i leave like you made, it work like original version, i try to get MsgBox to see if its find image. but not get any msg to test if it finds.
pro100andrik94
Posts: 27
Joined: 08 Aug 2018, 07:27

Re: Auto combination script. Need help to add image search...

09 Aug 2018, 04:39

You can try to do it like this

Code: Select all

    ImageSearch, , , X1, Y1, X2, Y2, ImageFile	 ;
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    MsgBox Icon could not be found on the screen.
else
    MsgBox The icon was found.
Dooodge
Posts: 10
Joined: 06 Aug 2018, 08:39

Re: Auto combination script. Need help to add image search...

09 Aug 2018, 04:57

I will do this alone, to find out if its find image. If no luck, can i replace image search to pixel search, maybe you can make sample script same as imagesearch on top my script. Collors i will find my self :)
Thank you
Dooodge
Posts: 10
Joined: 06 Aug 2018, 08:39

Re: Auto combination script. Need help to add image search...

09 Aug 2018, 05:00

Also maybe i made mistake with path to image.
I crop printed screen and saved to .bmp
File sits C:\test.bmp
Im using win 10.
Dooodge
Posts: 10
Joined: 06 Aug 2018, 08:39

Re: Auto combination script. Need help to add image search...

09 Aug 2018, 07:45

Update, Image search not working in game, it can find on desktop or other programs, but game not working.
i change image search to Pixel search, it working 100%. but find out some problem.
after ahk go to: SendSpace, pixel search looking at first time for pixels. But after first Space send, no longer looking for pixels. maybe need add something.
Here what i need at pixel search:

Code: Select all

    PixelSearch, Px, Py, 1045, 785, 1090, 830, 0x3435FF, 3, Fast			 ; The X1 and Y1 coordinates of the upper left corner of the rectangle to search
                                          								 		; The X2 and Y2 coordinates of the lower right corner of the rectangle to search
    if (ErrorLevel == 1)
    {
        num++
        goto nxt
    }
    ;------------------------------------ (Right Now it search pixels at this stage, if it finds, it sends all 15 Space keys, and not looking for pixels)----------------------------------
    ; -----------------------------------I need change to: after each send Space + sleep 2000 > check pixels. Bellow examle
    	send {Space}
    	sleep 2000
    	;===================   At This point need check if pixels still exist. If yes> continue send next Space key. if no pixels> go to next job.
	send {Space}
	sleep 2000
	;===================   At This point need check if pixels still exist. If yes> continue send next Space key. if no pixels> go to next job.
	send {Space}
	sleep 2000
	;===================   At This point need check if pixels still exist. If yes> continue send next Space key. if no pixels> go to next job.
	send {Space}
	sleep 2000
	;===================   At This point need check if pixels still exist. If yes> continue send next Space key. if no pixels> go to next job.
	send {Space}
	sleep 2000
	; ETC, ETC.....
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000
	send {Space}
	sleep 2000

nxt:
    if (num == 81)
    return
    goto, job%num%
    
return
}
Dooodge
Posts: 10
Joined: 06 Aug 2018, 08:39

Re: Auto combination script. Need help to add image search...

09 Aug 2018, 14:19

script have problem.
num++ skip 2 jobs : example (start with job1: all ok. now no pixel found, and here starts job3. but we just skip job2 ?)
it gos like this:
job1:
space... pix search ok> space... no more pixel found> go next job...
job3:
same thing, skip...
job5:
job7:
job9..... why it skip 2-4-6 jobs it have to be 1-2-3-4-5.....
were is the problem ?
pro100andrik94
Posts: 27
Joined: 08 Aug 2018, 07:27

Re: Auto combination script. Need help to add image search...

10 Aug 2018, 06:43

I guess I understand you not to the end correctly or you have not explained correctly after which space you need to skip work. I thought that the checking image/pixel should be in the job, and the space clicking function should be sent without conditions. In this case that you explain now, the code will be slightly different.

Code: Select all

sendspace:
num++
        loop 14 ; 14 means number of repeating pressing space
        {
            send {Space}
            sleep 2000
            PixelSearch, , , 1045, 785, 1090, 830, 0x3435FF, 3, Fast	; if you don't need to use coordinates where pixels were found you can keep  OutputVarX, OutputVarY, options empty
            if (ErrorLevel == 1)
            break

        }
nxt:
    if (num == 81)
    return
    goto, job%num%
    
return
And I have previously missed that it is possible to reduce part of script of the pressing a space by putting it into a loop
Dooodge
Posts: 10
Joined: 06 Aug 2018, 08:39

Re: Auto combination script. Need help to add image search...

12 Aug 2018, 11:35

This looks way better.
Yes, i need check pixels after each space press.
If pixel still exist, then continue press space and sleep 2 sec. When check pixel, pixel no longer found, i see you insert "break" ? I think it have to be go to NXT.
Also found dublicate num++ in before script.
Dont have ability to test this now. But i need num++ only if pixel not found and goto nxt.
So maybe : if error level ==1 》 num++ 》 goto nxt
All other code work perfect with pixelsearch.
One more problem i found, when game start laging, script fail to work correctly, maybe its a way to monitor if game not laging ? Maybe its not posible to track if game sync with server. If here is no way to do this, its ok :)
And thank you for your help Pro100 !
pro100andrik94
Posts: 27
Joined: 08 Aug 2018, 07:27

Re: Auto combination script. Need help to add image search...

13 Aug 2018, 01:06

Break means exit from current loop and go to next operator which is nxt
If you need num++ after "if errorlevel = 1" you can put it there, BUT only if after the last sending space you have no pixels found in all cases. If once after last sending space script will found pixel he will go same job again, because counter num++ will stay the same.
About monitoring if game lagging I don't know. Try to google it. Or do another topic here.
Dooodge
Posts: 10
Joined: 06 Aug 2018, 08:39

Re: Auto combination script. Need help to add image search...

14 Aug 2018, 05:51

Ok, thank you Pro100. You help me alot !
From this scrip i have some other ideas to use.
Thanks for your time !

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Pianist and 12 guests