Advertisement
CodeCrusader

\/a|0rant Colorbot

Apr 4th, 2025 (edited)
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.97 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. import pyautogui
  4. import time
  5. import math
  6. import threading
  7. import keyboard
  8.  
  9. """
  10. This script is used to assist in aiming at enemies in Valorant.
  11. It uses OpenCV to process the screen and find the enemies based on their color.
  12. It then calculates the angle to aim at the enemy and moves the mouse accordingly.
  13. It also includes a function to take a screenshot of the screen and save it as an image file.
  14. It uses the pyautogui library to move the mouse and take screenshots.
  15. It uses the numpy library to process the image data.
  16. It uses the cv2 library to process the image data.
  17. It uses the time library to add delays between actions.
  18. It uses the math library to calculate angles and distances.
  19. It uses the threading library to run the main function in a separate thread.
  20. It uses the keyboard library to listen for key presses and stop the script.
  21. """
  22.  
  23. def find_enemy(image, lower_color, upper_color):
  24.     """
  25.    Finds the enemy in the given image based on the specified color range.
  26.  
  27.    Args:
  28.        image (numpy.ndarray): The image to process.
  29.        lower_color (tuple): The lower bound of the color range in HSV.
  30.        upper_color (tuple): The upper bound of the color range in HSV.
  31.  
  32.    Returns:
  33.        tuple: The coordinates of the enemy's position (x, y) or None if not found.
  34.    """
  35.     if image is None or not isinstance(image, np.ndarray):
  36.         raise ValueError("Invalid image input. Please provide a valid numpy array.")
  37.    
  38.     hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
  39.     mask = cv2.inRange(hsv_image, lower_color, upper_color)
  40.     contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  41.  
  42.     if contours:
  43.         largest_contour = max(contours, key=cv2.contourArea)
  44.         if cv2.contourArea(largest_contour) > 100:  # Minimum area threshold
  45.             x, y, w, h = cv2.boundingRect(largest_contour)
  46.             return x + w // 2, y + h // 2
  47.     return None
  48.  
  49. def move_mouse_to_target(target_x, target_y):
  50.     """
  51.    Moves the mouse to the specified target coordinates.
  52.  
  53.    Args:
  54.        target_x (int): The x-coordinate of the target.
  55.        target_y (int): The y-coordinate of the target.
  56.    """
  57.     screen_width, screen_height = pyautogui.size()
  58.     current_x, current_y = pyautogui.position()
  59.  
  60.     # Calculate the relative movement
  61.     delta_x = target_x - current_x
  62.     delta_y = target_y - current_y
  63.  
  64.     # Move the mouse smoothly
  65.     pyautogui.moveRel(delta_x, delta_y, duration=0.1)
  66.  
  67. def take_screenshot():
  68.     """
  69.    Takes a screenshot of the screen and saves it as an image file.
  70.  
  71.    Returns:
  72.        numpy.ndarray: The screenshot image as a numpy array.
  73.    """
  74.     screenshot = pyautogui.screenshot()
  75.     screenshot_np = np.array(screenshot)
  76.     return cv2.cvtColor(screenshot_np, cv2.COLOR_RGB2BGR)
  77.  
  78. def main():
  79.     """
  80.    Main function to run the script.
  81.    """
  82.     lower_color = (0, 120, 70)  # Example HSV lower bound for red color
  83.     upper_color = (10, 255, 255)  # Example HSV upper bound for red color
  84.  
  85.     print("Press 'q' to stop the script.")
  86.  
  87.     while True:
  88.         # Take a screenshot
  89.         screen = take_screenshot()
  90.  
  91.         # Find the enemy on the screen
  92.         target = find_enemy(screen, lower_color, upper_color)
  93.  
  94.         if target:
  95.             target_x, target_y = target
  96.             print(f"Enemy found at: {target_x}, {target_y}")
  97.  
  98.             # Move the mouse to the target
  99.             move_mouse_to_target(target_x, target_y)
  100.         else:
  101.             print("No enemy found.")
  102.  
  103.         # Exit the script if 'q' is pressed
  104.         if keyboard.is_pressed('q'):
  105.             print("Exiting script.")
  106.             break
  107.  
  108.         time.sleep(0.1)  # Add a small delay to reduce CPU usage
  109.  
  110. if __name__ == "__main__":
  111.     main()
  112.  
  113.  
  114. # Note: This script is for educational purposes only. Use it responsibly and in accordance with the game's terms of service.
  115. # Using this script in online games may lead to bans or other penalties.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement