HelpAutoIT syntax

Posts 1628 of 28 · Page 2 of 2
Quote Originally Posted by Zaiakunokami View Post
Code:
Func Skill()
	If $AP=1 	Then
		If $APTimes>2 Then
			ToolTip("SinBotv2.2 will launch the skill spending program after " & $APTimes & " more runs.", 50, 50)
		ElseIf $APTimes=2 Then
			ToolTip("SinBotv2.2 will launch the skill spending program after " & $APTimes-1 & " more run.", 50, 50)
		ElseIf $APTimes=1 Then
			ToolTip("SinBotv2.2 will launch the skill spending program after the current run.", 50, 50)
		EndIf
		Sleep($SkillDelay)
		If $APTimes=0 OR $APTimes<0 Then
			If $SmartAP=0 Then
				ToolTip("SinBotv2.2 cannot be stopped during AP spending process. Please wait until finished.", 50, 60)
				Send("v")
				Send("{ALT DOWN}")
				MouseClick("left", $SkillBoxX, $SkillBoxY, 1) ; Selects All
				Call("SkillSelect")
				MouseClick("left", $XTab2, $SkillBoxY, 1) ; Combat
				Call("SkillSelect")
				MouseClick("left", $XTab3, $SkillBoxY, 1) ; Training
				Call("SkillSelect6")
				MouseClick("left", $XTab4, $SkillBoxY, 1) ; Restoration
				Call("SkillSelect8")
				MouseClick("left", $XTab5, $SkillBoxY, 1) ; Equipment
				Call("SkillSelect8")
				MouseClick("left", $XTab6, $SkillBoxY, 1) ; SP
				Call("SkillSelect6")
				Send("{ALT UP}")
			ElseIf $SmartAP=1 Then
				Send("v")
				Send("{ALT DOWN}")
				MouseClick("left", $SkillBoxX, $SkillBoxY, 1) ; Selects All
				Call("SkillSelect")
			EndIf
			Sleep(500)
			If FileExists ( $IniFile ) Then
				$APTimes=IniRead ( $IniFile, "skill", "APTimes", 40)
			Else
				$APTimes=40
			EndIf
			Sleep($LaunchButtonDelay)
			Call("Launch")
		ElseIf $APTimes>0 Then
			$APTimes=$APTimes-1
			Sleep($LaunchButtonDelay)
			Call("Launch")
		EndIf
	ElseIf $AP=0	Then
		Sleep($LaunchButtonDelay)
		Call ("Launch")
	Else
		MsgBox(0, "SinBotv2.2", "INI File Error. AP value must be 0 or 1.")
		Call("ExitBot")
	EndIf
EndFunc
Is there any way to better optimize this code using For/Next or any other commands?
Doesn't seem like you need any kind of loop for that..

Just keep in mind everyone has a different skill list depending on their level and class and what they've learned or not. Which is why with AutoVin for the custom skill training I made a little setup that just recorded the clicks needed to get to the right skill and recorded the location of it.
Quote Originally Posted by DanK View Post
Doesn't seem like you need any kind of loop for that..

Just keep in mind everyone has a different skill list depending on their level and class and what they've learned or not. Which is why with AutoVin for the custom skill training I made a little setup that just recorded the clicks needed to get to the right skill and recorded the location of it.
I know that everyone has a different list, that's why I have the two different modes coming up in v2.2. Smart and Regular.
With Regular mode it just clicks in every possible spot and then on max. It takes a while, but it'll be guaranteed to eventually fill everything.
Smart mode takes a little set-up. The user has to spend at least 1 AP in each skill they want trained, and have the "Trained Skills Only" tab selected. This mode just clicks on "All" and goes through those skills, filling each of them. Much faster and allows the user to select what skill they want.

I'm not nearly advanced enough to build something that a user can record their clicks, and have the bot remember that. I wouldn't have the first idea of where to start something like that. So I just went with what I knew I could do.

And the looping part comes into play with the "$APTimes" variable. I currently have it on a counter as defined in a .ini file attached with. It has a default of 40 (Max AP for any consistent run is 25, 25*40=1000=Stored AP Cap)

I want it to count down, and show the different system messages at the appropriate time. I know it's a minor thing, but I hate things that say "with 1 times remaining".
Quote Originally Posted by Zaiakunokami View Post
I know that everyone has a different list, that's why I have the two different modes coming up in v2.2. Smart and Regular.
With Regular mode it just clicks in every possible spot and then on max. It takes a while, but it'll be guaranteed to eventually fill everything.
Smart mode takes a little set-up. The user has to spend at least 1 AP in each skill they want trained, and have the "Trained Skills Only" tab selected. This mode just clicks on "All" and goes through those skills, filling each of them. Much faster and allows the user to select what skill they want.

