Advertisement
Guest User

startup

a guest
Mar 31st, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. fuso=0
  2.  
  3. function getHora()
  4.   local resposta = http.get("http://www.timeapi.org/utc/now")
  5.   if resposta then
  6.     local sResposta = resposta.readAll()
  7.     resposta.close()
  8.     for i=1,#sResposta,1 do
  9.       if string.sub(sResposta,i,i) == "T" then
  10.         nxt=i + 1
  11.         break
  12.       end
  13.     end
  14.     local hora = string.sub(sResposta,nxt,nxt+1) + fuso
  15.     local minuto = string.sub(sResposta,nxt+3,nxt+4) + 0
  16.     local segundo = string.sub(sResposta,nxt+6,nxt+7) + 0
  17.     if hora < 0 then
  18.       hora = hora + 24
  19.     end
  20.     return hora, minuto, segundo
  21.   else
  22.     return false
  23.   end
  24. end
  25.  
  26. function getTPS()
  27.   print("Conectando 1")
  28.   while not hora1 do
  29.     hora1, minuto1, segundo1 = getHora()
  30.   end
  31.   local segundos1=os.clock()
  32.   local resultado1 = hora1 * 3600 + minuto1 * 60 + segundo1
  33.   for i=5,0,-1 do
  34.     print(i .. " segundo(s)...")
  35.     sleep(1)
  36.   end
  37.   print("Conectando 2")
  38.   while not hora2 do
  39.     hora2, minuto2, segundo2 = getHora()
  40.   end
  41.   local segundos2=os.clock()
  42.   local resultado2 = hora2 * 3600 + minuto2 * 60 + segundo2
  43.   resultado1 = resultado2 - resultado1
  44.   segundos1 = segundos2 - segundos1
  45.   tps=segundos1 * 20 / resultado1
  46.   print("Tempo decorrido do jogo: " .. segundos1 .. "s")
  47.   print("Tempo decorrido real: " .. resultado1 .. "s")
  48.   print("TPS: " .. tps)
  49.   hora1=nil
  50.   hora2=nil
  51.   return segundos1 * 20 / resultado1
  52. end
  53.  
  54.  
  55. function config()
  56.   if fs.exists("configs") then
  57.     if not configs then
  58.       f = fs.open("configs","r")
  59.       configs=textutils.unserialize(f.readAll())
  60.       f.close()
  61.     else
  62.       f = fs.open("configs","w")
  63.       f.writeLine(textutils.serialize(configs))
  64.       f.close()
  65.     end
  66.   else
  67.     configs={}
  68.     f = fs.open("configs","w")
  69.     f.writeLine(configs)
  70.     f.close()
  71.   end
  72. end
  73.  
  74. config()
  75. while true do
  76.   print("Calculo n:" .. #configs + 1)
  77.   table.insert(configs,getTPS())
  78.   config()
  79.   print("--------------------------")
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement