Advertisement
NuAoA

Get the TPS of the /r/FTB server

Apr 19th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. local comp_faces = {"Front","Back","Left","Right","Top","Bottom"}
  2. local mon = nil
  3. for i=1,#comp_faces do
  4.                 if peripheral.getType(string.lower(comp_faces[i])) == "monitor" then                          
  5.                                 mon = peripheral.wrap( string.lower(comp_faces[i]))                    
  6.                 end
  7. end
  8.  
  9.  
  10. function getTime()
  11.         http.request("http://alienmc.co/checkTPS.php")
  12.         local requesting = true
  13.         local valid = false
  14.         local respondedText = ""
  15.         while requesting do
  16.                 local event, url, sourceText = os.pullEvent()
  17.                 if event == "http_success" then
  18.                         respondedText = sourceText.readAll()                  
  19.                         valid = true
  20.                         requesting = false
  21.                 elseif event == "http_failure" then                    
  22.                         requesting = false
  23.                 end
  24.         end
  25.                        
  26.         return tonumber(string.match(respondedText,"(%d+).%d+")) +tonumber(string.match(respondedText,"%d+.(%d+)"))/10
  27.        
  28.        
  29. end
  30.  
  31. while true do
  32.         local currTick = getTime()
  33.         if mon ~= nil then
  34.                 mon.clear()
  35.                 mon.setTextScale(2)
  36.   mon.setTextColor(colors.white)
  37.                 local x,y = mon.getSize()
  38.                 mon.setCursorPos(x/2 - 3,y/2)
  39.                 mon.write("TPS: ")
  40.                 if currTick < 6 then
  41.                         mon.setTextColor(colors.red)
  42.                 elseif currTick >= 6 and currTick < 15 then
  43.                         mon.setTextColor(colors.yellow)
  44.                 else
  45.                         mon.setTextColor(colors.green)
  46.                 end
  47.                 mon.write(currTick)
  48.         else
  49.                 print("TPS: "..currTick)
  50.         end
  51.         sleep(20)
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement