Simple example of a combat auto clicker in Python

Discussion in 'RuneScape Programming' started by ViperViking, Apr 1, 2023.

Simple example of a combat auto clicker in Python
  1. Unread #1 - Apr 1, 2023 at 3:16 PM
  2. ViperViking
    Joined:
    Mar 24, 2023
    Posts:
    6
    Referrals:
    0
    Sythe Gold:
    4

    ViperViking Newcomer

    Simple example of a combat auto clicker in Python

    Code:
    #The minotaur_alive.png photo is the health bar
    #of the minotaur that I set in the top left corner
    #of the game when playing
    #https://imgur.com/a/DL732u2
    
    import pyautogui
    import random
    import time
    from PIL import Image, ImageGrab
    import re
    import pytesseract
    import math
    
    # Set up the Tesseract OCR path
    pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
    
    def main(minotaur_images, region):  
        # Loop continuously
        while True:
            # Check if the player is fighting the minotaur
            if pyautogui.locateOnScreen("minotaur_alive.png", confidence=0.95, region=(0,0,300,200)) is None:
                # If the minotaur is on screen, attack it and then check health
                for image in minotaur_images:
                    print(image.filename)
                    minotaur_location = pyautogui.locateOnScreen(image, confidence=0.6, region=region)
                    if minotaur_location:
                        pyautogui.moveTo(minotaur_location, duration=random.randint(23,32)/100, tween=pyautogui.easeOutQuad)
                        pyautogui.moveTo(pyautogui.position()[0] + random.randint(-4, 4), pyautogui.position()[1] + random.randint(-4, 4), duration=.2, tween=pyautogui.easeOutQuad)
                        pyautogui.click(button='left')
                        time.sleep(random.randint(230, 320) / 100)
                        break
                health_button = ImageGrab.grab(bbox=(104, 933, 104+36, 933+15))
                resized_img = health_button.resize((health_button.width * 2, health_button.height * 2))
                health_amount = get_text(resized_img)
                if health_amount and not math.isnan(int(replace_chars(health_amount))):
                    print(int(replace_chars(health_amount)))
                if (int(replace_chars(health_amount)) > 2000 and int(replace_chars(health_amount)) < 4200):
                    lobster_location = pyautogui.locateOnScreen('lobster.png', confidence=0.95, region=region)
                    if lobster_location:
                        pyautogui.moveTo(lobster_location,duration=random.randint(23,32)/100,tween=pyautogui.easeOutQuad)
                        pyautogui.moveTo(pyautogui.position()[0]+random.randint(-4,4), pyautogui.position()[1]+random.randint(-4,4),duration=random.randint(23,55)/100,tween=pyautogui.easeOutQuad)
                        pyautogui.click(button='left')
                        time.sleep(random.randint(89,132)/100)
            else:
                # If the minotaur is not on screen, wait for it to appear
                time.sleep(0.2)
    
    def get_text(image):
        return pytesseract.image_to_string(image, config='--psm 6')
      
      
    def replace_chars(text):
        """
        Replaces all characters instead of numbers from 'text'.
      
        :param text: Text string to be filtered
        :return: Resulting number
        """
        list_of_numbers = re.findall(r'\d+', text)
        result_number = ''.join(list_of_numbers)
        return result_number
    
    if __name__ == '__main__':
        # Define the region to search for images in
        REGION = (0, 0, 1920, 1080)
      
        # Load the images of the minotaur
        minotaur_images = ['minotaur1.png', 'minotaur2.png', 'minotaur3.png', 'minotaur4.png', 'minotaur5.png']
        minotaur_images = [Image.open(image) for image in minotaur_images]
      
        # Start the main function
        main(minotaur_images, REGION)
    
     
    Last edited: Apr 1, 2023
  3. Unread #2 - Apr 1, 2023 at 3:18 PM
  4. ViperViking
    Joined:
    Mar 24, 2023
    Posts:
    6
    Referrals:
    0
    Sythe Gold:
    4

    ViperViking Newcomer

    Simple example of a combat auto clicker in Python

    Ok how tf do you align python code
     
< Client Development | Getting started? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site