Script clicks all the time

08/23/2014 14:48 klikata#1
Hello!
I used to use autohotkey, but since it is not possible to use on the server I play, i have found autoit. It is completely new for me. After few days of reading I have created my own script where
1)pixel should be read at given coordinates
2)if pixel is not there F4 should be sent

Script should be working over and over. Unfortunately for me -
script is not doing anything.
If i use "Not @error" then it is pressing f4 all the time even I'm 100% sure pixel is there.
To explain what this script should do - use mana potion in Lineage2 when mp gets lower.

Can anybody please guide me through the wrong part of my code?


Code:
Func _WinWaitActivate($title,$text,$timeout=0)
	WinWait($title,$text,$timeout)
	If Not WinActive($title,$text) Then WinActivate($title,$text)
	WinWaitActive($title,$text,$timeout)
EndFunc



_WinWaitActivate("Lineage*II * ","")
HotKeySet("{ESC}", "Terminate")
While 1
	PixelSearch( 234, 54, 0, 0, 0x234B88)
If @error Then
		 Send("{F4}")
		 Sleep (500)
		 EndIf
WEnd
Func Terminate()
    Exit 0
EndFunc
08/23/2014 17:20 Rorc#2
Code:
While True
	$bPixel = PixelSearch( 234, 54, 0, 0, 0x234B88)
If $bPixel = 0 Then
Send("{F4}")
Sleep (500)
Else
Sleep(50)
EndIf
WEnd
Sorry, didn't use Scite to write this, but this should actually work out.

As far as I know, Pixelsearch does not throw @error, if the pixel is not found, but simply returns 0.
08/23/2014 18:31 klikata#3
Quote:
Originally Posted by Shanks View Post
Code:
While True
	$bPixel = PixelSearch( 234, 54, 0, 0, 0x234B88)
If $bPixel = 0 Then
Send("{F4}")
Sleep (500)
Else
Sleep(50)
EndIf
WEnd
Sorry, didn't use Scite to write this, but this should actually work out.

As far as I know, Pixelsearch does not throw @error, if the pixel is not found, but simply returns 0.
Thanks for your input, but most of the sources says that @error should work.
I just tried your version and again, it just keeps spamming F4.
Looks like I have to find better way how to determine x,y and color of Lineage II client. Maybe the problem is in x, y, and color itself?!

I was using autoit tool.
08/23/2014 18:56 Rorc#4
Use the
Code:
PixelGetColor ( x , y [, hwnd] )
method to find out, wether or not your Color Hex is right.
08/23/2014 21:03 YatoDev#5
Quote:
Originally Posted by Shanks View Post
Code:
While True
	$bPixel = PixelSearch( 234, 54, 0, 0, 0x234B88)
If $bPixel = 0 Then
Send("{F4}")
Sleep (500)
Else
Sleep(50)
EndIf
WEnd
Sorry, didn't use Scite to write this, but this should actually work out.

As far as I know, Pixelsearch does not throw @error, if the pixel is not found, but simply returns 0.
It throws @error but better check with IsArray because @error can fail in some cases
08/24/2014 06:53 klikata#6
Thanks guys!
The secret was in
HTML Code:
Opt('PixelCoordMode',0)
It is 5.51AM but i got it done.
I have a million of questions, but lets leave them to other day.
Cheers again!