Advertisement
CelticCoder

gpsMiddle

May 12th, 2024 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Function to run your custom code
  2. local function runCustomCode()
  3.     x =
  4.     y =
  5.     z =
  6.     shell.run("gps", "host", x, y, z)
  7. end
  8.  
  9. local function wait()
  10.     os.sleep(4)
  11. end
  12.  
  13. -- Function to reboot the computer
  14. local function rebootComputer()
  15.     print("Rebooting computer...")
  16.     os.sleep(1) -- Optional: Wait for 1 second before rebooting
  17.     os.reboot() -- Reboot the computer
  18. end
  19.  
  20. -- Function to determine if it's the first run
  21. local function isFirstRun()
  22.     -- Check if a file indicating the first run exists
  23.     return not fs.exists("first_run")
  24. end
  25.  
  26. -- Function to mark subsequent runs
  27. local function markFirstRun()
  28.     -- Create a file to mark the first run
  29.     local file = fs.open("first_run", "w")
  30.     file.close()
  31. end
  32.  
  33. -- Function to delete the "first_run" file
  34. local function deleteFirstRun()
  35.     -- Delete the "first_run" file if it exists
  36.     if fs.exists("first_run") then
  37.         fs.delete("first_run")
  38.     end
  39. end
  40.  
  41. -- Main function to start the process
  42. local function main()
  43.     -- Check if it's the first run
  44.     if isFirstRun() then
  45.         -- Start the computer
  46.         print("Starting computer...")
  47.         -- Optional: Wait for 1 second before running custom code
  48.         os.sleep(1)
  49.         -- Run your custom code
  50.         parallel.waitForAny(
  51.             function() runCustomCode() end,
  52.             function() wait() end
  53.         )
  54.         -- Mark subsequent runs
  55.         markFirstRun()
  56.         -- Reboot the computer
  57.         rebootComputer()
  58.     else
  59.         -- Delete the "first_run" file
  60.         deleteFirstRun()
  61.         -- Run your custom code directly
  62.         runCustomCode()
  63.     end
  64. end
  65.  
  66. -- Call the main function to start the process
  67. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement