trying to make a small bot for a browsergame and failing miserably. Topic is solved

Ask gaming related questions (AHK v1.1 and older)
UsernameAlreadyInUse

trying to make a small bot for a browsergame and failing miserably.  Topic is solved

22 Mar 2017, 12:49

Hello and good day.

Yesterday I thought about making a small little bot, just as a test, since I have no programming/scripting experience whatsoever.
As you can guess from the title, the bot isn't working as expected on account of my inability I am aware.

2 pictures to better convey what the bot is supposed to do.
http://imgur.com/a/CZmJJ
http://imgur.com/a/lhfiL

So, it's basically a golf game, the black ball goes back and forth and decides how good your shot is.
If you hit the green area, it's a perfect hit.
Now herein lies the problem, the green area randomly changes position at every new hit you're supposed to make.
The bot is suppoed to find the green area, and if it is no longer green because the black ball covers it, it's supposed to hit space so that you get a perfect hit.


This is how my script looks so far:

Pause

TheColor = 0x48FF25 ; The green color
OtherColor = 0x010101 ; The black color
TopLx = 790
TopLy = 559
BotRx = 1126
BotRy = 578 ; The coordinates of the rectangle that's supposed to be searched for the color
variation = 15 ; The range of color variation


Loop
{
PixelSearch, Sx, Sy, %TopLx%, %TopLy%, %BotRx%, %BotRy%, %TheColor%, %variation%, fast ; Look for the color in the area that's specified

If (%Sx%, %Sy% != %TheColor%) ; If the black ball covers the green area, hit space
{
Send {Space down}
sleep 50
Send {Space up}
}



}

F8::Pause, toggle


What's working: It waits for the bar to appear and doesn't randomly press space
What isn't working: It hits space as soon as the bar appears, it does not wait for the black ball to cover the green area
What do I think: I think I'm just misunderstanding how PixelSearch actually works
What I want: A push in the right direction. I don't want the script to just be finished for me, I want to understand and also learn what I must do to finish it myself.

Thank you kindly for your patience and I'd appreciate any and all help.
Kind regards.
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: trying to make a small bot for a browsergame and failing miserably.

23 Mar 2017, 07:36

Can you please provide the website for the game so that we may use it for testing?
UsernameAlreadyInUse

Re: trying to make a small bot for a browsergame and failing miserably.

23 Mar 2017, 09:51

Yes,
The game is called "HAL's hole in one golf" for the SNES.
TravisQ
Posts: 27
Joined: 17 May 2015, 23:51

Re: trying to make a small bot for a browsergame and failing miserably.

24 Mar 2017, 06:55

inner loop - break
pixelgetcolor
if (expression)
grant
Posts: 323
Joined: 14 Oct 2015, 17:27

Re: trying to make a small bot for a browsergame and failing miserably.

28 Mar 2017, 04:27

I would approach like this:
-find the START of the green bar with PixelSearch (this should be top left). Then I would use PixelGetColor and increase the x by 1 till you get a false and halfway down is the center of the bar. Do the same again with y to get the middle of the green bar. Add the radius of the black dot to the centre (up - down) and middle (left - right) to get your calculated trigger spot
- now use PixelGetColor at your calculated trigger spot looking for the right most side of the black dot's color to trigger your key.

- you might find that the dot is past your trigger point by the time you have found your green bar center. In this case, you will have to increase your green bar detection speed by skipping a few pixels at a time, i.e check only every 3rd or 4th pixel, which will be less accurate but still better than human.
-if you are consistently hitting early or late, adjust the calculated trigger spot with a few pixels.
- if your dot is still past this and comes back (moving right to left) you will have to reverse your trigger point, but it should be fast enough.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: ReyAHK and 40 guests