[Wartune] E's AutoIt Scripts Daru Farmbot

06/10/2013 13:44 Schaikur#61
i have give it a try, the farm bot can only stealing but no plant revive oder take the weed. maybe it need another images for it. the worldmap farming do nothing. i will give a try and edit it
06/10/2013 23:04 VVayinsane#62
worldmap does if farmbot does, you need to make changes...read through the forums you will find the answers your looking for. You will need to change the coords that your x and y look at and searchicon. Also you may need to edit the attack image(most people have to). To see if it works find a chest start the bot. It will lock on (may take a few trys depending on what brightness the chest is at) if it goes to attack and wont click the attack button then yes you will need to change the attack image( I put a attack image in an earlier forum that does work for me).
06/11/2013 08:43 Ewvyx#63
Sorry folks. I will try to get back to this soon but something huge came up last week and it has been a chore dealing with that and other projects. Thanks VVayinsane for helping people out in my absence. I should be more responsive this week and I will be working on it when I get some free time.
06/11/2013 12:50 Schaikur#64
kk thx VVayinsane
still i need sometime to understand the source code before i dédit it for demonslayer.
I will give you guys a call if im am seccesful :)
06/11/2013 17:16 KilleN^#65
First wanted to say thanks for a great script.

Let me say this. I am in Fetid Swamp currently. taking my own images of monsters. The script runs and finds managog, It clicks someone else on the screen (doesnt hit managog) and then stops on attack part of script. Im trying to figure how to get my mouse to find and click the managog once the script recognizes the image I took.
06/11/2013 21:31 richardrah#66
Thanks for all the great work you guys are doing with this, i don't really know what i'm doing with autoit but have followed the instructions on fixes for mouse position etc. but i'm having no joy, I tried the script in murken forest with the new images of managogs but keep getting an error come up, something about line 40. The only thing i can think is that my resolution is too low for this to work in its current form, here's hoping you guys can work out one for 1366x768 :)
06/11/2013 22:30 VVayinsane#67
KilleN^ - Your haven false positive. You need to cut a new image of the mob and see if that will work without any false positives. Its takes time but your be able to get it working without any false hits but you will get them. Just cut a new image of a different part. On one mob it took me about 5 trys until i was able to find a working image.

Richardrah - screen size isnt the issue for that. Please can you post your script on here. Please make sure to use wrap code around the script [Code]your script goes here[./Code]
Just make sure to remove the .
06/11/2013 23:13 richardrah#68
Code:
;===========================================================================================================
;@Author Ewvyx  I wrote this so please don't slap your name on it.

;This script searches through the wilds of Erandel and fights Managogs for Daru Pearls
;It is designed for a 1920x1080 display
;Works best if you start in the top left most corner of the wilds map (less wait time for your character to move to the first found managog)
#RequireAdmin
#include <ImageSearch.au3>

;===========================================================================================================
;Global Variables (DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING)

;X Coords Input on 1920x1080 :  1518x198
;Y Coords Input on 1920x1080 :  1553x198

$Version = "1.1.0a"
Global $Paused
Global $gX = 0
Global $gY = 0
Global $c1X = 0
Global $c1Y = 0
Global $c2X = 0
Global $c2Y = 0
Global $success = False ;boolean for various checks
Global $managogFound = False ;flag for when a managog is found by _ImageSearch
Global $tolFail = 0 ;tolerance failures for _ImageSearch
Global $troopRecruitY = 0 ;Y coordinate of specified troop portrait in recruit troops window
Global $searchCoordsFound = False
$bmpLocation = @ScriptDir & "\Pics"
$managogsDir = "Managogs"
$buttonsDir = "Buttons"

;===========================================================================================================
;User Defined Variables

Global $mapX = 15 ;change this to the x coordinate of the map that your character is in. map starts at 15, goes to 585
Global $mapY = 8 ;change this to the x coordinate of the map that your character is in. map starts at 8, goes to 591
$collectTreasure = True ;set to True if you want to attack treasure caches as well, False if do not
$troops = "warlock" ;set this to the troops you are using i.e. "templar" or "warlock"
$defaultCheckRate = .1 ;smaller the number, the faster the image checks are.  increase if managogs aren't being found.

;===========================================================================================================
;HotKeys

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("q","RunScript")
HotKeySet("x","ChangeCoords")

