Jump to content
Sign in to follow this  
Guest Ickie

Making bot for 2D Game

Recommended Posts

Guest Ickie

;====================================================================
;MapleStory iBot
;====================================================================
;Author: Ickie <ickius@gmail.com>
;Details: Detects enemies when they spawn, auto-loots and auto-heals.
;====================================================================

;====================================================================
;GUI
;====================================================================
#include <GuiConstants.au3>

GUICreate("Maple Story iBot",300,400)

;====================================================================
;Detect Enemies
;====================================================================
WinWaitActive ("MapleStory")
$Size = WinGetPos("MapleStory")
$Pixel = PixelSearch($Size[0], $Size[1], $Size[2], $Size[3], 6258496)
Do
Send("{LCTRL}",0)
Until $Pixel = PixelSearch($Size[0], $Size[1], $Size[2], $Size[3], -1)

;--------------------------------------------------------------------
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

I'm trying to make a bot for "Maple Story" but for some reason its not working the way I want.

Basicly, as soon as the bot sees the enemy (Look in Attachment), my character shoots untill the enemy is dead. I attemped that in my small script.

Instead of doing what I planed, it does this:

Start Script

Switch to MapleStory

Press CTRL then he will start auto shooting, even if theirs not a enemy and won't stop.

Help?

Edited by Ickie

Share this post


Link to post
Share on other sites

I'm trying to make a bot for "Maple Story" but for some reason its not working the way I want.

Basicly, as soon as the bot sees the enemy (Look in Attachment), my character shoots untill the enemy is dead. I attemped that in my small script.

Instead of doing what I planed, it does this:

Start Script

Switch to MapleStory

Press CTRL then he will start auto shooting, even if theirs not a enemy and won't stop.

Help?

<{POST_SNAPBACK}>

Based on your code, if pixelsearch finds ANY PIXEL that matches 0x5F7F40 (6258496), then it's going to run it as true and start firing. Try narrowing down your search grid, stand some distance to the south of the spawn and only search the top 1/3 of the screen.

By the way, the colour you're searching for is a wierd shade of Olive Drab green. It's perfect for a secondary grass or tree colour in an MMORPG, so my guess you need to change your colour. Or change the way you look for it. Try HEX, it's easier to understand than decimal for colours.

Edit: I just looked at the screen shot. You're using the mushroom cap for the search colour. IT'S THE SAME COLOUR AS SOME OF THAT VINE!!!! Use the mushroom body (the white/offwhite) and combine it with a secondary pixelsearch that searches around a positive match for a pixel of the same colour or the shaded version of the mushroom body....the piece under the cap.

Not much else I can suggest as I haven't even played that game.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
Guest Ickie

Ok, thanks. I'm using the color of the inside of the Mushrooms mouth (pink).

One Problem, How do I make it loop until that color is gone? -1 Doesn't seem to work =/ then agian I just assumed that would do something.

Share this post


Link to post
Share on other sites

Ok, thanks. I'm using the color of the inside of the Mushrooms mouth (pink).

One Problem, How do I make it loop until that color is gone? -1 Doesn't seem to work =/ then agian I just assumed that would do something.

<{POST_SNAPBACK}>

#region Look for Pink
$pix1 = 0
$pix2 = 0
$pink1 = 0x000000
$pink2 = 0xFFFFFF

While 1
   Sleep(10)
   $pix1 = Pixelsearch(x1,y1,x2,y2,$pink1)
    If @error = 1 then ExitLoop
   $pix2 = Pixelsearch(x1,y1,x2,y2,$pink2)
    If @error = 1 then ExitLoop
Wend
MsgBox(0,"Found it!","I found pink!")
#endregion

This allows you to find two separate shades of pink, you'll have to change the variables to match your actual shade(s) of course. You could put this whole block inside a bigger while loop.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

#region Look for Pink
$pix1 = 0
$pix2 = 0
$pink1 = 0x000000
$pink2 = 0xFFFFFF

