NMDanny

Untitled

Apr 15th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. local chan=39701
  2. local monitor=peripheral.wrap("monitor_6")
  3. local modem=peripheral.wrap("left")
  4. modem.open(chan)
  5.  
  6.  
  7.         local width,height=monitor.getSize()
  8.         monitor.clear()
  9.         monitor.setBackgroundColor(colors.purple)
  10.         monitor.setTextColor(colors.yellow)
  11.         monitor.setCursorPos(1,1)
  12.         monitor.write("Energy Cell Management"..string.rep(" ",width-#"Energy Cell Management"))
  13.         monitor.setTextScale(.5)
  14.        
  15.        
  16.         local writeFormat={[1]={"Maximum Energy Stored: "," RF"},[2]={"Energy Stored: "," RF"},[3]={"Energy Percent: ","%"}}
  17.         local reporters={}
  18.        
  19. while true do
  20.         monitor.setBackgroundColor(colors.black)
  21.         monitor.setTextColor(colors.white)
  22.         for row=1,height do
  23.                 monitor.write(string.rep(" ",width))
  24.         end
  25.         local totalData={0,0,0}
  26.         local event={os.pullEvent()}
  27.  
  28.         if event[1]=="monitor_touch" then
  29.         print("Monitor touch detected")
  30.         if quit.clicked(event[3],event[4])==true then
  31.                         monitor.clear()
  32.                         break
  33.                 end
  34.         elseif event[1]=="key" and event[2]==keys.q then
  35.                 monitor.clear()
  36.                 break
  37.         elseif event[1]=="modem_message" and event[3]==chan then
  38.                 local data={}
  39.                 --print(event[5])
  40.                 for word in string.gmatch(event[5],"[^%s]+") do
  41.                         table.insert(data,word)
  42.                 end
  43.                 reporters[data[1]]={[1]=data[2],[2]=data[3],[3]=data[4]}
  44.         end
  45.         local maxLength=#writeFormat[1][1]
  46.         local currentRow=3
  47.         for key,value in pairs(reporters) do
  48.                 monitor.setCursorPos(1,currentRow)
  49.                 monitor.write(key..": ")
  50.                 currentRow=currentRow+1
  51.                 for key2,value2 in ipairs(reporters[key]) do
  52.                         monitor.setCursorPos(3,currentRow)
  53.                         monitor.write(string.rep(" ",maxLength-#writeFormat[key2][1])..writeFormat[key2][1]..value2..writeFormat[key2][2])
  54.                         totalData[key2]=totalData[key2]+value2
  55.                         currentRow=currentRow+1
  56.                 end
  57.                 currentRow=currentRow+1
  58.         end
  59.         totalData[3]=math.floor(100*(totalData[2]/totalData[1]))
  60.         monitor.setCursorPos(1,currentRow)
  61.         monitor.write("Total Energy Grid Information: ")
  62.         currentRow=currentRow+1
  63.         for i=1,3 do
  64.                 monitor.setCursorPos(3,currentRow)
  65.                 monitor.write(string.rep(" ",maxLength-#writeFormat[i][1])..writeFormat[i][1]..totalData[i]..writeFormat[i][2])
  66.                 currentRow=currentRow+1
  67.         end
  68.                
  69.  
  70. end
Advertisement
Add Comment
Please, Sign In to add comment