;===========================================================================================================
;~Functions

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Func CheckFor($directory,$img,$tolerance=50,$startX=0,$startY=0,$endX=@DesktopWidth,$endY=@DesktopHeight,$seconds=$defaultCheckRate)
	$c = 0
	MouseMove(0,(@DesktopHeight/2),0)
	$string = $bmpLocation & "\" & $directory & "\" & $img & ".bmp"
	If $img = "city" Then
		$updateString = "Wilds View"
	Else
		$updateString = $img
	EndIf
	ToolTip("Checking for " & $updateString,0,0)
	$tolerance = 50
	If $directory = $managogsDir Then
		$tolerance = 100		
	EndIf
	If $img = "treasure" Then
		$tolerance = 35
	ElseIf $img = "attackingsword" Then
		$tolerance = 70
	EndIf
	If $tolFail > 0 Then
		$tolerance += $tolFail
	EndIf
	Do
		$c += 1
		Sleep(100)
		If $c > ($seconds * 10) Then
			Return False
		EndIf
	Until _ImageSearchArea($string,1,$startX,$startY,$endX,$endY,$gX,$gY,$tolerance)
	;Until _ImageSearchArea($string,1,216,180,1723,1002,$gX,$gY,$tolerance)
	Sleep(500)
	Return True
EndFunc

Func ClickImage($directory,$img,$tolerance=50,$startX=0,$startY=0,$endX=@DesktopWidth,$endY=@DesktopHeight,$seconds=$defaultCheckRate)
	If CheckFor($directory,$img,$tolerance,$startX,$startY,$endX,$endY,$seconds) Then
		MouseClick("left",$gX,$gY,1,0)
		Return True
	Else
		Return False
	EndIf
EndFunc	

Func HoverOverImage($directory,$img,$tolerance=50,$startX=0,$startY=0,$endX=@DesktopWidth,$endY=@DesktopHeight,$seconds=$defaultCheckRate)
	If CheckFor($directory,$img,$startX,$startY,$endX,$endY,$seconds,$tolerance) Then
		MouseMove($gX,$gY,0)
		Sleep(2000)
		Return True
	Else
		Return False
	EndIf
EndFunc

Func ClickOffsetOfImage($direction,$offset,$directory,$img,$clicks=1,$tolerance=50,$startX=0,$startY=0,$endX=@DesktopWidth,$endY=@DesktopHeight,$seconds=$defaultCheckRate)
	If CheckFor($directory,$img,$startX,$startY,$endX,$endY,$seconds,$tolerance) Then
		If $direction = "right" Then
			$gX += $offset
		ElseIf $direction = "left" Then
			$gX -= $offset
		ElseIf $direction = "up" Then
			$gY -= $offset
		ElseIf $direction = "down" Then
			$gY += $offset
		EndIf
		MouseClick("left",$gX,$gY,$clicks,0)
		Return True
	Else
		Return False
	EndIf
EndFunc

Func ChangeCoords()
	;Changes map coordinates square by square.  Moves left to right then moves down one square and goes left to right again.
	$wait = 2000 ;sleep (milliseconds) at the end of this function
	If $mapX < 585 Then
		$mapX += 30
	Else
		$wait = 2000
		$mapX = 15
		If $mapY < 591 Then			
			$mapY += 17
		EndIf
	EndIf
	MouseClick("left",1181,21,2,0)
	Send($mapX)
	MouseClick("left",1208,20,2,0)
	Send($mapY)
	MouseCLick("left",1242,19,2,0)
	Sleep($wait)
EndFunc

Func FindXCoordsFor($directory,$img)
	If CheckFor($directory,$img) Then
		Return $gX
	Else
		Return 0
	EndIf
EndFunc		

Func FindYCoordsFor($directory,$img)
	If CheckFor($directory,$img) Then
		Return $gY
	Else
		Return 0
	EndIf
EndFunc	

Func SearchForAttackSword()
	;Searches for the sword icon.  Used to make sure SearchForManagogs() actually found something.
	If CheckFor($managogsDir,"attackingsword") Or CheckFor($managogsDir,"attackingsword2") Or CheckFor($managogsDir,"attackingsword3") Then
		Return True
	Else
		Return False
	EndIf
EndFunc
	
Func SearchForManagogs()
	;Iterates through each managog bitmap until it finds one.  Returns false if it doesn't.
	If ClickImage($managogsDir,"bear(black)") Or ClickImage($managogsDir,"bear(black)2") Then
		Return True
	ElseIf ClickImage($managogsDir,"bear(brown)") Then
		Return True
	ElseIf ClickImage($managogsDir,"goblin3") Or ClickImage($managogsDir,"goblin2") Or ClickImage($managogsDir,"goblin") Then
		Return True
	ElseIf ClickImage($managogsDir,"goblin(purple)") Then
		Return True
	ElseIf ClickImage($managogsDir,"griffon") Then
		Return True
	ElseIf ClickImage($managogsDir,"paladin") Or ClickImage($managogsDir,"paladin2") Then
		Return True
	ElseIf ClickImage($managogsDir,"tauren(club)") Or ClickImage($managogsDir,"tauren(club)2") Then
		Return True
	ElseIf ClickImage($managogsDir,"tauren(shield)") Then
		Return True
	ElseIf $collectTreasure Then
		If ClickImage($managogsDir,"treasure") Then
			Return True
		EndIf
	Else
		Return False
	EndIf
EndFunc

