Skip to content
Advertisement

What are ways to create a bot or script that detects monsters in a video game and click on it?

I’ve been trying to create a bot using python for an online mmo web game, and I am facing some issues. I’m using pyautogui, and basically, detects a certain RGB color of a pixel that the monster has and click on it, using the typical nested for loops. The issue here is that sometimes, the bot clicks on an environment on the screen that shares the same pixel RGB color as the monster, so instead of clicking on the monster, it clicks on the ground or any other object in the game.

here’s my code:

        pic = pyautogui.screenshot()

        (width, height) = pic.size

        for x in range(0, width):
            for y in range(0, height):
                (r, g, b) = pic.getpixel((x, y))

                # MOVE

                if r == 152 and g == 119 and b == 111 or r == 163 
                    and g == 119 and b == 113:
                    click(x, y)

What are other ways to detect monster and click? Here’s an image of the monster: enter image description here

enter image description here enter image description here

This method is also really slow in its scan, I move my character and I have to stop for a few seconds for it to scan the screen and detect, and move again.

Advertisement

Answer

well, a while ago I made a code in python for image recognition also in an mmo, I used the locateOnScreen, center and click methods, you can base yourself on these 3 main functions for the development of yours, I’ll leave part of mine below code:

#This function will locate the image "vara.png" in my directory and compare if it exists on the screen, grayscale is used to improve search processing and confidence means how close my image is found on the screen (80%)

positionVara = pyautogui.locateOnScreen('vara.png', grayscale=True,confidence=0.8)

#Center is used to detect x and y coordinates
positionCenterVara = pyautogui.center(positionVara)

#after obtaining the coordinates it will click on the center of the found image
pyautogui.click(positionCenterVara.x,positionCenterVara.y)

That’s it, hope it helps, sorry for my english because i used google translator

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement