Making a simple bot for 2D game

04/03/2016 16:16 mpaulsen#1
Hi. I am trying to make a simple bot in AutoIt for a old school mmo.
I am currently using AHK but i feel the pixelsearch in AutoIt works better.

So fare i have changed the desired sprites in the game so they have a blue square with hexcolor 0x0000FF, that i use durring pixelsearch, and a part that checks for my HP and pots if nessesary.

My problem is in AHK i could do Click, x, y, down to attack a monster for a specific amount of time. Cant rly seem to get that to work in AutoIt - the mouseMove then mouseDown seems unreliable.


Also any suggestions on anything i can improve ?

Code:
HotKeySet("!q", "Terminate")
HotKeySet("!a", "attackLoop")
HotKeySet("!e", "autoPot")

WinActivate("Lineage")

Global $interval
$interval = 5000
$hpcolor = 0x7B3029


Func Terminate()
   Exit 1
EndFunc



Local $aColorArray[1] = [ 0x0000FF]


Func attackLoop()
   While 1
	  $point = PixelSearch(275,192,445,296,$aColorArray)   %% Search a small box around target for monsters
	  $point2 = PixelSearch(228,158,350,252,$aColorArray) %% search a bigger box around target for monsters
		 if IsArray($point) Then
			MouseMove($point[0], $point[1])
                        MouseDown("left")
			Sleep($interval)
                        MouseUp("left")
		 ElseIf IsArray($point2) Then
			MouseMove($point2[0], $point2[1])
			MouseDown("left")
			Sleep($interval)
                        MouseUp("left")
		 Else
			Send("{F7}") % Random teleports to a new area.
			Sleep(3000)
		 EndIf
		 Sleep(50)
   WEnd
EndFunc


Func autoPot()
   While 1
		$pot = PixelGetColor(110,437)
		if $pot = $hpcolor Then

		   sleep(1000)
		Else
		   Send("{F5}")
		   sleep(1000)
		EndIf

   WEnd

   EndFunc

While 1
   Sleep(250)
WEnd
04/03/2016 19:22 alexutu2013#2
why you don't use MouseClick instead mousedown/up?
04/04/2016 05:48 Moneypulation#3
If MouseDown and MouseUp doesn't work you can try out AutoItSetOption with the [Only registered and activated users can see links. Click Here To Register...]
04/13/2016 00:33 HaMaDa..#4
Why u don't use mouseclick or controlclick instead of down/up ?

MouseClick("Left / right",x,y)
ControlClick("Your game title","","","Left/right",1000 ; clicks,x,y)