Problem with autoit script

01/31/2014 14:37 LiveLong23#1
Hi all im new on this forum.

First of all i got problem with this script, im making a bot for 1 game and bot will must do multi-tasks but i read that this can be done in autoit. My problem is when i want to use multiple tasks script become crazy :)
I made few files, main (main bot and gui), buff(for buffing), cam(camera rotation), pick(for pick items), and now i need to put all that to work together without problems.

here is piece of code that i have problem with

Code:
; main function for start boting when pressed F9
Func _toggleStart()

	; if process exists then start
	If $proc = True Then

		$run = Not $run ; pause script

		; main loop
		While $run
			_checkMob()
			
			If GUICtrlRead($cameraRoation) = $GUI_CHECKED Then
				#include <cam.au3>
			EndIf
			If GUICtrlRead($pickItems) = $GUI_CHECKED Then
				#include <pick.au3>
			EndIf
			#include <buffs.au3>
			
		WEnd

	EndIf

EndFunc

Func _checkMob()

	$mob = PixelSearch(415, 44, 596, 54, 0xF84B49)

	If IsArray($mob) And Not @error Then
		ControlSend($win, "", "", "{3}")
		Sleep(200)
	Else
		ControlSend($win, "", "", "{TAB}")
		Sleep(200)
	EndIf

EndFunc
and here is buff script

Code:
Global $win, $Input1, $Input2, $Input3, $Input4, $Input21, $Input22, $Input23, $Input24

		Sleep(2000)
		Send("{SHIFTDOWN}")
		Sleep(100)
		ControlSend($win, "", "", "{3}", 0)
		Sleep(GUICtrlRead($Input1))
		ControlSend($win, "", "", "{4}", 0)
		Sleep(GUICtrlRead($Input2))
		ControlSend($win, "", "", "{5}", 0)
		Sleep(GUICtrlRead($Input3))
		ControlSend($win, "", "", "{6}", 0)
		Sleep(GUICtrlRead($Input4))
		Send("{SHIFTUP}")
		Sleep(100)

		$Input1 = TimerInit()
		$Input2 = TimerInit()
		$Input3 = TimerInit()
		$Input4 = TimerInit()

		If TimerDiff($Input1) > GUICtrlRead($Input21) Then
			Send("{SHIFTDOWN}")
			Sleep(100)
			ControlSend($win, "", "", "{3}", 0)
			Sleep(GUICtrlRead($Input1))
			Send("{SHIFTUP}")
			Sleep(100)
			$Input1 = TimerInit()
		EndIf
		If TimerDiff($Input2) > GUICtrlRead($Input22) Then
			Send("{SHIFTDOWN}")
			Sleep(100)
			ControlSend($win, "", "", "{4}", 0)
			Sleep(GUICtrlRead($Input2))
			Send("{SHIFTUP}")
			Sleep(100)
			$Input2 = TimerInit()
		EndIf
		If TimerDiff($Input3) > GUICtrlRead($Input23) Then
			Send("{SHIFTDOWN}")
			Sleep(100)
			ControlSend($win, "", "", "{5}", 0)
			Sleep(GUICtrlRead($Input3))
			Send("{SHIFTUP}")
			Sleep(100)
			$Input3 = TimerInit()
		EndIf
		If TimerDiff($Input4) > GUICtrlRead($Input24) Then
			Send("{SHIFTDOWN}")
			Sleep(100)
			ControlSend($win, "", "", "{6}", 0)
			Sleep(GUICtrlRead($Input4))
			Send("{SHIFTUP}")
			Sleep(100)
			$Input4 = TimerInit()
		EndIf
So problem is next, when i press F9 it start to aim and kill mobs, cam rotation works fine but it buff all time, and what i need is when i press F9 script start, buff once, start attack, pause attack when buff are ready too use again, use buff, start attack again. If you dont understand something like this,

F9 = bot start
1. buff (when done)
2. attack
3. when buff ready again (pause attack)
4. buff again
5. start attack
01/31/2014 14:48 alpines#2
You could try to CreateThreads but that's unstable because it's crashing a lot.
In AutoIt multiprocessing is one of the ways to get an application "multithreaded" but it's not as nice as for example in C#.
01/31/2014 14:51 LiveLong23#3
I have trie to made something in c# and c++ looks so complicated, this is much more easier but as i see isnt so good :(
02/01/2014 04:25 elmarcia#4
Try initializing the timer init outside the while loop.
Like this:
Code:
$Input1 = TimerInit()

While 1

If (TimerDiff($Input1) > 3000) Then
	MsgBox(0,"buffTime","Sending keyStrokes")
$Input1 = TimerInit()
EndIf
$dif = TimerDiff($Input1)
ToolTip($dif,0,0)
WEnd
02/01/2014 09:12 alpines#5
You can use ControlSend in AutoItX.dll do use that in C#. It's not that hard.
02/01/2014 15:47 LiveLong23#6
Quote:
Originally Posted by elmarcia View Post
Try initializing the timer init outside the while loop.
Like this:
Code:
$Input1 = TimerInit()

While 1

If (TimerDiff($Input1) > 3000) Then
	MsgBox(0,"buffTime","Sending keyStrokes")
$Input1 = TimerInit()
EndIf
$dif = TimerDiff($Input1)
ToolTip($dif,0,0)
WEnd
This still dont works now it switch bar every few seconds like before :( , but problem isnt in buff script it works fine when i run it alone
buff.au3 it buff char, wait for timer to run out and buff again no problems
like this
Code:
Global $win, $Input1, $Input2, $Input3, $Input4, $Input21, $Input22, $Input23, $Input24

While 1
		Sleep(2000)
		Send("{SHIFTDOWN}")
		Sleep(100)
		ControlSend($win, "", "", "{3}", 0)
		Sleep(GUICtrlRead($Input1))
		ControlSend($win, "", "", "{4}", 0)
		Sleep(GUICtrlRead($Input2))
		ControlSend($win, "", "", "{5}", 0)
		Sleep(GUICtrlRead($Input3))
		ControlSend($win, "", "", "{6}", 0)
		Sleep(GUICtrlRead($Input4))
		Send("{SHIFTUP}")
		Sleep(100)

		$Input1 = TimerInit()
		$Input2 = TimerInit()
		$Input3 = TimerInit()
		$Input4 = TimerInit()

		If TimerDiff($Input1) > GUICtrlRead($Input21) Then
			Send("{SHIFTDOWN}")
			Sleep(100)
			ControlSend($win, "", "", "{3}", 0)
			Sleep(GUICtrlRead($Input1))
			Send("{SHIFTUP}")
			Sleep(100)
			$Input1 = TimerInit()
		EndIf
		If TimerDiff($Input2) > GUICtrlRead($Input22) Then
			Send("{SHIFTDOWN}")
			Sleep(100)
			ControlSend($win, "", "", "{4}", 0)
			Sleep(GUICtrlRead($Input2))
			Send("{SHIFTUP}")
			Sleep(100)
			$Input2 = TimerInit()
		EndIf
		If TimerDiff($Input3) > GUICtrlRead($Input23) Then
			Send("{SHIFTDOWN}")
			Sleep(100)
			ControlSend($win, "", "", "{5}", 0)
			Sleep(GUICtrlRead($Input3))
			Send("{SHIFTUP}")
			Sleep(100)
			$Input3 = TimerInit()
		EndIf
		If TimerDiff($Input4) > GUICtrlRead($Input24) Then
			Send("{SHIFTDOWN}")
			Sleep(100)
			ControlSend($win, "", "", "{6}", 0)
			Sleep(GUICtrlRead($Input4))
			Send("{SHIFTUP}")
			Sleep(100)
			$Input4 = TimerInit()
		EndIf
WEnd
only problem is when it need to do it while attack
07/20/2017 01:51 VitorCornelius#7
No clue if the owner still use the site or not, but a bit advise:
U have to manage ur code better, cause this is messy.
U should store the input valuses in variable, instead of pulling them every time from the GUI. If u did it cause u wana change the values anytime u want while the script running, then u can still do it easy on this way. It will be pretty much the same, but it help u make ur code become shorter and easyer to read and understand, when u have only this:
$delay1 = guictrlread($input1)

Sleep($delay1)
instead of this:
Sleep(GUICtrlRead($Input1))

U will realise the different when u write a long row.

Other thing, do not put the "include" stuff in an infinit loop or in any loop. Those stuffs have to called once, not every single milisecond.

The reason why it is not realy work, from first look is, cause u put ur buffing stuff in an infinite loop and every time reseting the timer when the loop get reseted in every few second. Every few second cause u put some sleep at the end of the while loop.
Still the main problem is the organisation, what the script do and when it is doing that. Placeing the stuffs on wrong place, make bugs or errors.

If u realy want multitask, better to use C, C#, or C++
But there is a function in AutoIt to run 2 different function next to each other at "same" time. Actualy not running at same time. While 1 running the other one is paused. What mean, the code is switching between the 2 function pretty fast.
Before u start codeing, better to write down what u want to make, and even make a diagram for it, just to be clear and see clear how it will work.

P.S.:
Sry for necro post, but maybe it will help for other ppls when they read it in a future, to do not fall into the same mistake.
07/20/2017 17:56 rachefaust#8
please dont push old threads ... this is from 2014 he can be a autoit pro now or learned c#
07/24/2017 12:26 Lawliet#9
#closed
las post 01.02.2014, 15:47