I'm not nearly advanced enough to build something that a user can record their clicks, and have the bot remember that. I wouldn't have the first idea of where to start something like that. So I just went with what I knew I could do.

And the looping part comes into play with the "$APTimes" variable. I currently have it on a counter as defined in a .ini file attached with. It has a default of 40 (Max AP for any consistent run is 25, 25*40=1000=Stored AP Cap)

I want it to count down, and show the different system messages at the appropriate time. I know it's a minor thing, but I hate things that say "with 1 times remaining".
Here is my code for recording the skill positions and clicks it took to get to them in the scrollbar.. This was designed for the old skill list before it was changed with a recent patch.. It obviously won't work just copy/paste but gives you an idea how to do it.


Code:
	$ClicksLabel = 0 ;a label showing the number of clicks on scrollbar
	GuiCtrlSetData($SetupLabel, @LF & @LF & "NOW RECORDING" &@LF&@LF& "Clicks = " & $ClicksLabel)
	_Win($Wwindow)  ;this is a function that has winactivate/waitwinactive vindictus
	$dll = DllOpen("user32.dll")
	Global $SkillClicks = 0  ;this the #of clicks on scrollbar that will get saved to ini
	While 1
	sleep(10)
		While 1
		sleep(10)
			If WinActive($wWindow,"") and _IsPressed("01", $dll) Then ;if left click is pressed
				While _IsPressed("01", $dll)  ;prevents inaccurate counts if left click is held down
					sleep(1)
				Wend
				$SkillClicks += 1
				$ClicksLabel += 1
				GuiCtrlSetData($SetupLabel, @LF & @LF & "NOW RECORDING" &@LF&@LF& "Clicks = " & $ClicksLabel)
				ExitLoop 1 
			EndIf
			If _IsPressed("02", $dll) Then  ;if right click (this stops the recording)
				$Trainpos = MouseGetPos() ;record the position of the skill
				ExitLoop 2 ;we are done recording so exit these loops next the code will save the values to the ini
			EndIf
		Wend
	WEnd
	IniWrite ( "settings.ini", $Sres, "SscrollClick" , $SkillClicks )  ;Sres is my variable for the resolution section in the ini... change to whatever.
	IniWrite ( "settings.ini", $Sres, "TrainX" , $TrainPos[0] )
	IniWrite ( "settings.ini", $Sres, "TrainY" , $TrainPos[1] )
Quote Originally Posted by DanK View Post
Here is my code for recording the skill positions and clicks it took to get to them in the scrollbar.. This was designed for the old skill list before it was changed with a recent patch.. It obviously won't work just copy/paste but gives you an idea how to do it.


Code:
	$ClicksLabel = 0 ;a label showing the number of clicks on scrollbar
	GuiCtrlSetData($SetupLabel, @LF & @LF & "NOW RECORDING" &@LF&@LF& "Clicks = " & $ClicksLabel)
	_Win($Wwindow)  ;this is a function that has winactivate/waitwinactive vindictus
	$dll = DllOpen("user32.dll")
	Global $SkillClicks = 0  ;this the #of clicks on scrollbar that will get saved to ini
	While 1
	sleep(10)
		While 1
		sleep(10)
			If WinActive($wWindow,"") and _IsPressed("01", $dll) Then ;if left click is pressed
				While _IsPressed("01", $dll)  ;prevents inaccurate counts if left click is held down
					sleep(1)
				Wend
				$SkillClicks += 1
				$ClicksLabel += 1
				GuiCtrlSetData($SetupLabel, @LF & @LF & "NOW RECORDING" &@LF&@LF& "Clicks = " & $ClicksLabel)
				ExitLoop 1 
			EndIf
			If _IsPressed("02", $dll) Then  ;if right click (this stops the recording)
				$Trainpos = MouseGetPos() ;record the position of the skill
				ExitLoop 2 ;we are done recording so exit these loops next the code will save the values to the ini
			EndIf
		Wend
	WEnd
	IniWrite ( "settings.ini", $Sres, "SscrollClick" , $SkillClicks )  ;Sres is my variable for the resolution section in the ini... change to whatever.
	IniWrite ( "settings.ini", $Sres, "TrainX" , $TrainPos[0] )
	IniWrite ( "settings.ini", $Sres, "TrainY" , $TrainPos[1] )
I'm going to need to copy all of these codes and study them in detail, and try to write my own. I don't learn well from watching other's work, but from making my own attempts, mistakes, failures and successes.

As expected from you DanK, simple, elegant and functional. Code Monkey indeed. *starts singing about Code Monkeys*
There's another work around for the skills, you could create a representation of each skill (the picture or the text) based on width, height and pixel checksum (or even a chain of pixelcolors) and store it just like how you store coordinates, for instance something like:
Code:
$meditation = "color,width,height,checksum"
With that you can create a function to look in the screen (or a portion of it) for that color as a reference, once it finds it, it makes the checksum, if it doesn't match it keeps looking until you finally have your skill.