Func WaitForAttack()
	;Waits for your character to get to the managog. If the attack button does not appear after 1 min, it will search for and click on the managog again.
	If ClickImage($buttonsDir,"attack",0,0,@DesktopWidth,@DesktopHeight,1,50) Then
		$success = True
		Sleep(2000)
	Else
		$success = False
	EndIf
EndFunc

Func CheckAFKMode()
	;Ensures AFK mode is on for faster farming.
	ClickImage($buttonsDir,"afkmode")
EndFunc

Func CheckWildsView()
	;Returns True if the city button is in view, false if not.
	If CheckFor($buttonsDir,"city") Then
		Return True
	Else
		Return False
	EndIf
EndFunc

Func CheckLowTroops()
	;Ensures troop count doesn't drop too low.
	If ClickImage($buttonsDir,"recruittroops") Then
		Return True
	Else
		Return False
	EndIf
EndFunc

Func RecruitTroops()
	;Recruits more troops
	$troopPortrait = ""
	If $troops = "templar" Then
		$troopPortrait = "templarportrait"
	ElseIf $troops = "warlock" Then
		$troopPortrait = "warlockportrait"
	EndIf
	Do
		ClickImage($buttonsDir,"scrollarrow(down)")
	Until CheckFor($buttonsDir,$troopPortrait)
	$troopRecruitY = $gY
	ClickImage($buttonsDir,"recruit",0,$troopRecruitY,@DesktopWidth,@DesktopHeight,0.5,50)
	ClickImage($buttonsDir,"ok")
	ClickImage($buttonsDir,"x")
EndFunc		

Func RunScript()
	;Main script activated by hotkey
	While 1
		If CheckWildsView() Then
			Do
				If ClickImage($buttonsDir,"attack") Then
					Sleep(500)
				ElseIf CheckLowTroops() Then
					RecruitTroops()
				ElseIf SearchForAttackSword() Then
					Do
						WaitForAttack()
					Until SearchForAttackSword() = False Or ClickImage($buttonsDir,"attack") = True
				ElseIf $managogFound = False And SearchForManagogs() Then
					ToolTip("Managog found!",0,0)
					Sleep(1000)
					$managogFound = True
					Do
						WaitForAttack()
					Until SearchForAttackSword() = False Or ClickImage($buttonsDir,"attack") = True
				ElseIf $managogFound = True And $success = False Then
					$managogFound = False
					ChangeCoords()
				ElseIf $managogFound = False Then
					ChangeCoords()
				EndIf
			Until $success = True
			If $success = True Then
				$managogFound = False
				CheckAFKMode()
			EndIf
		Else
			$success = False
			$managogFound = False
			CheckAFKMode()
		EndIf	
	WEnd
EndFunc		

;===========================================================================================================
;Main

While 1
	ToolTip("Press 'q' to begin...",0,0)
	Sleep(100)
WEnd
This is what I have :)

This is the error I get when I try to run script.

Line 40

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

Error: Subscript used with non-Array variable

Have no idea what's going on :(
06/12/2013 00:04 VVayinsane#69
try this.

Code:
	
Until _ImageSearchArea($string,1,$startX,$startY,$endX,$endY,$gX,$gY,$tolerance)
;Until _ImageSearchArea($string,1,216,180,1723,1002,$gX,$gY,$tolerance)
To

Code:
	
;Until _ImageSearchArea($string,1,$startX,$startY,$endX,$endY,$gX,$gY,$tolerance)
Until _ImageSearchArea($string,1,216,180,1723,1002,$gX,$gY,$tolerance)
06/12/2013 00:15 richardrah#70
Still getting the Line 40 error :(
06/12/2013 00:29 VVayinsane#71
Im not getting that error on my screen at all.. script works well for me. The error code isnt coming from the darudaru, its coming from Imagesearch script.
06/12/2013 00:32 KilleN^#72
Thank you Wayinsane. Im going to give that a try right now, taking images of every monster in swamps. If I get working images I will share.
06/12/2013 00:33 VVayinsane#73
Try and re extract the script. Run darudaru without maken any changes and see if the error pops backup. If not then change the x and y coords like before and run the script again.

error subscript means that a folder or subfolder cannot be found

Did you put the system32 in the right place?

From looking into the script and seeing what it looks for before it goes to the error is the system32 folder. I think that is your issue.
06/12/2013 01:00 richardrah#74
I've hit a treasure chest lol had to copy system32 over to syswow and ran it at x86, it went through all managogs and found a treasure chest then it stayed at finding searchicon, should I use mouse position and fine tune them like you showed us?
06/12/2013 01:45 VVayinsane#75
mouse postion is only for changing map area. You may have to if you want it to change location. Try and see if it will change map location. Make sure no mobs or chest is in the area. See if it will cycle through. If it wont change go a head and make the changes like before. Just the x, y, and searchicon. When it found the chest did the sword come up?

At least we got your first error figured out.