LivioBrunner

Untitled

Apr 19th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. function load(name)
  2.   local file = fs.open(name,"r")
  3.   local data = file.readAll()
  4.   file.close()
  5.   return textutils.unserialize(data)
  6. end
  7. function save(table,name)
  8.   local file = fs.open(name,"w")
  9.   file.write(textutils.serialize(table))
  10.   file.close()
  11. end
  12. function tablelength(T)
  13.   local count = 0
  14.   for _ in pairs(T) do count = count + 1 end
  15.   return count
  16. end
  17. local function centerText(text)
  18.     local x,y = term.getSize()
  19.     local x2,y2 = term.getCursorPos()
  20.     term.setCursorPos(math.floor((x / 2) - (string.len(text) / 2)), y2)
  21.     write(text)
  22. end
  23. function create(x,y,width,height,color,mon)
  24.     mon.setCursorPos(x,y)
  25.         for j = 0, height do
  26.         mon.setCursorPos(x,y+j)
  27.         for i = 0,width do
  28.             mon.setBackgroundColor(color)
  29.             mon.write(" ")
  30.         end
  31.     end
  32. end
  33. function clearAll(mon, color)
  34.     local w,h = mon.getSize()
  35.     for i = 0,h do
  36.         for j = 0, w do
  37.             mon.setCursorPos(1+j,1+i)
  38.             mon.setBackgroundColor(color)
  39.             mon.write(" ")
  40.         end
  41.     end
  42. end
  43. function file_exists(name)
  44.    local f=io.open(name,"r")
  45.    if f~=nil then io.close(f) return true else return false end
  46. end
  47.  
  48. local all = 0
  49. local version = "2.0"
  50. local mfsu = {}
  51. local strom = {}
  52. local length = 0
  53. local counter = 0
  54. local stopIt = false
  55.  
  56. term.clear()
  57.  
  58.  
  59.  
  60. function getAllEU()
  61.         local all = 0
  62.     for i = mfsu[1], tablelength(mfsu)+mfsu[1]-1 do
  63.         all = all + strom[i]
  64.     end
  65.     return all
  66. end
  67.  
  68. function progressBar()
  69.  
  70. mfsu = load("saves/id")
  71. for i = mfsu[1], tablelength(mfsu)+mfsu[1]-1 do
  72.     nb = peripheral.wrap("mfsu_" .. i)
  73.     EU = nb.getEUStored()
  74.     strom[i] = EU
  75.   end
  76.    term.write(getAllEU() .."/".. (tablelength(mfsu) * 40000000).."EU")
  77.    sleep(1)
  78. end
  79. function startMessage()
  80.     clearAll(term,colors.blue)
  81.     term.setTextColor(colors.white)
  82.     term.setCursorPos(1,1)
  83.     centerText("Welcome to Sutrang's Glass Version ".. version)
  84.     sleep(1)
  85. end
  86. function settings()
  87.     term.clear()
  88.     term.setCursorPos(1,1)
  89.     local w, h = term.getSize()
  90.     create(0,0,w, h, colors.blue,term)
  91.     term.setTextColor(colors.white)
  92.     startMessage()
  93.     term.setCursorPos(1,3)
  94.     centerText("Network Cable Side:")
  95.     networkcableside = read()
  96.     save(networkcableside, "saves/networkcable")
  97.     term.setCursorPos(1,5)
  98.     centerText("Name your MFSU's:")
  99.     name = read()
  100.     save(name, "saves/name")
  101.     while stopIt ~= true do
  102.         counter = counter + 1
  103.         term.setCursorPos(1,8 + counter)
  104.         centerText("Write id of your MFSU's:")
  105.         message = read()
  106.         if message == "" then
  107.             stopIt = true
  108.             term.clearLine()
  109.         else
  110.             table.insert(mfsu, message)
  111.         end
  112.     end
  113.     save(mfsu, "saves/id")
  114.     startMessage()
  115. end
  116.  
  117.  
  118. --{MAIN PROGRAMM}--
  119. --{INIT}--
  120. fs.makeDir("saves")
  121. term.clear()
  122. term.setCursorPos(1,1)
  123.  
  124. if fs.exists("saves/id") ~= true then
  125.     settings()
  126. end
  127. networkcableside = load("saves/networkcable")
  128.  
  129. nb = peripheral.wrap(networkcableside)
  130. while true do
  131.     progressBar()
  132. end
  133. --{INIT}--
Advertisement
Add Comment
Please, Sign In to add comment