Advertisement
BlissSilence

Untitled

Jan 13th, 2025 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. -- Script to monitor TPS (Ticks Per Second) in Minecraft using CC:Tweaked
  2. -- Ensure this script is run on a Computer or Advanced Computer
  3.  
  4. -- Configuration
  5. local updateInterval = 5 -- Time in seconds between TPS updates
  6.  
  7. -- Attach to the monitor
  8. local monitor = peripheral.find("monitor")
  9. if not monitor then
  10. error("No monitor found on side " .. monitorSide)
  11. end
  12.  
  13. monitor.setTextScale(1)
  14. monitor.clear()
  15. term.redirect(monitor)
  16.  
  17. -- Function to draw a horizontal bar using paintutils
  18. local function drawHorizontalBar(x, y, width, percentage, color)
  19. paintutils.drawLine(x, y, x + width - 1, y, colors.black) -- Clear the bar
  20. local filledWidth = math.floor(width * percentage)
  21. if filledWidth > 0 then
  22. paintutils.drawLine(x, y, x + filledWidth - 1, y, color)
  23. end
  24. end
  25.  
  26. -- Function to display TPS
  27. local function displayTPS(tps)
  28. monitor.clear()
  29. monitor.setCursorPos(1, 1)
  30. monitor.setTextColor(colors.white)
  31. monitor.write("Minecraft TPS Monitor")
  32.  
  33. monitor.setCursorPos(1, 3)
  34. monitor.write("Current TPS: " .. string.format("%.2f", tps))
  35.  
  36. local status, color
  37. if tps >= 19.0 then
  38. status = "Excellent"
  39. color = colors.green
  40. elseif tps >= 15.0 then
  41. status = "Good"
  42. color = colors.yellow
  43. elseif tps >= 10.0 then
  44. status = "Fair"
  45. color = colors.orange
  46. else
  47. status = "Poor"
  48. color = colors.red
  49. end
  50.  
  51. monitor.setCursorPos(1, 5)
  52. monitor.write("Status: " .. status)
  53.  
  54. -- Draw the horizontal bar to visually represent TPS
  55. local barWidth = 30 -- Adjust the width to fit your monitor size
  56. local x, y = 2, 7 -- Starting position of the bar
  57. local percentage = math.min(tps / 20, 1)
  58. drawHorizontalBar(x, y, barWidth, percentage, color)
  59. end
  60.  
  61. -- Function to fetch TPS
  62. local function getTPS()
  63. local tps = commands.exec("/forge tps allthemodium:the_beyond")
  64. if tps then
  65. local line = tps[2] -- Adjust this index if needed to capture the correct line
  66. local extractedTPS = line:match("Overall: (%d+%.?%d*)")
  67. return tonumber(extractedTPS) or 0
  68. end
  69. return 0
  70. end
  71.  
  72. -- Main loop
  73. while true do
  74. local tps = getTPS()
  75. displayTPS(tps)
  76. sleep(updateInterval)
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement