Little help with pixel search

05/18/2014 00:25 mlukac89#1
I have this piece of code, problem is when it kill mob so no more color there, he waits untill bar from mob hp dissapear from screen then he send tab and aim other mob then attack. But it need to work like, send tab until you find color (that works), send keys to kill mob (that works), send tab again after mob is dead without waiting for 5-6 seconds (that dont works). And it send keys all time, when he kill mob or search for him

Code:
Global $Run = False

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

If $pid Then
	If WinExists($win) Then
		WinActivate($win)
		Sleep(1000)
		WinMove($win, "", 0, 0, "1024", "768", 2)
		Sleep(3000)
	EndIf
Else
	MsgBox(48, "Error", "Game is not running")
	Exit
EndIf

While 1
	Sleep(200)
WEnd

Func _Attack()
	$Run = NOT $Run
	While $Run
		$find = PixelSearch(425, 20, 593, 29, $color)
		If IsArray($find) Then
			ControlSend($win, "", "", "{3}")
			Sleep(2200)
			ControlSend($win, "", "", "{4}")
			Sleep(2200)
			ControlSend($win, "", "", "{5}")
			Sleep(2500)
		Else
			ControlSend($win, "", "", "{TAB}")
			Sleep(300)
		EndIf
	WEnd
EndFunc
and i tried like this too and its same

Code:
Func _Attack()
	$Run = NOT $Run
	While $Run
		$find = PixelSearch(425, 20, 593, 29, $color)
		If @error Then
			ControlSend($win, "", "", "{TAB}")
			Sleep(300)
		Else
			ControlSend($win, "", "", "{3}")
			Sleep(2200)
			ControlSend($win, "", "", "{4}")
			Sleep(2200)
			ControlSend($win, "", "", "{5}")
			Sleep(2500)
		EndIf
	WEnd
EndFunc
05/18/2014 09:41 YatoDev#2
the loop cant get true in your code...
and $Run = Not $Run -> $Run = False
05/18/2014 12:03 mlukac89#3
Now script do nothing

Code:
Func _Attack()
	$Run = False
	While $Run = True
		$find = PixelSearch(425, 20, 593, 29, $color)
		If IsArray($find) Then
			ControlSend($win, "", "", "{3}")
			Sleep(2200)
			ControlSend($win, "", "", "{4}")
			Sleep(2200)
			ControlSend($win, "", "", "{5}")
			Sleep(2500)
		Else
			ControlSend($win, "", "", "{TAB}")
			Sleep(300)
		EndIf
	WEnd
EndFunc
Ok problem solved, i added pause in separate function and added tab to send first, now works fine

Code:
Func _Attack()
	While 1
		ControlSend($win, "", "", "{TAB}")
		Sleep(300)
		$find = PixelSearch(425, 20, 593, 29, $color)
		If IsArray($find) Then
			ControlSend($win, "", "", "{3}")
			Sleep(2200)
			ControlSend($win, "", "", "{4}")
			Sleep(2200)
			ControlSend($win, "", "", "{5}")
			Sleep(2500)
		Else
			ControlSend($win, "", "", "{TAB}")
			Sleep(300)
		EndIf
	WEnd
EndFunc

Func TogglePause()
    $fPaused = Not $fPaused
    While $fPaused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc
And Flutter why not $run = NOT $run look on this link [Only registered and activated users can see links. Click Here To Register...]