While 1
   Sleep(10)
   $pix1 = Pixelsearch(x1,y1,x2,y2,$pink1)
    If @error = 1 then ExitLoop
   $pix2 = Pixelsearch(x1,y1,x2,y2,$pink2)
    If @error = 1 then ExitLoop
Wend
MsgBox(0,"Found it!","I found pink!")
#endregion

This allows you to find two separate shades of pink, you'll have to change the variables to match your actual shade(s) of course.  You could put this whole block inside a bigger while loop.

<{POST_SNAPBACK}>

No reason to question this really but to affirm my own thoughts.

What's the difference of:

While 1
   Sleep(10)
   $pix1 = Pixelsearch(x1,y1,x2,y2,$pink1)
    If @error = 1 then ExitLoop
   $pix2 = Pixelsearch(x1,y1,x2,y2,$pink2)
    If @error = 1 then ExitLoop
Wend

Or

While 1
   Sleep(10)
   $pix1 = Pixelsearch(x1,y1,x2,y2,$pink1)
    If @error Then ExitLoop
   $pix2 = Pixelsearch(x1,y1,x2,y2,$pink2)
    If @error Then ExitLoop
Wend

Been working alot with pixels lately and under the impression that if PixelSearch was @error that it returned 1 regardless. Would it return something other than that? Because that would make a difference in some of my scripts.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Maybe can help you script this if you need it. I play the game too, and am constantly looking for places to bot and testing new scripts out. And it looks like you have a really nice script going so maybe i could get that from you when it is complete? you know test it out? but if not thats totally understandable and cool.

Share this post


Link to post
Share on other sites

What's the difference of:

While 1
   Sleep(10)
   $pix1 = Pixelsearch(x1,y1,x2,y2,$pink1)
    If @error = 1 then ExitLoop
   $pix2 = Pixelsearch(x1,y1,x2,y2,$pink2)
    If @error = 1 then ExitLoop
Wend

Or

While 1
   Sleep(10)
   $pix1 = Pixelsearch(x1,y1,x2,y2,$pink1)
    If @error Then ExitLoop
   $pix2 = Pixelsearch(x1,y1,x2,y2,$pink2)
    If @error Then ExitLoop
Wend

Been working alot with pixels lately and under the impression that if PixelSearch was @error that it returned 1 regardless.  Would it return something other than that?  Because that would make a difference in some of my scripts.

<{POST_SNAPBACK}>

My guess would be that the If @error Then function checks for any NON-ZERO value.

I always like specify what @error should equal to, that way there's no ambiguity in the code. It's just my quirk, YMMV.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

I always like specify what @error should equal to, that way there's no ambiguity in the code.  It's just my quirk, YMMV.

<{POST_SNAPBACK}>

There is a serious flaw in this logic, though. If a function suddenly gets a new error condition and @error is set to reflect that, your code will suddenly fail. @error should never be checked for an explicit value unless that explicit value is important to the proper execution of the code.

For example, say that you have a function which returns an array of data. When you first start using this function, @error will be set to 1 if the array is not created successfully. This would lead to the following code:

$array = LoadArrayFromData($data)
If @error = 1 Then
    MsgBox(4096, "Error", "Error populating array with data.")
    Return
EndIf
For $i = 0 To UBound($array)-1
    MsgBox(0, "Array contents", $array[$i])
Next

Now, fast forward in time to a newer, more efficient version of LoadArrayFromData(). Say for example the author wished to expand the @error codes to better describe what sort of problem the function had. Now suppose that @error can be set as follows:

@error = 1 - The $data string was empty

@error = 2 - The $data string was not empty, however, no delimiters were found so an array could not be built.

Now, lets go back to the code from before. Since @error is explicty checked against the value of 1, an @error of 2 will not be caught and you'll get a runtime crash complaining about indexing a non-array variable.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...