Apr-01-2018, 08:46 AM
How do I make it after it loops 670+ times it does not break. It stop working and starts to lag.
from time import sleep from random import uniform, randint from keyboard import wait, send, add_hotkey from pyautogui import pixelMatchesColor, keyDown, keyUp, moveRel, position, click, alert, typewrite fail_safe = 0 shut_down = 0 on_off = 0 click_one = 1 click_two = 1 move_one = 1 look_chance = 60#% move_chance = 50#% def toggle(): global on_off global fail_safe first_cord, second_cord = position() if pixelMatchesColor(first_cord, second_cord, (0, 0, 0), tolerance=20) is True: fail_safe = 1 print('STAY SAFE!') if pixelMatchesColor(first_cord, second_cord, (37, 0, 18), tolerance=10) is True: if on_off == 0: on_off = 1 print('Script toggled OFF!') elif on_off == 1: on_off = 0 print('Script toggled back ON!') else: return def look(): if on_off == 0: first_cord, second_cord = position() if pixelMatchesColor(first_cord, second_cord, (95, 95, 0), tolerance=20) is True or pixelMatchesColor(first_cord, second_cord, (148, 148, 0), tolerance=30) is True: moveRel(-50,0, duration=0.17) elif pixelMatchesColor(first_cord, second_cord, (0, 89, 0), tolerance=30) is True or pixelMatchesColor(first_cord, second_cord, (0, 45, 0), tolerance=30) is True: moveRel(40,0, duration=0.17) elif pixelMatchesColor(first_cord, second_cord, (46, 0, 93), tolerance=20) is True or pixelMatchesColor(first_cord, second_cord, (36, 0, 72), tolerance=20) is True: moveRel(-110,0, duration=0.17) elif pixelMatchesColor(first_cord, second_cord, (178, 89, 0), tolerance=20) is True or pixelMatchesColor(first_cord, second_cord, (197, 98, 0), tolerance=20) is True: moveRel(110,0, duration=0.17) else: return else: return def attack(): global click_two global click_one if on_off == 0: first_cord, second_cord = position() if pixelMatchesColor(first_cord, second_cord, (186, 112, 186), tolerance=20) is True or pixelMatchesColor(first_cord, second_cord, (135, 81, 135), tolerance=30) is True: chance = randint(1, 100) if chance <= look_chance: #print('Hit Chance ='+ str(chance)) if click_two == 1: click() moveRel(3,2, duration=0.1) click_two = 2 else: if click_two == 2: click() moveRel(-3,-2, duration=0.1) click_two = 1 elif click_one == 1: click() moveRel(-40,3, duration=0.17) click_one = 2 else: if click_one == 2: click() moveRel(40,-3, duration=0.17) click_one = 1 else: return else: return def move(): global move_one if on_off == 0: first_cord, second_cord = position() if pixelMatchesColor(first_cord, second_cord, (169, 56, 93), tolerance=20) is True or pixelMatchesColor(first_cord, second_cord, (90, 18, 90), tolerance=30) is True or pixelMatchesColor(first_cord, second_cord, (203, 76, 127), tolerance=20) is True: 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: keyDown('a') send('backspace') sleep(time_to_wait) keyUp('a') move_one = 2 elif move_one == 2: keyDown('d') send('backspace') sleep(time_to_wait) keyUp('d') move_one = 1 else: return else: return while fail_safe == 0: shut_down += 1 toggle() look() attack() move() if shut_down > 669: fail_safe = 1