class FoundEnemy(Exception):
pass
class triggerBot():
def __init__(self):
self.toggled = False
self.mode = 1
self.last_reac = 0
def toggle(self):
self.toggled = not self.toggled
def switch(self):
if self.mode != 2:
self.mode += 1
else:
self.mode = 0
if self.mode == 0:
winsound.Beep(200, 200)
if self.mode == 1:
winsound.Beep(200, 200)
winsound.Beep(200, 200)
if self.mode == 2:
winsound.Beep(200, 200)
winsound.Beep(200, 200)
winsound.Beep(200, 200)
def click(self):
ctypes.windll.user32.mouse_event(2, 0, 0, 0,0) # left down
ctypes.windll.user32.mouse_event(4, 0, 0, 0,0) # left up
def approx(self, r, g ,b):
return PURPLE_R - TOLERANCE < r < PURPLE_R + TOLERANCE and PURPLE_G - TOLERANCE < g < PURPLE_G + TOLERANCE and PURPLE_B - TOLERANCE < b < PURPLE_B + TOLERANCE
def grab(self):
with mss.mss() as sct:
bbox=(int(S_HEIGHT/2-GRABZONE), int(S_WIDTH/2-GRABZONE), int(S_HEIGHT/2+GRABZONE), int(S_WIDTH/2+GRABZONE))
sct_img = sct.grab(bbox)
# Convert to PIL/Pillow Image
return PIL.Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw', 'BGRX')
def scan(self):
start_time = time.time()
pmap = self.grab()
try:
for x in range(0, GRABZONE*2):
for y in range(0, GRABZONE*2):
r, g, b = pmap.getpixel((x,y))
if self.approx(r, g, b):
raise FoundEnemy
except FoundEnemy:
self.last_reac = int((time.time() - start_time)*1000)
self.click()
if self.mode == 0:
time.sleep(0.5)
if self.mode == 1:
time.sleep(0.25)
if self.mode == 2:
time.sleep(0.12)
print_banner(self)