Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- import pyautogui
- import time
- import math
- import threading
- import keyboard
- """
- This script is used to assist in aiming at enemies in Valorant.
- It uses OpenCV to process the screen and find the enemies based on their color.
- It then calculates the angle to aim at the enemy and moves the mouse accordingly.
- It also includes a function to take a screenshot of the screen and save it as an image file.
- It uses the pyautogui library to move the mouse and take screenshots.
- It uses the numpy library to process the image data.
- It uses the cv2 library to process the image data.
- It uses the time library to add delays between actions.
- It uses the math library to calculate angles and distances.
- It uses the threading library to run the main function in a separate thread.
- It uses the keyboard library to listen for key presses and stop the script.
- """
- def find_enemy(image, lower_color, upper_color):
- """
- Finds the enemy in the given image based on the specified color range.
- Args:
- image (numpy.ndarray): The image to process.
- lower_color (tuple): The lower bound of the color range in HSV.
- upper_color (tuple): The upper bound of the color range in HSV.
- Returns:
- tuple: The coordinates of the enemy's position (x, y) or None if not found.
- """
- if image is None or not isinstance(image, np.ndarray):
- raise ValueError("Invalid image input. Please provide a valid numpy array.")
- hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
- mask = cv2.inRange(hsv_image, lower_color, upper_color)
- contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
- if contours:
- largest_contour = max(contours, key=cv2.contourArea)
- if cv2.contourArea(largest_contour) > 100: # Minimum area threshold
- x, y, w, h = cv2.boundingRect(largest_contour)
- return x + w // 2, y + h // 2
- return None
- def move_mouse_to_target(target_x, target_y):
- """
- Moves the mouse to the specified target coordinates.
- Args:
- target_x (int): The x-coordinate of the target.
- target_y (int): The y-coordinate of the target.
- """
- screen_width, screen_height = pyautogui.size()
- current_x, current_y = pyautogui.position()
- # Calculate the relative movement
- delta_x = target_x - current_x
- delta_y = target_y - current_y
- # Move the mouse smoothly
- pyautogui.moveRel(delta_x, delta_y, duration=0.1)
- def take_screenshot():
- """
- Takes a screenshot of the screen and saves it as an image file.
- Returns:
- numpy.ndarray: The screenshot image as a numpy array.
- """
- screenshot = pyautogui.screenshot()
- screenshot_np = np.array(screenshot)
- return cv2.cvtColor(screenshot_np, cv2.COLOR_RGB2BGR)
- def main():
- """
- Main function to run the script.
- """
- lower_color = (0, 120, 70) # Example HSV lower bound for red color
- upper_color = (10, 255, 255) # Example HSV upper bound for red color
- print("Press 'q' to stop the script.")
- while True:
- # Take a screenshot
- screen = take_screenshot()
- # Find the enemy on the screen
- target = find_enemy(screen, lower_color, upper_color)
- if target:
- target_x, target_y = target
- print(f"Enemy found at: {target_x}, {target_y}")
- # Move the mouse to the target
- move_mouse_to_target(target_x, target_y)
- else:
- print("No enemy found.")
- # Exit the script if 'q' is pressed
- if keyboard.is_pressed('q'):
- print("Exiting script.")
- break
- time.sleep(0.1) # Add a small delay to reduce CPU usage
- if __name__ == "__main__":
- main()
- # Note: This script is for educational purposes only. Use it responsibly and in accordance with the game's terms of service.
- # Using this script in online games may lead to bans or other penalties.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement