yeeeeeeeeeeeee

time

May 3rd, 2025
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. -- DEVICES
  2. monitor = peripheral.wrap("")
  3.  
  4.  
  5.  
  6. -- VARIABLES
  7. local width, height = monitor.getSize()
  8. local defaultText = colours.white
  9. local defaultBackground = colours.black
  10.  
  11.  
  12.  
  13. -- FUNCTIONS
  14.  
  15. -- Sets everything up before running
  16. function setup()
  17.     monitor.setBackgroundColour(defaultBackground)
  18.     monitor.setTextColour(defaultText)
  19.     monitor.clear()
  20. end
  21.  
  22. -- Prints stuff to the screen
  23. function print2Screen(line, colour, text)
  24.     -- Centers Cursor in line and clears line
  25.     monitor.setCursorPos(width/2-#text/2, line)
  26.     monitor.clearLine()
  27.    
  28.     -- Print to screen
  29.     if colour == nil then
  30.         -- no colour given
  31.         monitor.setTextColour(defaultText)
  32.     else
  33.         -- colour given
  34.         monitor.setTextColour(colour)
  35.     end
  36.     monitor.write(text)
  37.    
  38.     -- Colour reset
  39.     monitor.setTextColour(defaultText)
  40. end
  41.  
  42. -- Gets the current time (true -> 12h format)
  43. function getTime(isInsane)
  44.     local time = ""
  45.     local tizn = os.date("%z")
  46.    
  47.     if isInsane then
  48.         -- 12h format
  49.         time = os.date("%r")
  50.     else
  51.         -- 24h format
  52.         time = os.date("%H:%M:%S   ")
  53.     end
  54.    
  55.     return tostring(time.." UTC"..tizn)
  56. end
  57.  
  58. -- Gets the current date (true -> american date format)
  59. function getDate(isInsane)
  60.     local date = ""
  61.    
  62.     if isInsane then
  63.         -- american date format
  64.         date = os.date("%D")
  65.     else
  66.         -- normal date format
  67.         date = os.date("%d.%m.%Y")
  68.     end
  69.    
  70.     return date
  71. end
  72.  
  73. -- Gets Minecraft Day
  74. function getMCDay()
  75.     return os.day()
  76. end
  77.  
  78. -- Gets Minecraft Time
  79. function getMCTime(isInsane)
  80.     return textutils.formatTime(os.time(), not isInsane)
  81. end
  82.  
  83.  
  84.  
  85. -- MAIN LOOP
  86. print("Script running since: "..os.date())
  87. print("Monitor dimensions: "..width.."x"..height)
  88.  
  89. setup()
  90. print2Screen(1, colours.grey, "Server Time:")
  91. print2Screen(6, colours.grey, "Minecraft Time:")
  92. while true do
  93.     -- EXAMPLES:
  94.     -- Server Time:
  95.     print2Screen(2, colours.yellow, getTime())
  96.     print2Screen(4, colours.orange, getDate())
  97.    
  98.     -- Minecraft Time:
  99.     print2Screen(7, colours.pink, getMCTime())
  100.     print2Screen(9, colours.purple, "Day: "..getMCDay())
  101.    
  102.     -- Update Frequency
  103.     os.sleep(0.5)
  104. end
Add Comment
Please, Sign In to add comment