qué hace este codigo python: import pyautogui import time import pygetwindow as gw…
- User
qué hace este codigo python: import pyautogui import time import pygetwindow as gw import keyboard import random import win32api, win32con from threading import Timer
Tiempo de espera antes de empezar
time.sleep(2)
Funciones para detectar y recolectar crionita
def click_izquierdo(x, y): win32api.SetCursorPos((x, y)) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
def collect_cryo(): r_min, g_min, b_min = 18, 178, 199 r_max, g_max, b_max = 48, 206, 228 crionita_recogida = False while not keyboard.is_pressed('q'): flag = 0 pic = pyautogui.screenshot(region=(1086, 604, 152, 152))
codewidth, height = pic.size for x in range(0, width, 4): for y in range(0, height, 4): r, g, b = pic.getpixel((x, y)) if r_min <= r <= r_max and g_min <= g <= g_max and b_min <= b <= b_max: flag = 1 click_izquierdo(x + 1086, y + 604) time.sleep(3.5) # Esperar 3.5 segundos pyautogui.press('2') # Presionar la tecla 2 time.sleep(2) # Esperar 2 segundos print('Crionita recolectada') crionita_recogida = True if flag == 1: break if not crionita_recogida: break return crionita_recogidaFunciones para seleccionar enemigos
def right_click(x, y): win32api.SetCursorPos((x, y)) win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0) win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0)
def select_entity(): r_min, g_min, b_min = 223, 204, 1 r_max, g_max, b_max = 240, 221, 54
codewhile not keyboard.is_pressed('q'): pic = pyautogui.screenshot(region=(1086, 604, 152, 152)) width, height = pic.size for x in range(0, width, 4): for y in range(0, height, 4): r, g, b = pic.getpixel((x, y)) if r_min <= r <= r_max and g_min <= g <= g_max and b_min <= b <= b_max: right_click(x + 1086, y + 604) time.sleep(2) print('Enemigo seleccionado') return True print("No se encontró enemigo") return False - Assistant
- User
- Assistant
Por supuesto, dime qué cambios te gustaría realizar en el código, y te asisteré en su modificación.
- User
quiero que cuando region se ponga de este color rgb: (255, 255, 255 ) seleccione a un enemigo
- Assistant
Para modificar el código y hacer que seleccione un enemigo cuando la región tiene un píxel con el color RGB (255, 255, 255), necesitas ajustar la función
select_entitypara buscar ese color específico. Aquí está el cambio que necesitas realizar:pythondef select_entity(): # Cambiamos los valores RGB al color blanco r_target, g_target, b_target = 255, 255, 255 while not keyboard.is_pressed('q'): pic = pyautogui.screenshot(region=(1086, 604, 152, 152)) width, height = pic.size for x in range(0, width, 4): for y in range(0, height, 4): r, g, b = pic.getpixel((x, y)) # Compara cada píxel con el color blanco (255, 255, 255) if r == r_target and g == g_target and b == b_target: right_click(x + 1086, y + 604) time.sleep(2) print('Enemigo seleccionado') return True print("No se encontró enemigo") return False - User
me equivoque, cambia el color anterior por: ( 21, 27, 36)
- Assistant
Para ajustar la función
select_entitypara que busque y seleccione un enemigo cuando detecte el color RGB(21, 27, 36), simplemente necesitamos modificar los valores de la variabler_target,g_targetyb_targeten la función correspondiente. Aquí está el código modificado:python