The good part is, assuming you already have the representation for the skill and it's visible, you could do something like:
Code:
add_ap($meditation);
The bad part is, the script would probably take a few seconds to find a given skill.

I'm gonna try it and see how it goes, it may be useful for other things as well
Quote Originally Posted by japmsn View Post
There's another work around for the skills, you could create a representation of each skill (the picture or the text) based on width, height and pixel checksum (or even a chain of pixelcolors) and store it just like how you store coordinates, for instance something like:
Code:
$meditation = "color,width,height,checksum"
With that you can create a function to look in the screen (or a portion of it) for that color as a reference, once it finds it, it makes the checksum, if it doesn't match it keeps looking until you finally have your skill.

The good part is, assuming you already have the representation for the skill and it's visible, you could do something like:
Code:
add_ap($meditation);
The bad part is, the script would probably take a few seconds to find a given skill.

I'm gonna try it and see how it goes, it may be useful for other things as well
I hope you can get it right, because anytime that I've ever tried to make a checksum work, it's failed, miserably.
I initially tried doing checksums for the boat launch and error removal parts of the script but they failed or did something screwy about 70% of the time. So I switch to an individual pixel check. And its worked nearly perfect for all but one (who mailed me, I tweaked it, and it now works for them too).

So I'll stick with individual pixels for now. If you get a pixelchecksum working though, I'd love to see how you did it.
Well actually I got it working, I was making a small tool to get the required data now.

Basically this is the script that has the two functions that do all the work, it's not to be opened but rather included:

include_me.au3
Code:
;this would be the file to be included in order to have
;available the following 2 functions,
;*************************************
;img_to_data(left, top, right, bottom)
;converts a box on the screen to data that can be
;compared later on by the other function
;return/example:
;=> color, width, height, checksum
;=> 2302746,32,33,273114417
;*************************************
;search_img(data)
;search the screen for a box of pixels with same checksum
;returns:
;=> false ;if no image found
;=> [$x, $y] ;an array containing the center of the image

Dim $_pos[2]

Func img_to_data($x0, $y0, $x1, $y1)
	$_height = $y1 - $y0
	$_width = $x1 - $x0
	$_checksum = PixelChecksum ( $x0, $y0, $x1, $y1 )
	$_color = PixelGetColor($x0, $y0)
	$_data = $_color & "," & $_width & "," & $_height & "," & $_checksum
	return $_data
EndFunc

Func search_img($data)
	Tooltip("Searching...", 10, 10)
	$_array = StringSplit($data, ",")
	$_color = $_array[1]
	$_width = $_array[2]
	$_height = $_array[3]
	$_checksum = $_array[4]
	;It can only look so far
	$_max_width = @desktopWidth - $_width
	$_max_height = @desktopHeight - $_height
	;Look the lazy way (pixel by pixel), perhaps could use PixelSearch
	For $x = 0 To $_max_width
		For $y = 0 To $_max_height
			If $_color = PixelGetColor($x,$y) Then
				$_data = img_to_data($x, $x + $_width, $y, $y + $_height)
				$_array = StringSplit($_data, ",")
				If $_array[4] = $_checksum Then
					;I'm adding $_width/2 and $_height/2 to return the middle
					$_pos[0] = $x + $_width/2 
					$_pos[1] = $y + $_height/2
					Tooltip("")
					return $_pos
				EndIf
			EndIf		
		Next
	Next
	Tooltip("")
	return false
EndFunc
And the following is the tool to get the data required, basically you place your mouse over the top-left corner of whatever you're trying to read and press Numpad1, then place the mouse over the bottom-right corner and press Numpad2, this will read the data required within those two coordinates and copy it to your clipboard for further use, you can even see if it's working by pressing the HOME key.

tool.au3
Code:
#include "include_me.au3"

HotKeySet("{Numpad1}","pick_min")
HotKeySet("{Numpad2}","pick_max")
HotKeySet("{HOME}","test")
HotKeySet("{END}","close")

Dim $_x0,$_x1,$_y0,$_y1,$_img

Func info($txt)
	Tooltip($txt, 10, 10)
EndFunc

info("Use Numpad1 to pick the top-left position of an object")

While 1
WEnd

Func pick_min()
	$pos = MouseGetPos()
	$_x0 = $pos[0]
	$_y0 = $pos[1]
	info("Use Numpad2 to pick the bottom-right position of an object")
EndFunc

Func pick_max()
	$pos = MouseGetPos()
	$_x1 = $pos[0]
	$_y1 = $pos[1]
	read_from_user()
EndFunc

Func read_from_user()
	$_img = img_to_data($_x0, $_x1, $_y0, $_y1)
	ClipPut( $_img )
	info("Use HOME to test and find the object")
	msgbox(48, "Alert", "The following data has been added to the clipboard" & @LF & $_img)
EndFunc

Func test()
	$res = search_img($_img)
	If isArray($res) Then
		$x = $res[0]
		$y = $res[1]
		mousemove($x, $y)
		msgbox(48, "Alert", "Object found at (" & $x & "," & $y & ")")
	Else
		msgbox(48, "Alert", "Object not found")
	EndIf
EndFunc

Func Close()                                                              
  Exit                                                             
EndFunc
And finally this is how you'd actually use it:

example.au3
Code:
#include "include_me.au3"

HotKeySet("{HOME}","test_me")
HotKeySet("{END}","close")

;this is one was taken for my res for the skill meditation
;so actually replace for one you get using the tool
$sample_skill = "2302746,32,33,273114417"

While 1
Wend

Func test_me()
	add_ap($sample_skill)
EndFunc

;this is a way to use the search_img() function
Func add_ap($skill)
	$res = search_img($sample_skill)
	If isArray($res) Then
		$x = $res[0]
		$y = $res[1]
		;replace the following with click and add offset if needed depending
		;on how the data was taken, (x,y) corresponds to the middle of the object
		mousemove($x, $y) 
		msgbox(48, "Alert", "Object found at (" & $x & "," & $y & ")")
	Else
		msgbox(48, "Alert", "Object not found")
	EndIf
EndFunc

Func Close()                                                              
  Exit                                                             
EndFunc
And I'm surprised how much you can copy on a single post lol
Wow. *wipes eyes* I went a little fuzzy reading that, but I suppose I see how that all works together.

My script is nowhere near that fancy. DanK knows, he's seen it.
What I'm realizing is that I need to have a different methodology for determining the boat launch pixelcheck.

Since the bot requires you to start it while on that boat, should I insert some sort of immediate pixel check to grab the number for future usage?

Something along the lines of:
Code:
	WinWaitActive("Vindictus", "")
	tooltip("SinBotv2.2 has started. Pause/Break to Pause and End to exit.", 50, 50)
	$BCReload=0
	Send("{ALT DOWN}")
	Sleep(500)
	MouseClick ("left", $LaunchX, $LaunchY, 1)
        $PixelCheck=PixelGetColor($PixelCheckBoatX, $PixelCheckBoatY)
	Sleep(500)
	MouseMove($CenterX, $CenterY, 1)
	Send("{ALT UP}")
	Send($Reach)
	Sleep($FirstMapDelay)
	Call("SkipMap")
And then in the future for the error checker functionality, just have it reference the $PixelCheck variable?

Or will calling the pixelgetcolor function at the start of each and every boat launch be a bad idea.

What I've done now is create a range of colors that seems to work for most, but not all.
Quote Originally Posted by Zaiakunokami View Post
What I'm realizing is that I need to have a different methodology for determining the boat launch pixelcheck.

Since the bot requires you to start it while on that boat, should I insert some sort of immediate pixel check to grab the number for future usage?

Something along the lines of:
Code:
	WinWaitActive("Vindictus", "")
	tooltip("SinBotv2.2 has started. Pause/Break to Pause and End to exit.", 50, 50)
	$BCReload=0
	Send("{ALT DOWN}")
	Sleep(500)
	MouseClick ("left", $LaunchX, $LaunchY, 1)
        $PixelCheck=PixelGetColor($PixelCheckBoatX, $PixelCheckBoatY)
	Sleep(500)
	MouseMove($CenterX, $CenterY, 1)
	Send("{ALT UP}")
	Send($Reach)
	Sleep($FirstMapDelay)
	Call("SkipMap")
And then in the future for the error checker functionality, just have it reference the $PixelCheck variable?

Or will calling the pixelgetcolor function at the start of each and every boat launch be a bad idea.

What I've done now is create a range of colors that seems to work for most, but not all.
You cant detect whether you are in town or on a boat by using the color of the avatar icon on the bottom right of your screen.. If in town it will be lit up, if on a boat it will be greyed out.
Quote Originally Posted by DanK View Post
You cant detect whether you are in town or on a boat by using the color of the avatar icon on the bottom right of your screen.. If in town it will be lit up, if on a boat it will be greyed out.
Again. I should have thought of that. I will be using this!
Quote Originally Posted by Zaiakunokami View Post
Again. I should have thought of that. I will be using this!
LOl I just noticed I said "Can't" when I meant "Can", you understood me anyways though.
Quote Originally Posted by DanK View Post
LOl I just noticed I said "Can't" when I meant "Can", you understood me anyways though.
Well it was pretty obvious what you meant. And thanks for the tip. The bot now can recognize much faster if it is in town when it should be on a boat instead.
Posts 1628 of 28 · Page 2 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?