Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java bot for an online game

I am creating a bot in java using the java.awt.Robot. The bot works fine on a browser (I have also tested it using Microsoft Word!) but when I run it in the game, the only function that works is the mouseMove. I want to build a bot that simply presses keyboard buttons for me.

I instantiate the robot class

Robot r = new Robot();

Then I do some simple stuff: press z,press 1, move the mouse and right click.

r.keyPress(KeyEvent.VK_Z);
r.keyRelease(KeyEvent.VK_Z);

r.keyPress(KeyEvent.VK_1);
System.out.println("Press 1 button");
r.keyRelease(KeyEvent.VK_1);
System.out.println("Release 1 button");
r.delay(1000);

System.out.println("Move mouse");
r.mouseMove(110, 690);

System.out.println("Press");
r.mousePress(InputEvent.BUTTON3_MASK);
System.out.println("Release");
r.mouseRelease(InputEvent.BUTTON3_MASK);

Why is this happening? Can this Robot class perform these kind of actions within a game if it runs in the background?

Thank you

Update: If I run my bot on PES 2012 for example, it works fine but if I run it on an online game like Cabal, it does not work? the protection system of the game does not detect anything so that is not the case.

like image 724
George Artemiou Avatar asked Aug 31 '12 23:08

George Artemiou


People also ask

Do online games use bots?

Game bots are present in nearly every multiplayer game, from Halo to MMORPGs. Game bots perform various tasks, everything from acting as the player would or NPCs doing farm work. Artificial intelligence has come a long way from the days of Pong. There are various types of game bots as well.

Can I make a bot with Java?

Java: Coding Your Discord Bot in a Robust, Popular LanguageMaking your own Discord bot in Java is going to teach you all the nuances of setting up a project, configuring it, adding a library/wrapper, writing code, and finally getting your bot online.

What is a bot in online gaming?

A Game Bot is an automated program that plays the game on behalf of human players. Since they can play without break, game bots can accumulate money and items much faster than normal human players.


1 Answers

First of all, most games have bot protection, so make sure to add a delay to the bot and, maybe, a 'cooldown'. Before that r.delay(1000) statement, the bot did two instant actions.

I'm almost sure it's not working because the keystrokes are way too fast: they press and release instantly. Try adding bot.delay(500) (or more, depends on the game) right after you instantiate Robot class; before all the key pressing functions. That would add a 500ms delay between ALL actions done by the robot.

public static void doStuff() {

    Robot r = new Robot();

        r.delay(500); //Or more - depends on the game

        r.keyPress(KeyEvent.VK_Z);
        r.keyRelease(KeyEvent.VK_Z);

        r.keyPress(KeyEvent.VK_1);
        System.out.println("Press 1 button");
        r.keyRelease(KeyEvent.VK_1);
        System.out.println("Release 1 button");
        r.delay(1000);

        System.out.println("Move mouse");
        r.mouseMove(110, 690);

        System.out.println("Press");
        r.mousePress(InputEvent.BUTTON3_MASK);
        System.out.println("Release");
        r.mouseRelease(InputEvent.BUTTON3_MASK);
}

I think the only reason why the Z and 1 keys didn't work was the speed everything was done. The game probably has an anti-bot system.

like image 63
borges Avatar answered Oct 12 '22 07:10

borges