DEV Community

Cover image for GTA RP Nopixel Thermite Fast Click Bot
Possessed Player
Possessed Player

Posted on

GTA RP Nopixel Thermite Fast Click Bot

If you've played GTA RP Nopixel, you know it has very challenging minigames, one of which is called "Thermite".

Image description

In this minigame you've to memorize the pattern in 5 seconds only, after which you're asked to repeat it very quickly, and as you might imagine this is pretty challenging.

But no worries, this is where my script comes to the rescue, all you've to do is press a hotkey to the record the pattern, then press another one to make the script repeat what it just recorded.

Clone the Github repo here.

Check out the bot video here.

Code Explained

Line (12) record function

def record():
    img_bgr = pag.screenshot()
    img_bgr = np.array(img_bgr)
    img_rgb = img_bgr[:,:,::-1].copy()
    img_gray = cv.cvtColor(img_rgb, cv.COLOR_BGR2GRAY)
    template = cv.imread('obj/' + WIMG + '.jpg',0)
    w, h = template.shape[::-1]

    res = cv.matchTemplate(img_gray, template,cv.TM_SQDIFF_NORMED)
    mn,mx,mnLoc,mxLoc = cv.minMaxLoc(res)
Enter fullscreen mode Exit fullscreen mode

This function is called when the user presses
"CTRL + SHIFT + ALT + O"

Which initiates the pattern recording process.

It works by taking a screenshot of the whole screen using pyautogui.screenshot function, then looks for parts of the screen that looks exactly like a white square, by comparing a template image of the white square to the screenshot using opencv "cv.matchTemplate" function.

Line (23) record function cont.

    print(mx)
    threshold = 0.05
    loc = np.where(res <= threshold)
    points = []
    for pt in zip(*loc[::-1]):
        close = False
        for p in points:
            if abs(pt[0] - p[0]) < 10 and abs(pt[1] - p[1]) < 10:
                close = True
                break

        if close: 
            continue
        points.append(pt)
        cv.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)

    global Whites
    Whites = points
Enter fullscreen mode Exit fullscreen mode

In this part of the record function it looks for matches, and saves them in the global list "Whites", after processing them into a screen position tuples.

Line (43) go function

def go():
    global Whites
    print(Whites)
    for pt in Whites:
        pag.click(pt[0] + 30, pt[1] + 30)
        sleep(0.05)
Enter fullscreen mode Exit fullscreen mode

This function is executed when the user presses
"CTRL + SHIFT + ALT + P"

It works by clicking on recorded screen locations, which are saved by the 'record' function.

It goes over the global list "Whites", and clicks on each screen location, using pyautogui.click function.

def kb_listener():
    def on_release(key):
        print(str(key))
        if str(key) == "<79>":
            record()
        elif str(key) == "<80>":
            go()

    with Listener(on_release=on_release) as listener:
        listener.join()
Enter fullscreen mode Exit fullscreen mode

This is our usual keyboard listener function, which executes 'record' and 'go' functions when the user presses the right combinations(Check pynput documentation for more info about this function).

Line (62) script main code

if __name__ == '__main__':
    WIMG = input("Type 7 for 7x7, 8 for 8x8 then press Enter\n")
    if not (WIMG in ("7", "8")):
        print("Type either 7 or 8 to run this bot, Exiting...")
        quit()

    print("Running...")

    while True:
        kb_listener()
Enter fullscreen mode Exit fullscreen mode

This part is responsible of running the whole script and loads the global variable 'WIMG', which a selector for the minigame square size, 7x7 and 8x8 are supported.

Thanks for reading.

Top comments (1)

Collapse
 
arrtuu profile image
t

i seems to cant get this to work, if you could help me i would apprieate it