Problem with timers,array for buff script

01/07/2015 13:16 LiveLong23#1
Hi i have problem with this script for buffing. I want it when i press F2 to fire buffs ( send keys ) and then put timers "on" for next buffing. So to do like this :

- run script
- script do nothing untill i press F2
- when i press F2 send keys ( cast time is Sleep() )
- put timers "on" and when buff cooldown time ends send only that key where timer is reached cooldown time and put timer "on" again

F2 pause/start script

EDIT :

i correct some of code and now it works, so when i press F2 it send keys but wont send again when cooldown time reach time given in array

Code:
Opt("SendKeyDelay", 5) ;5 milliseconds

HotKeySet("{F2}", "_Start")

Global $Run
Global $keys[7] = [3, 4, 5, 6, 7, 8, 9] ; keys
Global $cast[7] = [2000, 2000, 2000, 2000, 2000, 2000, 2000] ; cast
Global $cooldown[7] = [140000, 100000, 440000, 495000, 480000, 360000, 360000] ; cooldown

While 1
	Sleep(100)
WEnd

Func _Start()
	$Run = NOT $Run
	While $Run
		For $i=0 To UBound($keys)-1
			If TimerDiff($cast[$i]) > $cooldown[$i] Then
				Send($keys[$i])
				$cooldown[$i]=TimerInit()
				Sleep($cast[$i])
			EndIf
		Next
	WEnd
EndFunc
Thanks in advance
01/07/2015 15:31 Moneypulation#2
First of all, if all your cast times are 2000 (ms), you don't need an array of it.

TimerDiff() expects a TimerInit() handle but you give it a plain number. I don't really get the line
Code:
If TimerDiff($cast[$i]) > $cooldown[$i] Then
Maybe you could comment a bit on it?
01/07/2015 20:15 lolkop#3
You might try something like this:
Code:
HotKeySet("{F2}", "GO")
Dim $run, $action, $castTimer, $array[7][3] = [[3,140],[4,100],[5,440],[6,495],[7,480],[8,360],[9,360]] ; key, cd, cd-timer
While Sleep(1)
	If $run And TimerDiff($castTimer)>=2000 And TimerDiff($array[$action][2])>=$array[$action][1]*1000 Then
		ConsoleWrite("Send("&$array[$action][0]&")"&@CRLF)
		$array[$action][2] = TimerInit()
		$castTimer=TimerInit()
		$action+=1
	EndIf
	If $action>=2UBound($array) Then $action=0
WEnd

Func GO()
	$run = Not $run
EndFunc
01/07/2015 20:38 LiveLong23#4
Quote:
Originally Posted by lolkop View Post
You might try something like this:
Code:
HotKeySet("{F2}", "GO")
Dim $run, $action, $castTimer, $array[7][3] = [[3,140],[4,100],[5,440],[6,495],[7,480],[8,360],[9,360]] ; key, cd, cd-timer
While Sleep(1)
	If $run And TimerDiff($castTimer)>=2000 And TimerDiff($array[$action][2])>=$array[$action][1]*1000 Then
		ConsoleWrite("Send("&$array[$action][0]&")"&@CRLF)
		$array[$action][2] = TimerInit()
		$castTimer=TimerInit()
		$action+=1
	EndIf
	If $action>=2UBound($array) Then $action=0
WEnd

Func GO()
	$run = Not $run
EndFunc
This works fine but not good as it shoul be look on this pic [Only registered and activated users can see links. Click Here To Register...]

He cast 3456789 then when timer run out compare it it should cast then like 4389576 because of cooldown time.

And this is not all the same its just for test because i will make gui for it so it will read from it
Global $cast[7] = [2000, 2100, 1800, 2000, 2000, 2000, 2000]

look exaple how will it look like on pic [Only registered and activated users can see links. Click Here To Register...]
01/07/2015 22:40 lolkop#5
Quote:
Originally Posted by LiveLong23 View Post
This works fine but not good as it shoul be look on this pic [Only registered and activated users can see links. Click Here To Register...]

He cast 3456789 then when timer run out compare it it should cast then like 4389576 because of cooldown time.

And this is not all the same its just for test because i will make gui for it so it will read from it
Global $cast[7] = [2000, 2100, 1800, 2000, 2000, 2000, 2000]

look exaple how will it look like on pic [Only registered and activated users can see links. Click Here To Register...]
That's even more easy... I thought you wanted it to use the numbers in exactly the same order all the time...

Replacing the ordered actions by a simple for loop should do the trick =)

Code:
HotKeySet("{F2}", "GO")
Dim $run, $castTimer, $array[7][3] = [[3,140],[4,100],[5,440],[6,495],[7,480],[8,360],[9,360]] ; key, cd, cd-timer
While Sleep(1)
	For $i=0 To UBound($array)-1
		If $run And TimerDiff($castTimer)>=2000 And TimerDiff($array[$i][2])>=$array[$i][1]*1000 Then
			ConsoleWrite("Send("&$array[$i][0]&")"&@CRLF)
			$array[$i][2] = TimerInit()
			$castTimer=TimerInit()
		EndIf
	Next
WEnd

Func GO()
	$run = Not $run
EndFunc
Edit:
To add variable delays betweens each cast, you could simply add 2 more dimensions to the array :P (delay and timer)
01/07/2015 22:53 LiveLong23#6
Im quite new to Autoit and i got confused with timers and arrays im doing this all day long :(

But now it works like a charm, thanks a lot.