Autoit multiple If endif question

08/25/2014 20:10 klikata#1
Hello!
Here I'm again.
I'm reading help files, but it is my "English" or it is just a bit too complcated for now, but - here is my script -

HTML Code:
HotKeySet("{Del}", "TooglePause")
Global $Paused
Opt('PixelCoordMode', 0)
Global $handle = WinGetHandle("Lineage*II * ", "")

While 1
WEnd

Func TooglePause()
	$Paused = Not $Paused
	While $Paused

		;target hp bar check at 0 HP
		$tHppixel = PixelSearch(787, 58, 787, 58, 0x6F1713, 2, 1, $handle)

		If IsArray($tHppixel) = 0 Then
			Send("{F12}") ;finding next mob
			Sleep(20)

			If IsArray($tHppixel) = 0 Then
				Send("{F11}") ;finding next mob
				Sleep(20)

				If IsArray($tHppixel) = 0 Then
					Send("{F10}") ;finding next mob
					Sleep(20)

				EndIf

			EndIf
   ;target should be found at this point, so attacking
		Else
			Send("{F2}") ;attacking mob skill 1
			Sleep(20)
			Send("{F3}") ;attacking mob skill 2
			Sleep(20)

		EndIf
	WEnd
EndFunc   ;==>TooglePause
I'm trying to next target mob if previous mob HP didn't show up. What happens is it presses F12,F11,F10 and stops at F10. I tried to implement ElseIf, but result is exactly the same. What am I doing wrong this time?


And one more question - is it possible to stop script with different script?
What I mean is if have script no1 running which every 1h stops other script no2 by pressing no1 hotkey for 1 minute and then again presses no1 hotkey and script no1 starts?! Or it should be implemented in script no2?
08/25/2014 21:27 KDeluxe#2
Code:
Opt('PixelCoordMode', 0)
Opt('SendKeyDelay', 25)

HotKeySet("{Del}", "TooglePause")

Global $paused = True
Global $handle

While Sleep(10)
    If Not $paused Then
        $handle = WinGetHandle("Lineage*II * ", "")
        If Not @error Then
            ;target hp bar check at 0 HP
            $tHppixel = PixelSearch(787, 58, 787, 58, 0x6F1713, 2, 1, $handle)
            If @error Then
                Send("{F12}") ;finding next mob

                $tHppixel = PixelSearch(787, 58, 787, 58, 0x6F1713, 2, 1, $handle)
                If @error Then
                    Send("{F11}") ;finding next mob

                    $tHppixel = PixelSearch(787, 58, 787, 58, 0x6F1713, 2, 1, $handle)
                    If IsArray($tHppixel) = 0 Then
                        Send("{F10}") ;finding next mob
                    EndIf
                EndIf
            EndIf

            If IsArray($tHppixel) Then
                ;target found, attacking
                Send("{F2}") ;attacking mob skill 1
                Send("{F3}") ;attacking mob skill 2
            EndIf
        EndIf
    EndIf
WEnd

Func TooglePause()
    $Paused = Not $Paused
EndFunc
08/26/2014 14:20 klikata#3
Thank you!
Added few extra sleep and now works as a charm. Your script gives me a good lesson of how to put things together and save pc resources as well. Cheers!
08/26/2014 20:45 Moneypulation#4
Quote:
Originally Posted by KDeluxe View Post
Code:
Opt('PixelCoordMode', 0)
Opt('SendKeyDelay', 25)

HotKeySet("{Del}", "TooglePause")

Global $paused = True
Global $handle

While Sleep(10)
    If Not $paused Then
        $handle = WinGetHandle("Lineage*II * ", "")
        If Not @error Then
            ;target hp bar check at 0 HP
            $tHppixel = PixelSearch(787, 58, 787, 58, 0x6F1713, 2, 1, $handle)
            If @error Then
                Send("{F12}") ;finding next mob

                $tHppixel = PixelSearch(787, 58, 787, 58, 0x6F1713, 2, 1, $handle)
                If @error Then
                    Send("{F11}") ;finding next mob

                    $tHppixel = PixelSearch(787, 58, 787, 58, 0x6F1713, 2, 1, $handle)
                    If IsArray($tHppixel) = 0 Then
                        Send("{F10}") ;finding next mob
                    EndIf
                EndIf
            EndIf

            If IsArray($tHppixel) Then
                ;target found, attacking
                Send("{F2}") ;attacking mob skill 1
                Send("{F3}") ;attacking mob skill 2
            EndIf
        EndIf
    EndIf
WEnd

Func TooglePause()
    $Paused = Not $Paused
EndFunc
Was macht While Sleep(10) ?
Also läuft die Schleife 10 Millisekunden lang? Wenn ja, wozu ist das gut
08/26/2014 22:35 lolkop#5
Quote:
Originally Posted by moneypulation View Post
Was macht While Sleep(10) ?
Also läuft die Schleife 10 Millisekunden lang? Wenn ja, wozu ist das gut
Die Sleep funktion gibt immer 1 (True) zurück. Entsprechend ist
Code:
While Sleep(10)
WEnd
identisch zu
Code:
While True
    Sleep(10)
WEnd
Am Ende kann man mit "While Sleep(10)" eine Endlosschleife realisieren, welche gleichzeitig die CPU entlastet.