有什么方法可以创建一个机器人或脚本来检测视频游戏中的怪物并点击它?

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

我一直在尝试使用 python 创建一个用于在线 mmo 网络游戏的机器人,但我遇到了一些问题。我正在使用 pyautogui,基本上,使用典型的嵌套 for 循环检测怪物拥有的像素的特定 RGB 颜色并单击它。这里的问题是,有时候,机器人会点击屏幕上与怪物共享相同像素 RGB 颜色的环境,因此它不会点击怪物,而是点击地面或游戏中的任何其他物体。

这是我的代码:

        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)

还有哪些检测怪物和点击的方法?这是怪物的图片:enter image description here

enter image description here enter image description here

这个方法扫描起来也很慢,我移动我的角色,我必须停下来几秒钟,它才能扫描屏幕并检测,然后再移动。

嗯,前段时间我在python中做了一个代码,也是在一个mmo中进行图像识别,我使用了locateOnScreen,center和click方法,你可以基于这3个主要功能进行开发你的,我会在代码下面留下我的一部分:

#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)

就是这样,希望对您有所帮助,抱歉我的英语不好,因为我使用了 google 翻译器