Apr-05-2018, 05:33 PM
The code will loop itself for around 5 minutes. That no functions will be running in the while loops and it loops 700+ it breaks and loops really fast and lags. It tries to run stuff but does not, might cause the lag I don't know. How do I fix this so it can loop and not break? I think it has to do with the pixelMatchesColor call. Less I have longer it runs?
Mose of the functions I'm making into modules but making it all in one place to get help. I'm new to python as well, trying my best.
Mose of the functions I'm making into modules but making it all in one place to get help. I'm new to python as well, trying my best.
from time import sleep from random import uniform, randint from pyautogui import pixelMatchesColor, keyDown, keyUp, moveRel, position, click, press fail_safe = 0 shut_down = 0 on_off = 0 click_one = 1 click_two = 1 move_one = 1 def look(): #trys to see if a pixel im looking at is one of the 4 colors, moves my mouse x amount on what one it sees. first_cord, second_cord = position() find_look_left_1 = pixelMatchesColor(first_cord, second_cord, (95, 95, 0), tolerance=20) find_look_left_2 = pixelMatchesColor(first_cord, second_cord, (148, 148, 0), tolerance=30) find_look_right_1 = pixelMatchesColor(first_cord, second_cord, (0, 89, 0), tolerance=30) find_look_right_2 = pixelMatchesColor(first_cord, second_cord, (0, 45, 0), tolerance=30) find_look_hard_left_1 = pixelMatchesColor(first_cord, second_cord, (46, 0, 93), tolerance=20) find_look_hard_left_2 = pixelMatchesColor(first_cord, second_cord, (36, 0, 72), tolerance=20) find_look_hard_right_1 = pixelMatchesColor(first_cord, second_cord, (178, 89, 0), tolerance=20) find_look_hard_right_2 = pixelMatchesColor(first_cord, second_cord, (197, 98, 0), tolerance=20) if find_look_left_1 or find_look_left_2: moveRel(-50,0, duration=0.17) elif find_look_right_1 or find_look_right_2: moveRel(40,0, duration=0.17) elif find_look_hard_left_1 or find_look_hard_left_2: moveRel(-110,0, duration=0.17) elif find_look_hard_right_1 or find_look_hard_right_2: moveRel(110,0, duration=0.17) else: return def attack(): #trys to see if a pixel im looking attack has moves my mouse a lot or little of my mouse while clicking. global click_one global click_two look_chance = 60#% first_cord, second_cord = position() attack_1 = pixelMatchesColor(first_cord, second_cord, (186, 112, 186), tolerance=20) attack_2 = pixelMatchesColor(first_cord, second_cord, (135, 81, 135), tolerance=30) if attack_1 or attack_2: chance = randint(1, 100) if chance <= look_chance: #print('Hit Chance ='+ str(chance)) if click_two == 1: #look main click() moveRel(3,2, duration=0.1) click_two = 2 else: if click_two == 2: #look back click() moveRel(-3,-2, duration=0.1) click_two = 1 elif click_one == 1: #big look main click() moveRel(-40,3, duration=0.17) click_one = 2 else: if click_one == 2: #big look back click() moveRel(40,-3, duration=0.17) click_one = 1 else: return def move(): #trys to see if a pixel im looking at then has moves from side to side. global move_one move_chance = 50#% first_cord, second_cord = position() find_move_1 = pixelMatchesColor(first_cord, second_cord, (169, 56, 93), tolerance=20) find_move_2 = pixelMatchesColor(first_cord, second_cord, (90, 18, 90), tolerance=30) find_move_3 = pixelMatchesColor(first_cord, second_cord, (203, 76, 127), tolerance=20) if find_move_1 or find_move_2 or find_move_3: chance = randint(1, 100) time_to_wait = uniform(0.12, 0.16) if chance <= move_chance: #print('Move Chance ='+ str(chance)) if move_one == 1: #main move keyDown('a') press('backspace') sleep(time_to_wait) keyUp('a') move_one = 2 elif move_one == 2:#move back keyDown('d') press('backspace') sleep(time_to_wait) keyUp('d') move_one = 1 else: return while fail_safe == 0: shut_down += 1 print(shut_down) if shut_down > 669: fail_safe = 1 first_cord, second_cord = position() #trys to see if a pixel im looking at is bad and stops it. bad_pixel = pixelMatchesColor(first_cord, second_cord, (0, 0, 0), tolerance=20) if bad_pixel: fail_safe = 1 print('SS!') #trys to see if a pixel im looking at then toggles on and off. toggler = pixelMatchesColor(first_cord, second_cord, (37, 0, 18), tolerance=10) if toggler: if on_off == 0: on_off = 1 print('Script toggled OFF!') sleep(2) elif on_off == 1: on_off = 0 print('Script toggled back ON!') sleep(2) if on_off == 0: look() attack() move()