Help me create my Macro script ( with STEPS and DIAGRAM)

Ask gaming related questions (AHK v1.1 and older)
kentpachi
Posts: 152
Joined: 15 May 2016, 01:23

Help me create my Macro script ( with STEPS and DIAGRAM)

09 May 2017, 22:56

Hello AHKers

Can you help me create my macro for my game please?

First, let me show you my script

Code: Select all

Loop
 {
MouseGetPos, mousePosX, mousePosY
  WinGetPos, , , winSizeX, winSizeY, A
  ImageSearch, imageLocX, imageLocY, 0, 0, %winSizeX%, %winSizeY%, starve.png
  if ErrorLevel = 0
sleep, 500
ImageSearch, imageLocX, imageLocY, 0, 0, %winSizeX%, %winSizeY%, 1.png
if ErrorLevel = 0
Click right %imageLocX%, %imageLocY%, 1
sleep, 3000
Click 774, 212
sleep, 3000

return
}

F3::pause
F5::reload
return
Now what does it do is it will search image then right click a 2nd image then click a specific location
here's a concept

1st step:
it will search this image Image
if it will find the image proceed to step 2, if not go back to step 1

2nd step:
it will search another image again, this image Image then right click it
if image found right click then proceed to step 3
if not go back to step 1
step 3:
it will then click this coordinate
Click 774, 212
after click go back to step 1 again


here's a diagram
Image

thats it good sirs but unfortunately my script i made is pure fail. I need your help masters

sorry for my bad english and explanation
Thank you very much
User avatar
theartofx
Posts: 15
Joined: 07 May 2017, 15:50

Re: Help me create my Macro script ( with STEPS and DIAGRAM)

10 May 2017, 13:04

Not real familiar with image searches, but at cursory glance, you need to enclose multiple instructions an "If" statement performs in brackets.

Code: Select all

Loop
{
  MouseGetPos, mousePosX, mousePosY
  WinGetPos, , , winSizeX, winSizeY, A
  ImageSearch, imageLocX, imageLocY, 0, 0, %winSizeX%, %winSizeY%, starve.png
  if ErrorLevel = 0
  {
    sleep, 500
    ImageSearch, imageLocX, imageLocY, 0, 0, %winSizeX%, %winSizeY%, 1.png
    if ErrorLevel = 0
    {
      Click right %imageLocX%, %imageLocY%, 1
      sleep, 2000 
      Click 774, 212
      sleep, 2000
    }
  }
;return    ; Commented out as would end loop on one iteration as noted below.
}
Edits: Commented out return and changed to 2 second sleeps as noted by poster below. Apologies, had just copy/pasted the code and bracketed out the If statements.
Last edited by theartofx on 10 May 2017, 16:33, edited 2 times in total.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Help me create my Macro script ( with STEPS and DIAGRAM)

10 May 2017, 15:52

Your diagram may have some flaws in it, logically.

If image1 is found, you would like to search for image2. (I assume really you mean keep looking until image1 is found). And you want to right click image2. But what if it's not found? Do you still want to right click where you think it should be? Is the right click supposed to be for the 774, 212, or is that a second left click?

Finally, after step 3 was performed, do you want it to go to step 1 eve if the click was not a success? I don't know what would be considered not a success.

I do appreciate the diagram, it can be helpful for figuring out what you want. But there are some questions here.

@theartofx, you have a return within your loop, so it'll only run the loop once. If the image isn't found, that's it, the script is done. If it is found, it'll be able to search for the second image and possibly do clicks, but that's it, it'll only happen once.

Additionally, @kentpachi was looking for some Sleep 2 seconds, which would be Sleep 2000 instead of the 3000s that you're using. No big deal there though.
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Help me create my Macro script ( with STEPS and DIAGRAM)

10 May 2017, 16:23

I ask the question bu image it and guess

Mostly the same questions mentioned above, but Inkscape does make a lot better arrows than ms paint :D
oMNMct8_inkscaped.png
oMNMct8_inkscaped.png (37.5 KiB) Viewed 2050 times
kentpachi
Posts: 152
Joined: 15 May 2016, 01:23

Re: Help me create my Macro script ( with STEPS and DIAGRAM)

12 May 2017, 09:49

theartofx wrote:Not real familiar with image searches, but at cursory glance, you need to enclose multiple instructions an "If" statement performs in brackets.

Code: Select all

Loop
{
  MouseGetPos, mousePosX, mousePosY
  WinGetPos, , , winSizeX, winSizeY, A
  ImageSearch, imageLocX, imageLocY, 0, 0, %winSizeX%, %winSizeY%, starve.png
  if ErrorLevel = 0
  {
    sleep, 500
    ImageSearch, imageLocX, imageLocY, 0, 0, %winSizeX%, %winSizeY%, 1.png
    if ErrorLevel = 0
    {
      Click right %imageLocX%, %imageLocY%, 1
      sleep, 2000 
      Click 774, 212
      sleep, 2000
    }
  }
;return    ; Commented out as would end loop on one iteration as noted below.
}
Edits: Commented out return and changed to 2 second sleeps as noted by poster below. Apologies, had just copy/pasted the code and bracketed out the If statements.
tried this already but it seems it doesnt work like c programming :(
kentpachi
Posts: 152
Joined: 15 May 2016, 01:23

Re: Help me create my Macro script ( with STEPS and DIAGRAM)

12 May 2017, 09:54

Exaskryz wrote:Your diagram may have some flaws in it, logically.

If image1 is found, you would like to search for image2. (I assume really you mean keep looking until image1 is found). And you want to right click image2. But what if it's not found? Do you still want to right click where you think it should be? Is the right click supposed to be for the 774, 212, or is that a second left click?

Finally, after step 3 was performed, do you want it to go to step 1 eve if the click was not a success? I don't know what would be considered not a success.

I do appreciate the diagram, it can be helpful for figuring out what you want. But there are some questions here.

@theartofx, you have a return within your loop, so it'll only run the loop once. If the image isn't found, that's it, the script is done. If it is found, it'll be able to search for the second image and possibly do clicks, but that's it, it'll only happen once.

Additionally, @kentpachi was looking for some Sleep 2 seconds, which would be Sleep 2000 instead of the 3000s that you're using. No big deal there though.
*"(I assume really you mean keep looking until image1 is found)" - yes keep find image 1

*"And you want to right click image2. But what if it's not found? Do you still want to right click where you think it should be? Is the right click supposed to be for the 774, 212, or is that a second left click?" - If image2 is not found keep looking it like image1 does, the right click is for image2 so that means when the script finds the images2 then it will right click and proceed to step 3 which is to left click in 774, 212 screen position

* "was looking for some Sleep 2 seconds" - sleep not really needed at all but it helps me prevent looping bug (ive been using sleep with my script especially when i use looping to prevent high cpu usage when running a very long time)
kentpachi
Posts: 152
Joined: 15 May 2016, 01:23

Re: Help me create my Macro script ( with STEPS and DIAGRAM)

12 May 2017, 09:57

Almost_there wrote:I ask the question bu image it and guess

Mostly the same questions mentioned above, but Inkscape does make a lot better arrows than ms paint :D

oMNMct8_inkscaped.png
* sleep not really needed at all, you can ignore it
* offset? i dont really know much about programming so im not sure what you mean but if you mean what is to right click then its the image2

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 50 guests