Advertisement
DOGGYWOOF

Untitled

Jan 25th, 2025 (edited)
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. -- Function to get the time of day
  2. function getTimeOfDay()
  3. local time = os.time() % 24000 -- Minecraft's time cycle is 24000 ticks
  4. if time < 5000 then
  5. return "Day"
  6. elseif time < 10000 then
  7. return "Evening"
  8. elseif time < 13000 then
  9. return "Sunset"
  10. else
  11. return "Night"
  12. end
  13. end
  14.  
  15. -- Function to display the menu
  16. function displayMenu()
  17. print("===== In-game Timer Menu =====")
  18. print("1. View Current Time")
  19. print("2. Exit to GUI")
  20. print("Choose an option (1-2):")
  21. end
  22.  
  23. -- Function to handle menu input
  24. function handleMenuChoice(choice)
  25. if choice == "1" then
  26. -- Display the current time and time of day
  27. local timeOfDay = getTimeOfDay()
  28. local currentTime = os.time() % 24000
  29. print("Time: " .. currentTime .. " (" .. timeOfDay .. ")")
  30. elseif choice == "2" then
  31. -- Exit to GUI using shell.run
  32. print("Exiting to GUI...")
  33. shell.run("/disk/os/gui") -- Use shell.run to execute the command
  34. return true
  35. else
  36. print("Invalid choice. Please try again.")
  37. end
  38. return false
  39. end
  40.  
  41. -- Main loop
  42. while true do
  43. displayMenu()
  44. local choice = read() -- Wait for user input
  45. local exit = handleMenuChoice(choice)
  46. if exit then
  47. break -- Exit the loop if the user chooses option 2
  48. end
  49. sleep(1) -- Update every second
  50. end
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement