RylofScripts

Py Script Badlands

Oct 1st, 2023 (edited)
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.72 KB | None | 0 0
  1. --- python script to autorejoin lobby after 20 minutes. For badlands
  2.  
  3. -- if you are having problems getting the script to work, ask chatGPT how to run this script.
  4.  
  5. import psutil
  6. import time
  7. import webbrowser
  8. import logging
  9.  
  10. logging.basicConfig(level=logging.INFO)
  11.  
  12. def is_process_running(process_name):
  13.     try:
  14.         for process in psutil.process_iter(attrs=['pid', 'name']):
  15.             current_process = process.info['name']
  16.             logging.info(f"Checking process: {current_process}")
  17.             if current_process == process_name:
  18.                 return True, process.info['pid']
  19.     except Exception as e:
  20.         logging.error(f"An error occurred: {e}")
  21.     return False, None
  22.  
  23. def terminate_process(pid):
  24.     try:
  25.         process = psutil.Process(pid)
  26.         process.terminate()
  27.         logging.info(f"Terminated process with PID: {pid}")
  28.     except Exception as e:
  29.         logging.error(f"An error occurred while terminating the process: {e}")
  30.  
  31. def main():
  32.     process_name = "Windows10Universal.exe"  # Replace with the exact name you see in Task Manager
  33.     check_interval = 7  # time in seconds to check if process is running
  34.     termination_timer = 11 * 60  # Change this to a sensible amount
  35.     relaunch_check_interval = 1 * 60  # 5 minutes in seconds
  36.    
  37.     while True:
  38.         time.sleep(check_interval)
  39.         logging.info("Checking if the process is running...")
  40.        
  41.         is_running, pid = is_process_running(process_name)
  42.        
  43.         if not is_running:
  44.             logging.info(f"Process {process_name} is not running. Opening Roblox...")
  45.             url = "roblox://placeID=3260590327"
  46.             webbrowser.open_new(url)
  47.         else:
  48.             logging.info(f"Process {process_name} is running. Waiting {str(termination_timer)} minutes before termination.")
  49.            
  50.             time_remaining = termination_timer
  51.             while time_remaining > 0:
  52.                 time.sleep(min(time_remaining, relaunch_check_interval))
  53.                 time_remaining -= relaunch_check_interval
  54.                
  55.                 # Recheck if the process is still running during the termination timer
  56.                 is_running, new_pid = is_process_running(process_name)
  57.                 if not is_running:
  58.                     logging.info(f"Process {process_name} is not running anymore. Resetting timer and relaunching...")
  59.                     url = "roblox://placeID=3260590327"
  60.                     webbrowser.open_new(url)
  61.                     time_remaining = termination_timer  # Reset the timer
  62.                 else:
  63.                     pid = new_pid  # Update PID in case it has changed
  64.            
  65.             terminate_process(pid)
  66.  
  67. if __name__ == "__main__":
  68.     main()
  69.  
Advertisement
Add Comment
Please, Sign In to add comment