Hi.
As a learning exercise I decided to write a simple pixel bot for a game. It consists of 3 modules that I would like to run at the same time:
Walking(cavebot), targetting, healing. They work well as separate scripts, but I can't seem to "connect" them together.
Using some internet resources, I've decided to run them all using GUI script:
Targetting used to work solo:
Cavebot is the most difficult one for me. It used to work solo, but I need it to do the actions only if the "czekaj" variable from targetting is False. I honestly have no idea how to properly import it from one script to another as nothing seems to work, especially considering the fact that I want it changed before the actions in targetting are done, not after that (this could work with "return True" but then the cavebot would work through the actions of the loop in targetting, atleast thats how I understand it)
As a learning exercise I decided to write a simple pixel bot for a game. It consists of 3 modules that I would like to run at the same time:
Walking(cavebot), targetting, healing. They work well as separate scripts, but I can't seem to "connect" them together.
Using some internet resources, I've decided to run them all using GUI script:
import tkinter as tk
import threading
from engine import cavebot, targetting, healing
def set_cavebot_running(value):
global cavebot_running
cavebot_running = value
if value:
threading.Thread(target=run_cavebot).start()
def set_targetting_running(value):
global targetting_running
targetting_running = value
if value:
threading.Thread(target=run_targetting).start()
def set_healing_running(value):
global healing_running
healing_running = value
if value:
threading.Thread(target=run_healing).start()
def run_cavebot():
while cavebot_running:
cavebot.walking()
def run_targetting():
while targetting_running:
targetting.attacking()
def run_healing():
while healing_running:
healing.leczenie()
root = tk.Tk()
root.title("Cavebot and Targetting Control")
cavebot_running = False
cavebot_start_button = tk.Button(root, text="Start Cavebot", command=lambda: set_cavebot_running(True))
cavebot_start_button.pack()
cavebot_stop_button = tk.Button(root, text="Stop Cavebot", command=lambda: set_cavebot_running(False))
cavebot_stop_button.pack()
targetting_running = False
targetting_start_button = tk.Button(root, text="Start Targetting", command=lambda: set_targetting_running(True))
targetting_start_button.pack()
targetting_stop_button = tk.Button(root, text="Stop Targetting", command=lambda: set_targetting_running(False))
targetting_stop_button.pack()
healing_running = False
healing_start_button = tk.Button(root, text="Start healing", command=lambda: set_healing_running(True))
healing_start_button.pack()
healing_stop_button = tk.Button(root, text="Stop healing", command=lambda: set_healing_running(False))
healing_stop_button.pack()
root.mainloop()turning them on works, turning them off doesn't, also, they seem to only workif the GUI is "on top", while pausing if its hidden under the game window.Targetting used to work solo:
import pyautogui
import time
global czekaj
target = False
zaatakowane = False
czekaj = False
confidence = 0.8
interval = 0.5
def attacking():
while True:
if not pyautogui.locateOnScreen('engine/empty.png', confidence=confidence):
time.sleep(0.5)
pyautogui.click(335, 315)
time.sleep(0.1)
pyautogui.press('space')
target = True
czekaj = True
zaatakowane = True
print("Target acquired, zaatakowane = True")
time.sleep(interval)
if zaatakowane:
while pyautogui.locateOnScreen('engine/attk.png', confidence=confidence):
time.sleep(1)
print("Attacking")
zaatakowane = True
else:
print("not attacking, proceed to loot")
zaatakowane = False
time.sleep(interval)
else:
czekaj = False
target = False
zaatakowane = False
print("No target", czekaj, target, zaatakowane)
time.sleep(interval)Now it works when conditions for the last else are met, but crashes without error if the empty.png file is not found.Cavebot is the most difficult one for me. It used to work solo, but I need it to do the actions only if the "czekaj" variable from targetting is False. I honestly have no idea how to properly import it from one script to another as nothing seems to work, especially considering the fact that I want it changed before the actions in targetting are done, not after that (this could work with "return True" but then the cavebot would work through the actions of the loop in targetting, atleast thats how I understand it)
import pyautogui
import time
from engine import targetting
global czekaj
minimap_center = (910, 103)
images = ['engine/lock.png', 'engine/teststar1.png']
def walking():
while True:
while czekaj is False:
for image in images:
if pyautogui.locateOnScreen(image, region=(857, 51, 115, 115), confidence=0.7) != None:
print("I can see it", image)
wptcenter = pyautogui.locateCenterOnScreen(image, confidence=0.7)
print(wptcenter)
pyautogui.click(wptcenter)
print("moved to", image)
time.sleep(2)
if wptcenter == minimap_center:
print("reached", image)
if image != 'lock.png':
print('wpt walk done')
time.sleep(1)
else:
wptcenter = pyautogui.locateCenterOnScreen(image, confidence=0.7)
pyautogui.click(wptcenter)
time.sleep(2)
print('roping')
pyautogui.press('f12')
pyautogui.click(337,316)
time.sleep(1)
else:
while wptcenter != minimap_center:
wptcenter = pyautogui.locateCenterOnScreen(image, confidence=0.7)
pyautogui.click(wptcenter)
print("clicking")
time.sleep(1)
else:
print("I am unable to see it")
time.sleep(0.5)
else:
time.sleep(1)I know its a lot of useless code and I've probably done it in the most illogical way possible, but any suggestion would be appreciated as a learning experience.
