Advertisement
killer64

reactor panel

Dec 9th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local m=infutil.wrap("monitor")
  2. local re=infutil.wrap("generator")
  3. m.setTextScale(0.5)
  4. local Mx,My=m.getSize()
  5. local Cx,Cy=math.ceil(Mx/2),math.ceil(My/2)
  6.  
  7. m.setCursorPos(Cx-5,2)
  8. m.write("Main power")
  9. m.setCursorPos(Cx-4,8)
  10. m.write("Reactor")
  11. while true do
  12.     local st,mx=0,0
  13.     do -- Main power
  14.         for k,v in pairs(peripheral.getNames()) do
  15.             if peripheral.getType(v)=="batbox" then
  16.                 st=st+peripheral.call(v,"getStored")
  17.                 mx=mx+peripheral.call(v,"getCapacity")
  18.             end
  19.         end
  20.         st=math.min(st,mx)
  21.         local i=math.ceil((st/mx)*(Mx-3))
  22.         for l=4,6 do
  23.             m.setBackgroundColor(colors.green)
  24.             m.setCursorPos(2,l)
  25.             m.write(string.rep(" ",i))
  26.             m.setBackgroundColor(colors.red)
  27.             m.write(string.rep(" ",math.max(0,(Mx-3)-i)))
  28.         end
  29.         local t=(math.floor((st/mx)*1000)/10).."% ["..tostring(st):reverse():gsub("...","%1,"):reverse().."/"..tostring(mx):reverse():gsub("...","%1,"):reverse().." EU]"
  30.         local n=math.max(0,i-(Cx-math.floor(#t/2))+2)
  31.         m.setBackgroundColor(colors.green)
  32.         m.setCursorPos(Cx-math.floor(#t/2),5)
  33.         m.setTextColor(colors.black)
  34.         m.write(t:sub(1,n))
  35.         m.setBackgroundColor(colors.red)
  36.         m.write(t:sub(n+1))
  37.     end
  38.     do -- Reactor
  39.         m.setTextColor(colors.white)
  40.         m.setBackgroundColor(colors.black)
  41.         m.setCursorPos(2,10)
  42.         m.clearLine()
  43.         m.write("Status: ")
  44.         if re.getOutput()~=0 then
  45.             m.setTextColor(colors.green)
  46.             m.write("ON")
  47.         else
  48.             m.setTextColor(colors.red)
  49.             m.write("OFF")
  50.         end
  51.         m.setTextColor(colors.white)
  52.         m.setCursorPos(2,11)
  53.         m.clearLine()
  54.         m.write("Cycle: ")
  55.         local p=re.getStackInSlot(20)
  56.         if re.getOutput()~=0 and p then
  57.             local r=math.floor(p.dmg/8)
  58.             local sc=tostring(math.floor(r%60))
  59.             m.write((100-math.floor((p.dmg/10000)*1000)/10).."% ["..math.floor(r/60)..":"..string.rep("0",2-#sc)..sc.."]")
  60.         else
  61.             m.write("N/A")
  62.         end
  63.     end
  64.     sleep(1)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement