Advertisement
LivioBrunner

Energy Control 3.0

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