Help with thinking this bot up

04/21/2019 05:55 tafradrasu#1
Hello everyone and thank you for allowing this awesome forum.

I'am trying to write a little bot here, for a mobile game in an emulator, you can see it in the image below.

[Only registered and activated users can see links. Click Here To Register...]

the idea is to drag every 2 similar items together so they merge.

So the way I've been thinking I should do this is as follow:
1. Make a library for every weapon by taking a screenshot then use paint.exe to change it to .bmp format (one time only).

2. Capture a snapshot of the game.
3. Image search one weapon at a time into the snapshot and store the coordinates of the similar weapons in an array.
4. Click and drag from coordinate[i] to coordinate[i+1] in the array till it's done.
5. Repeat #3 and #4 for each weapon in the library.
6. Once done, wait x minutes and go to #2.

Any better way to do it?
I can't use PixelSearch here, right? Because the location of the items is not fixed.


I started by testing the imageSearchEX function but it never finds the weapon in the game.

Code:
#RequireAdmin
#AutoIt3Wrapper_UseX64=NO
#include <imageSearchEX.au3>


$Win_Title = "(GrowStone)"
$Image_Path = @ScriptDir  & "\Image_Lib\Donut.bmp"

$Image_Coordinates = imageSearchEX($Win_Title,$Image_Path)

If $Image_Coordinates <> 0 Then
	MsgBox(0,"BINGO",$Image_Coordinates[0] & " " & $Image_Coordinates[1])
 Else
    MsgBox(0,"NICHTS","Image Not Found",50)
 EndIf
Any insights what could be the reason?

Ich bedanke Ihnen.
04/21/2019 16:30 FacePalmMan#2
1. Are you 100% sure the title and file path are correct?
2. I have not worke with imageSearch for a long time. Try to output the @error code and find out what it means.
3. If everything indicates that the image is really just not being found, try turning the tolerance value up a little. I think imageSearchEx has a parameter that goes from 0-255 with 255 finding only 100% exact match.

If that makes it work: Don't compare coordinate[i] + coordinate[i+1]. Have a 2D array that contains all values parsed to some form of item ID or name.
Then you do 2 for loops like this:
Code:
For $i = 0 To Ubound($coordinate, 1)
    For $j = 0 To Ubound($coordinate, 2)
        ;check surrounding and act
    Next
Next
In it you put the if clause that checks for a match, together with the MouseClickDrag.
Like this:
Code:
$aIsEqual = check($i, $j)
If IsArray($aIsEqual) Then
    MouseClickDrag("left", $aIsEqual[0][0], $aIsEqual[0][1], $aIsEqual[1][0], $aIsEqual[1][2])
EndIf
And check() should be defined at the end, looking sort of like this:
Code:
Func check($x, $y)
    Local $retX, $retY, $aRet[2] ;If something is found, it is saved into retX&Y. aRet is for output.
    If $x > 0 and $coordinate[$x][$y] == $coordinate[$x-1][y] Then ;If it is not on the very left, check to the left.
        $retX = $x - 1
        $retY = $y
    ElseIf $y > 0 and $coordinate[$x][$y] == $coordinate[$x][$y - 1] Then ;If it is not on the very top, check on top of it.
        $retX = $x
        $retY = $y - 1
    ElseIf $x < Ubound($coordinate, 1) - 1 and $coordinate[$x][$y] == $coordinate[$x+1][y] Then ;If it is not on the very right, check to the right.
        $retX = $x + 1
        $retY = $y
    ElseIf $y < Ubound($coordinate, 2) - 1 and $coordinate[$x][$y] == $coordinate[$x][$y + 1] Then ;If it is not on the very bottom, check beneath it.
        $retX = $x
        $retY = $y + 1
    EndIf
    $aRet[0] = $retX
    $aRet[1] = $retY ;Put the found (or not found) values into the return array
    Return (IsInt($retX)) ? ($aRet) : (False) ;"Ternary operator". If there is something in retX, $aRet (with retX,retY) will be returned, otherwise False.
EndFunc
This is how it could look like if you want to scan what is above and beneath it and match it like that. But that's just a suggestion.
04/22/2019 01:23 tafradrasu#3
Quote:
Originally Posted by FacePalmMan View Post
1. Are you 100% sure the title and file path are correct?
2. I have not worke with imageSearch for a long time. Try to output the @error code and find out what it means.
3. If everything indicates that the image is really just not being found, try turning the tolerance value up a little. I think imageSearchEx has a parameter that goes from 0-255 with 255 finding only 100% exact match.

If that makes it work: Don't compare coordinate[i] + coordinate[i+1]. Have a 2D array that contains all values parsed to some form of item ID or name.
Then you do 2 for loops like this:
Code:
For $i = 0 To Ubound($coordinate, 1)
    For $j = 0 To Ubound($coordinate, 2)
        ;check surrounding and act
    Next
Next
In it you put the if clause that checks for a match, together with the MouseClickDrag.
Like this:
Code:
$aIsEqual = check($i, $j)
If IsArray($aIsEqual) Then
    MouseClickDrag("left", $aIsEqual[0][0], $aIsEqual[0][1], $aIsEqual[1][0], $aIsEqual[1][2])
EndIf
And check() should be defined at the end, looking sort of like this:
Code:
Func check($x, $y)
    Local $retX, $retY, $aRet[2] ;If something is found, it is saved into retX&Y. aRet is for output.
    If $x > 0 and $coordinate[$x][$y] == $coordinate[$x-1][y] Then ;If it is not on the very left, check to the left.
        $retX = $x - 1
        $retY = $y
    ElseIf $y > 0 and $coordinate[$x][$y] == $coordinate[$x][$y - 1] Then ;If it is not on the very top, check on top of it.
        $retX = $x
        $retY = $y - 1
    ElseIf $x < Ubound($coordinate, 1) - 1 and $coordinate[$x][$y] == $coordinate[$x+1][y] Then ;If it is not on the very right, check to the right.
        $retX = $x + 1
        $retY = $y
    ElseIf $y < Ubound($coordinate, 2) - 1 and $coordinate[$x][$y] == $coordinate[$x][$y + 1] Then ;If it is not on the very bottom, check beneath it.
        $retX = $x
        $retY = $y + 1
    EndIf
    $aRet[0] = $retX
    $aRet[1] = $retY ;Put the found (or not found) values into the return array
    Return (IsInt($retX)) ? ($aRet) : (False) ;"Ternary operator". If there is something in retX, $aRet (with retX,retY) will be returned, otherwise False.
EndFunc
This is how it could look like if you want to scan what is above and beneath it and match it like that. But that's just a suggestion.
Ok thank you for your reply, I'll give what you said some thought, do some testing and report back here :)