Advertisement
Cpone

startup

Jun 28th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.93 KB | None | 0 0
  1. local bedrockPath='/' if OneOS then OneOS.LoadAPI('/System/API/Bedrock.lua', false)elseif fs.exists(bedrockPath..'/Bedrock')then os.loadAPI(bedrockPath..'/Bedrock')else if http then print('Downloading Bedrock...')local h=http.get('http://pastebin.com/raw.php?i=0MgKNqpN')if h then local f=fs.open(bedrockPath..'/Bedrock','w')f.write(h.readAll())f.close()h.close()os.loadAPI(bedrockPath..'/Bedrock')else error('Failed to download Bedrock. Is your internet working?') end else error('This program needs to download Bedrock to work. Please enable HTTP.') end end if Bedrock then Bedrock.BasePath = bedrockPath Bedrock.ProgramPath = shell.getRunningProgram() end
  2.  
  3. local monitor = peripheral.wrap( "right" )
  4.  
  5. local barrels_drums = {}
  6.  
  7. for k, v in pairs( peripheral.getNames() ) do
  8.     if ( peripheral.getType(v) == "drum" or peripheral.getType(v) == "mcp_mobius_betterbarrel" ) then
  9.         table.insert( barrels_drums, v )
  10.     end
  11. end
  12.  
  13. term.redirect( monitor )
  14. monitor.setTextScale( 1 )
  15.  
  16. local page = 1
  17. local maxpage = math.ceil( table.getn( barrels_drums ) / 4 )
  18.  
  19. local program = Bedrock:Initialise()
  20.  
  21. function format_thousand(v)
  22.     local s = string.format("%d", math.floor(v))
  23.     local pos = string.len(s) % 3
  24.     if pos == 0 then pos = 3 end
  25.     return string.sub(s, 1, pos)
  26.     .. string.gsub(string.sub(s, pos+1), "(...)", ",%1")
  27. end
  28.  
  29. program:StartRepeatingTimer(function()
  30.     local pageText = "Page: " .. tostring( page )
  31.  
  32.     -- Object 1
  33.     local object1Name = "N/A"
  34.     local object1Quantity = 0
  35.     local object1Max = 0
  36.     local object1Text = "N/A - N/A"
  37.     local object1Decimal = 0
  38.        
  39.     if not ( barrels_drums[ ( ( page - 1 ) * 4 ) + 1 ] == nil ) then
  40.         local object1 = peripheral.wrap( barrels_drums[ ( ( page - 1 ) * 4 ) + 1 ] )
  41.         local object1Type = peripheral.getType( barrels_drums[ ( ( page - 1 ) * 4 ) + 1 ] )
  42.        
  43.         if ( object1Type == "mcp_mobius_betterbarrel" ) then
  44.             if not ( object1.getStoredItems() == nil ) then
  45.                 object1Name = object1.getStoredItems().display_name
  46.                 object1Quantity = object1.getStoredItems().qty
  47.                 object1Max = object1.getMaxStoredItems()
  48.                 object1Text = object1Name .. " - " .. format_thousand( object1Quantity ) .. " / " .. format_thousand( object1Max )
  49.             end
  50.         elseif ( object1Type == "drum" ) then
  51.             if not ( object1.getTankInfo()[1].contents == nil ) then
  52.                 object1Name = object1.getTankInfo()[1].contents.rawName
  53.                 object1Quantity = object1.getTankInfo()[1].contents.amount
  54.                 object1Max = object1.getTankInfo()[1].capacity
  55.                 object1Text = object1Name .. " - " .. format_thousand( object1Quantity ) .. " / " .. format_thousand( object1Max ) .. " mB"
  56.             end
  57.         end
  58.        
  59.         object1Decimal = object1Quantity / object1Max
  60.     end
  61.    
  62.     -- Object 2
  63.     local object2Name = "N/A"
  64.     local object2Quantity = 0
  65.     local object2Max = 0
  66.     local object2Text = "N/A - N/A"
  67.     local object2Decimal = 0
  68.    
  69.     if not ( barrels_drums[ ( ( page - 1 ) * 4 ) + 2 ] == nil ) then
  70.         local object2 = peripheral.wrap( barrels_drums[ ( ( page - 1 ) * 4 ) + 2 ] )
  71.         local object2Type = peripheral.getType( barrels_drums[ ( ( page - 1 ) * 4 ) + 2 ] )
  72.        
  73.         if ( object2Type == "mcp_mobius_betterbarrel" ) then
  74.             if not ( object2.getStoredItems() == nil ) then
  75.                 object2Name = object2.getStoredItems().display_name
  76.                 object2Quantity = object2.getStoredItems().qty
  77.                 object2Max = object2.getMaxStoredItems()
  78.                 object2Text = object2Name .. " - " .. format_thousand( object2Quantity ) .. " / " .. format_thousand( object2Max )
  79.             end
  80.         elseif ( object2Type == "drum" ) then
  81.             if not ( object2.getTankInfo().contents == nil ) then
  82.                 object2Name = object2.getTankInfo()[1].contents.rawName
  83.                 object2Quantity = object2.getTankInfo()[1].contents.amount
  84.                 object2Max = object2.getTankInfo()[1].capacity
  85.                 object2Text = object2Name .. " - " .. format_thousand( object2Quantity ) .. " / " .. format_thousand( object2Max ) .. " mB"
  86.             end
  87.         end
  88.        
  89.         object2Decimal = object2Quantity / object2Max
  90.     end
  91.    
  92.     -- Object 3
  93.     local object3Name = "N/A"
  94.     local object3Quantity = 0
  95.     local object3Max = 0
  96.     local object3Text = "N/A - N/A"
  97.     local object3Decimal = 0
  98.        
  99.     if not ( barrels_drums[ ( ( page - 1 ) * 4 ) + 3 ] == nil ) then
  100.         local object3 = peripheral.wrap( barrels_drums[ ( ( page - 1 ) * 4 ) + 3 ] )
  101.         local object3Type = peripheral.getType( barrels_drums[ ( ( page - 1 ) * 4 ) + 3 ] )
  102.        
  103.         if ( object3Type == "mcp_mobius_betterbarrel" ) then
  104.             if not ( object3.getStoredItems() == nil ) then
  105.                 object3Name = object3.getStoredItems().display_name
  106.                 object3Quantity = object3.getStoredItems().qty
  107.                 object3Max = object3.getMaxStoredItems()
  108.                 object3Text = object3Name .. " - " .. format_thousand( object3Quantity ) .. " / " .. format_thousand( object3Max )
  109.             end
  110.         elseif ( object3Type == "drum" ) then
  111.             if not ( object3.getTankInfo().contents == nil ) then
  112.                 object3Name = object3.getTankInfo()[1].contents.rawName
  113.                 object3Quantity = object3.getTankInfo()[1].contents.amount
  114.                 object3Max = object3.getTankInfo()[1].capacity
  115.                 object3Text = object3Name .. " - " .. format_thousand( object3Quantity ) .. " / " .. format_thousand( object3Max ) .. " mB"
  116.             end
  117.         end
  118.        
  119.         object3Decimal = object3Quantity / object3Max
  120.     end
  121.    
  122.     -- Object 4
  123.     local object4Name = "N/A"
  124.     local object4Quantity = 0
  125.     local object4Max = 0
  126.     local object4Text = "N/A - N/A"
  127.     local object4Decimal = 0
  128.    
  129.     if not ( barrels_drums[ ( ( page - 1 ) * 4 ) + 4 ] == nil ) then
  130.         local object4 = peripheral.wrap( barrels_drums[ ( ( page - 1 ) * 4 ) + 4 ] )
  131.         local object4Type = peripheral.getType( barrels_drums[ ( ( page - 1 ) * 4 ) + 4 ] )
  132.        
  133.         if ( object4Type == "mcp_mobius_betterbarrel" ) then
  134.             if not ( object4.getStoredItems() == nil ) then
  135.                 object4Name = object4.getStoredItems().display_name
  136.                 object4Quantity = object4.getStoredItems().qty
  137.                 object4Max = object4.getMaxStoredItems()
  138.                 object4Text = object4Name .. " - " .. format_thousand( object4Quantity ) .. " / " .. format_thousand( object4Max )
  139.             end
  140.         elseif ( object4Type == "drum" ) then
  141.             if not ( object4.getTankInfo()[1].contents == nil ) then
  142.                 object4Name = object4.getTankInfo()[1].contents.rawName
  143.                 object4Quantity = object4.getTankInfo()[1].contents.amount
  144.                 object4Max = object4.getTankInfo()[1].capacity
  145.                 object4Text = object4Name .. " - " .. format_thousand( object4Quantity ) .. " / " .. format_thousand( object4Max ) .. " mB"
  146.             end
  147.         end
  148.        
  149.         object4Decimal = object4Quantity / object4Max
  150.     end
  151.    
  152.     program:GetObject('PageLabel1').Text = pageText
  153.     program:GetObject('PageLabel2').Text = pageText
  154.    
  155.     program:GetObject('Indicator1').Text = object1Text
  156.     program:GetObject('IndicatorP1').Text = tostring( math.floor( object1Decimal * 100 ) ) .. "%"
  157.     program:GetObject('IndicatorBar1').Value = object1Decimal
  158.    
  159.     program:GetObject('Indicator2').Text = object2Text
  160.     program:GetObject('IndicatorP2').Text = tostring( math.floor( object2Decimal * 100 ) ) .. "%"
  161.     program:GetObject('IndicatorBar2').Value = object2Decimal
  162.    
  163.     program:GetObject('Indicator3').Text = object3Text
  164.     program:GetObject('IndicatorP3').Text = tostring( math.floor( object3Decimal * 100 ) ) .. "%"
  165.     program:GetObject('IndicatorBar3').Value = object3Decimal
  166.    
  167.     program:GetObject('Indicator4').Text = object4Text
  168.     program:GetObject('IndicatorP4').Text = tostring( math.floor( object4Decimal * 100 ) ) .. "%"
  169.     program:GetObject('IndicatorBar4').Value = object4Decimal
  170.  
  171. end, 5)
  172.  
  173. program:Run(function()
  174.     program:GetObject('PageRightButton1').OnClick = function(self, event, side, x, y)
  175.         if not ( page == maxpage ) then
  176.             page = page + 1
  177.         end
  178.     end
  179.     program:GetObject('PageRightButton2').OnClick = function(self, event, side, x, y)
  180.         if not ( page == maxpage ) then
  181.             page = page + 1
  182.         end
  183.     end
  184.     program:GetObject('PageLeftButton1').OnClick = function(self, event, side, x, y)
  185.         if not ( page == 1 ) then
  186.             page = page - 1
  187.         end
  188.     end
  189.     program:GetObject('PageLeftButton2').OnClick = function(self, event, side, x, y)
  190.         if not ( page == 1 ) then
  191.             page = page - 1
  192.         end
  193.     end
  194. end)
  195.  
  196. term.restore()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement