[Release] Thin thread making bot(Autoit)

05/22/2012 13:08 SKAKERA#1
Had this around for a while,and seeing nothing similar being posted(save for cobweb gathering ones) thought I'd put it here in case anyone has any kind of use for this.It did rely on mod_potato's autopick for gathering cobwebs from a spider-farm so commented that part for obvious reasons.

Might need more crippling on some parts,I won't bother testing it as I don't play mabi anymore(testing it crippled I mean,it worked fine otherwise)

Images needed etc on comments.

Code:
#Include <Imagesearch.au3>
#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
MsgBox (0,"Startbox","Push ok to start")
HotKeySet("{ESC}", "Terminate")

WinActivate("Mabinogi")
WinActive("Mabinogi")


Global $inputweavingbutton,$weavingbutton

;$fullinv=0

Popup()
Sleep (2000)

;Commenting this out cause it relied on potato's auto pick up feature.
;Do ;This starts gathering cobwebs,make sure you are at the spider farm without autopick
;	GatherCobwebs()
;Until $fullinv=1

While 1 ;Main loop of weaving,gathering,blabla
	While $fullinv=1 
	GoinHS()
	
	Weave()
	Sleep(1000)
	
	OutofHS()
	
	Popupwait()
	
	;If $fullinv=0 Then
	;	Do
	;		GatherCobwebs()
	;	Until $fullinv=1
	;EndIf
	WEnd
WEnd

;Func GatherCobwebs() ;Function that gathers cobwebs,obviously needs a working mod_potato for autopick
;	Send ("{Enter}")
;	Send ("/pick")
;	Send ("{Enter}")
;	Sleep(30000)
;	CheckINV()
;	If $fullinv=1 Then
;		Send ("{Enter}")
;		Send ("/pick")
;		Send ("{Enter}")
;	EndIf
;	Sleep(1000)
;EndFunc

Func GoinHS()
	Send ("{U}")
	$goin=_Imagesearch("Goin.jpg",$x,$y,80) ;Image is supposed to be the homestead entry button
	MouseClick("left",$x,$y,1,2)
EndFunc

Func Popup() 
	GUICreate("Thin Thread bot",328, 128, 202, 178)
	$inputweavebutton=GUICtrlCreateInput("",184, 32, 25, 21,$ES_UPPERCASE)
	GUICtrlSetLimit(-1, 2)
	$Label1 = GUICtrlCreateLabel("Weaving Skill Button", 120, 32, 64, 40)
	$Button1 = GUICtrlCreateButton("Start!", 128, 96, 75, 25, 0)
	GUISetState(@SW_SHOW)
	Do
		$msg = GUIGetMsg()
		
		If $msg = $button1 Then
			$weavingbutton=Number(GuiCtrlRead($inputweavingbutton))
			
			$msg = $GUI_EVENT_CLOSE
		EndIf
	Until $msg = $GUI_EVENT_CLOSE
	GUIDelete()
EndFunc

Func Popupwait()
	GuiCreate("Waiting",100,150,100,100)
	$Button1=GuiCtrlCreateButton("Start Again!",50,100,50,50,0)
	GUISetState(@SW_SHOW)
	Do
		$msg=GUIGetMsg()
		
		If $msg=$Button1 Then
			$msg=$GUI_EVENT_CLOSE
		EndIf
	Until $msg=$GUI_EVENT_CLOSE
	GuiDelete()
EndFunc

Func OutofHS()
	Send ("{U}")
	$goout=_Imgesearch("goout.jpg",$x,$y,80) ;Suppoosed to be the button that gets you out of homestead.
	MouseClick("left",$x,$y,1,2)
EndFunc

Func Weave()
	Send("{$weavingbutton}")
	$count=0
	$result1 = _ImageSearch("Cobweb.bmp",1,$x1,$y1,100) ;Stack of 5 cobwebs in inventory slot.
	$result2 = _ImageSearch("Slot.bmp",1,$x2,$y2,100) ;Empty slot at production window.
	While $result1=1
		Do
			$result1 = _ImageSearch("Cobweb.bmp",1,$x1,$y1,100)
			$result2 = _ImageSearch("Slot.bmp",1,$x2,$y2,100)
			If $result1=1 and $result2=1 Then
				MouseMove($x1,$y1,1)
				MouseClick("left",$x1,$y1,1,1)
				Sleep(100)
				MouseMove($x2,$y2,1)
				MouseClick("left",$x2,$y2,1,1)
				Sleep(100)
				$count=$count+1
			EndIf
		Until $count=10
		If $count=10 Then
			$button= _Imagesearch("start.jpg",1,$x,$y,100) ;Start button of production window.
			MouseClick ("left",$x,$y,1,1)
		EndIf
		Send("{$weavingbutton}")
		$result1= _ImageSearch("Cobweb.bmp",1,$x1,$y1,100)
		$result2 = _ImageSearch("Slot.bmp",1,$x2,$y2,100)
		$count=0
	WEnd
	If $result1=0 Then
		$result3=_Imagesearch("cancel.jpg",1,$x,$y,100) ;Cancel button on production window.
		Mouseclick ("left",$x,$y,1,1)
		;$fullinv=0
	EndIf
EndFunc

;Func CheckINV()
;	$result=_Imagesearch("emptyinvslot.jpg",1,$x,$y,90) ;Empty inventory slot image.
;	If $result=0 Then
;		$fullinv=1
;	EndIf
;EndFunc
05/22/2012 21:29 Balthamel#2
I made this one last week, it gathers cobwebs from a spider farm and then goes to homestead and uses your spinning wheel, it stops when it sees a full thin thread bag.

Code:

HotKeySet("{END}","Exitscript")
OnAutoItExitRegister("Exitscript")
Global $a[2], $b[2]
Local $i, $j
Local $findImage, $resultPosition, $tolerance
Local $Point[2]
;$x and $y used as placeholders only, do not use for actual variables
Local $x,$y
Global $Winpos[4]
$Winpos=WinGetPos("Mabinogi")


;BODY START

Sleep(2000)


While 1

	;Fill inv with cobwebs
	Send("{ALTDOWN}")
	Sleep(200)
	While ImageSearch(".\InvSlot.bmp",1,$a[0],$a[1],5)=1
		Sleep(100)
		Do
		Until ImageSearch(".\Cobweb1.bmp",1,$a[0],$a[1],60)=1
		Sleep(200)
		MouseMove($a[0],$a[1],2)
		Sleep(100)
		MouseClick("Left")
		Sleep(500)
	WEnd
	Send("{ALTUP}")
	Sleep(200)

	;Go to Homestead

	If ImageSearch(".\Home1.bmp",1,$a[0],$a[1],5)=0 Then Exit 5
	Sleep(200)
	MouseMove($a[0],$a[1],2)
	Sleep(100)
	MouseClick("Left")
	Sleep(600)
	If ImageSearch(".\Home2.bmp",1,$a[0],$a[1],5)=0 Then Exit 6
	Sleep(200)
	MouseMove($a[0],$a[1],2)
	Sleep(100)
	MouseClick("Left")
	Sleep(5000)


	;Prepare for weaving, change to bare hands
	Do
		Send("{TAB}")
		Sleep(1000)
	Until ImageSearch(".\Tab1.bmp",1,$a[0],$a[1],5)=1

	;Use the transformation
	Send("{F10}")
	Sleep(3000)

	;Use the spinning wheel
	Do
		Send("{-}")
		Sleep(1000)
		$j=Weav1()
		Sleep(300)
		If ImageSearch(".\Start.bmp",1,$a[0],$a[1],5)=0 then Exit 4
		Sleep(200)
		MouseMove($a[0],$a[1],2)
		Sleep(100)
		MouseClick("Left")
		Sleep(10000)
		If $j=1 Then
			If ImageSearch(".\Cobweb2.bmp",1,$a[0],$a[1],5)=0 Then $j=2
		EndIf
	Until $j=2

	;When 100 or more thread is produced stop.
	If ImageSearch(".\ThinThread.bmp",1,$a[0],$a[1],5)=1 then Exit 1

	;Prepare for Gathering, change to bow
	Do
		Send("{TAB}")
		Sleep(1000)
	Until ImageSearch(".\Tab2.bmp",1,$a[0],$a[1],5)=1

	;Leave Homestead

	If ImageSearch(".\Exit.bmp",1,$a[0],$a[1],5)=0 Then Exit 7
	Sleep(200)
	MouseMove($a[0],$a[1],2)
	Sleep(100)
	MouseClick("Left")
	Sleep(600)
	If ImageSearch(".\Exit2.bmp",1,$a[0],$a[1],5)=0 Then Exit 8
	Sleep(200)
	MouseMove($a[0],$a[1],2)
	Sleep(100)
	MouseClick("Left")
	Sleep(15000)
WEnd
;MsgBox(0,"","")

;BODY END



;Fill the weaving window with cobwebs(5 stack)

Func Weav1()
	;Loop till full wheel
	Do
		;Locate cobweb
		$i=0
		Do

			;If all cobweb is used, break loop
			$i+=1
			If $i=10 then Return 2
		Until ImageSearch(".\Cobweb2.bmp",1,$a[0],$a[1],5)=1
		;Locate empty slot
		$i=0
		Do

			;If it cannot be found then maybe spinning wheel is not active
			$i+=1
			If $i=10 Then
				Send("{-}")
				Sleep(500)
				EndIf
			;perhaps no? okay something is wrong, KILL IT KILL IT NOW!
			If $i=20 Then Exit 9
		Until ImageSearch(".\Empty.bmp",1,$b[0],$b[1],5)=1

		;Move the web and verify
		Do
			Sleep(200)
			MouseMove($a[0],$a[1],2)
			Sleep(100)
			MouseClick("Left")
			Sleep(600)
			MouseMove($b[0],$b[1],2)
			Sleep(600)
			MouseClick("Left")
			Sleep(1300)
		Until ImageSearchLocal(".\Cobweb3.bmp",$a,5)=1

	Until ImageSearch(".\Empty.bmp",1,$x,$y,5)=0

	Return 1
EndFunc






;Imagesearch for .png in the entire region defined by winpos.

Func ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y, $tolerance)
	Local $result

	;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
	if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
	$result = DllCall(".\ImageSearchDLL.dll","str","ImageSearch","int",$Winpos[0],"int",$Winpos[1],"int",$Winpos[2],"int",$Winpos[3],"str",$findImage)

	; If error exit
	If UBound($result)=0 then Return 0
    if $result[0]="0" then Return 0

	; Otherwise get the x,y location of the match and the size of the image to
	; compute the centre of search
	$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

;A VERY local image search to return only success or fail
Func ImageSearchLocal($findImage, $Point, $tolerance)
	Local $result

	;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
	if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
	$result = DllCall(".\ImageSearchDLL.dll","str","ImageSearch","int",$Point[0]-12,"int",$Point[1]-12,"int",$Point[0]+12,"int",$Point[1]+12,"str",$findImage)

	; If error exit
	If UBound($result)=0 then Return 0
	if $result[0]="0" then Return 0

	; Otherwise get the x,y location of the match and the size of the image to
	; compute the centre of search
	;$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 Exitscript()
	Send("{ALTUP}")
	Exit
EndFunc