Autoit Bot Tutorial 2 for Noobies

09/23/2010 17:24 ax5#1
Ok, so im back with a new noob tutorial to make a bot in Autoit for allot of online games. Remember to visit my website. :mofo:

If you haven't read my first post to to it [Only registered and activated users can see links. Click Here To Register...]

Ok like always you need this 2 programs.
Ok, now you will need to download the R32.zip file on this post. So now make a new project with ScTE, and ad all the text from 32.txt on the top of the new project. This code makes you work with Search on your screen for images. Her's the code also.


Quote:
#Region ### START ImageSearch ###
Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
return _ImageSearchArea($findImage,$resultPosition,0,0,@D esktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc

Func _ImageSearchArea($findImage,$resultPosition,$x1,$y 1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)

if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
$result = DllCall("ImageSearchDLL.dll","str","ImageSearch"," int",$x1,"int",$y1,"int",$right,"int",$bottom,"str ",$findImage)


if $result[0]="0" then return 0


$array = StringSplit($result[0],"|")

$x=Int(Number($array[2]))
$y=Int(Number($array[3]))
if $resultPosition=1 then
$x=$x + Int(Number($array[4])/2)
$y=$y + Int(Number($array[5])/2)
endif
return 1
EndFunc


Func _WaitForImageSearch($findImage,$waitSecs,$resultPo sition,ByRef $x, ByRef $y,$tolerance)
$waitSecs = $waitSecs * 1000
$startTime=TimerInit()
While TimerDiff($startTime) < $waitSecs
sleep(100)
$result=_ImageSearch($findImage,$resultPosition,$x , $y,$tolerance)
if $result > 0 Then
return 1
EndIf
WEnd
return 0
EndFunc


Func _WaitForImagesSearch($findImage,$waitSecs,$resultP osition,ByRef $x, ByRef $y,$tolerance)
$waitSecs = $waitSecs * 1000
$startTime=TimerInit()
While TimerDiff($startTime) < $waitSecs
for $i = 1 to $findImage[0]
sleep(100)
$result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance)
if $result > 0 Then
return $i
EndIf
Next
WEnd
return 0
EndFunc
#EndRegion ### START ImageSearch ###
Ok make a new folder on your desktop and add a new folder in it call it img and add the ImageSearchDLL.dll in the folder (not in the img folder.)
[Only registered and activated users can see links. Click Here To Register...]

Ok so make a picture of somthing you want the bot is going to click on if is there. so this is my image, also add it to the img folder.
[Only registered and activated users can see links. Click Here To Register...]

ok now to the coding part. This is a code to make the program read and see where the image is on your desktop, X Y angels.
Quote:
$x1=0
$y1=0
Then we will add a hot key to terminate the bot. This will terminate the bot when u press F1.
HotKeySet("{F1}", "Terminate")

Now we will need to open and close a loop.
Quote:
While 1

WEnd
Ok now in the loop we will need to add the code that fiends the image and clicks on it
Quote:
$result = _ImageSearch("img/2.bmp",1,$x1,$y1,1)
Here you will make a variable that makes the program know to what to search on. Also adding the posiion on X,Y angels.

Then we will need to make a IF sate that will make the movement and click or what ever.
Quote:
if $result=1 Then
MouseMove($x1,$y1,3)
MouseClick("left",$x1,$y1,1,3)
MouseClick("left",$x1,$y1,1,3)
EndIf
So now the script for that image will move and click on it "LEFT CLICK WITH THE MOUSE."

now out side of the loop we will need to finish the terminate kotkey script so add this code. This will me called when you press the F1 button

Quote:
Func Terminate()
Exit 0
EndFunc
ALERT, THE IMAGE MOST BE .BMP FORMAT.

FULL CODE HERE
Quote:
#Region ### START ImageSearch ###
Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
return _ImageSearchArea($findImage,$resultPosition,0,0,@D esktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc

Func _ImageSearchArea($findImage,$resultPosition,$x1,$y 1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)

if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
$result = DllCall("ImageSearchDLL.dll","str","ImageSearch"," int",$x1,"int",$y1,"int",$right,"int",$bottom,"str ",$findImage)


if $result[0]="0" then return 0


$array = StringSplit($result[0],"|")

$x=Int(Number($array[2]))
$y=Int(Number($array[3]))
if $resultPosition=1 then
$x=$x + Int(Number($array[4])/2)
$y=$y + Int(Number($array[5])/2)
endif
return 1
EndFunc


Func _WaitForImageSearch($findImage,$waitSecs,$resultPo sition,ByRef $x, ByRef $y,$tolerance)
$waitSecs = $waitSecs * 1000
$startTime=TimerInit()
While TimerDiff($startTime) < $waitSecs
sleep(100)
$result=_ImageSearch($findImage,$resultPosition,$x , $y,$tolerance)
if $result > 0 Then
return 1
EndIf
WEnd
return 0
EndFunc


Func _WaitForImagesSearch($findImage,$waitSecs,$resultP osition,ByRef $x, ByRef $y,$tolerance)
$waitSecs = $waitSecs * 1000
$startTime=TimerInit()
While TimerDiff($startTime) < $waitSecs
for $i = 1 to $findImage[0]
sleep(100)
$result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance)
if $result > 0 Then
return $i
EndIf
Next
WEnd
return 0
EndFunc
#EndRegion ### START ImageSearch ###

$x1=0
$y1=0

HotKeySet("{F1}", "Terminate")

While 1

$result = _ImageSearch("img/2.bmp",1,$x1,$y1,1)

if $result=1 Then
MouseMove($x1,$y1,3)
MouseClick("left",$x1,$y1,1,3)
EndIf


WEnd

Func Terminate()
Exit 0
EndFunc
Have fun. Remember to press thanks and visit my site.
09/29/2010 03:16 fierce134#2
sir why does my grandfaper bot automitically ends after 1minute
09/29/2010 04:07 Al1as#3
I always wondered how to get it to click something without coordinates...thanks!

EDIT: Code doesn't work.

if $result[0]="0" then return 0
if $result^ ERROR
10/05/2010 21:25 ax5#4
Quote:
Originally Posted by Al1as View Post
I always wondered how to get it to click something without coordinates...thanks!

EDIT: Code doesn't work.

if $result[0]="0" then return 0
if $result^ ERROR
MouseClick("left")

Quote:
Originally Posted by fierce134 View Post
sir why does my grandfaper bot automitically ends after 1minute
try using a Loop that never ends