Advertisement
DOGGYWOOF

Untitled

Nov 7th, 2024 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. -- Simple shutdown and reboot after 3 seconds
  2. local function shutdownscreen(reboot)
  3. -- Colors for the screen
  4. local bgcolor = colors.cyan
  5. local txtcolor = colors.white
  6.  
  7. -- Function to render the shutdown or reboot message
  8. local function render()
  9. term.setBackgroundColor(bgcolor)
  10. term.clear()
  11. term.setTextColor(txtcolor)
  12. term.setCursorPos(1, 1)
  13. if reboot then
  14. print("Restarting in 3 seconds...")
  15. else
  16. print("Shutting down in 3 seconds...")
  17. end
  18. end
  19.  
  20. -- Render the screen
  21. render()
  22. os.sleep(3) -- Wait for 3 seconds before proceeding
  23.  
  24. -- Perform the shutdown or reboot using _G.os to access the original methods
  25. if reboot then
  26. _G.os.reboot() -- Call the original reboot behavior from _G
  27. else
  28. _G.os.shutdown() -- Call the original shutdown behavior from _G
  29. end
  30. end
  31.  
  32. -- Override os.shutdown and os.reboot to prevent loops
  33. local original_shutdown = _G.os.shutdown
  34. local original_reboot = _G.os.reboot
  35.  
  36. function _G.os.shutdown()
  37. shutdownscreen(false) -- Call with false for shutdown
  38. os.exit() -- Prevent further triggering after shutdown
  39. end
  40.  
  41. function _G.os.reboot()
  42. shutdownscreen(true) -- Call with true for reboot
  43. os.exit() -- Prevent further triggering after reboot
  44. end
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement