Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- python script to autorejoin lobby after 20 minutes. For badlands
- -- if you are having problems getting the script to work, ask chatGPT how to run this script.
- import psutil
- import time
- import webbrowser
- import logging
- logging.basicConfig(level=logging.INFO)
- def is_process_running(process_name):
- try:
- for process in psutil.process_iter(attrs=['pid', 'name']):
- current_process = process.info['name']
- logging.info(f"Checking process: {current_process}")
- if current_process == process_name:
- return True, process.info['pid']
- except Exception as e:
- logging.error(f"An error occurred: {e}")
- return False, None
- def terminate_process(pid):
- try:
- process = psutil.Process(pid)
- process.terminate()
- logging.info(f"Terminated process with PID: {pid}")
- except Exception as e:
- logging.error(f"An error occurred while terminating the process: {e}")
- def main():
- process_name = "Windows10Universal.exe" # Replace with the exact name you see in Task Manager
- check_interval = 7 # time in seconds to check if process is running
- termination_timer = 11 * 60 # Change this to a sensible amount
- relaunch_check_interval = 1 * 60 # 5 minutes in seconds
- while True:
- time.sleep(check_interval)
- logging.info("Checking if the process is running...")
- is_running, pid = is_process_running(process_name)
- if not is_running:
- logging.info(f"Process {process_name} is not running. Opening Roblox...")
- url = "roblox://placeID=3260590327"
- webbrowser.open_new(url)
- else:
- logging.info(f"Process {process_name} is running. Waiting {str(termination_timer)} minutes before termination.")
- time_remaining = termination_timer
- while time_remaining > 0:
- time.sleep(min(time_remaining, relaunch_check_interval))
- time_remaining -= relaunch_check_interval
- # Recheck if the process is still running during the termination timer
- is_running, new_pid = is_process_running(process_name)
- if not is_running:
- logging.info(f"Process {process_name} is not running anymore. Resetting timer and relaunching...")
- url = "roblox://placeID=3260590327"
- webbrowser.open_new(url)
- time_remaining = termination_timer # Reset the timer
- else:
- pid = new_pid # Update PID in case it has changed
- terminate_process(pid)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment