Guest User

ME Storage script

a guest
Sep 8th, 2019
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local serialization = require("serialization")
  3. local sides = require("sides")
  4. local term = require("term")
  5.  
  6. local me = component.me_controller
  7. local cell = 16777216
  8. local count = 80
  9. local storagesize = cell*count
  10. local freespace = cell*count
  11. local timer = 60
  12. local lines = 0
  13.  
  14. term.clear()
  15. os.execute("resolution 60 90")
  16.  
  17. local function byteCount(n)
  18.  
  19.     if n >= 10^6 then
  20.         return string.format("%.2fMB", n/1024^2)
  21.     elseif n>= 10^3 then
  22.         return string.format("%.2fKB", n/1024)
  23.     else
  24.         return string.format("%.0fB", n)
  25.     end
  26. end
  27.  
  28. local function amount(n)
  29.  
  30.     if n >= 10^6 then
  31.         return string.format("%.2fm", n/10^6)
  32.     elseif n>= 10^3 then
  33.         return string.format("%.2fk", n/10^3)
  34.     else
  35.         return tostring(n)
  36.     end
  37. end
  38.  
  39. while true do
  40.  
  41. local space = freespace
  42.  
  43. for key,item in ipairs(me.getItemsInNetwork()) do
  44.     print("--------------------")
  45.     print(item.label.." :: "..amount(item.size).." Unit(s), Bytes: "..byteCount((512+item.size)))
  46.     space = space - (512+item.size)
  47.     lines = lines + 2
  48.     os.sleep(0.5)
  49. end
  50.  
  51. local x = (1-(space/storagesize))*100
  52. x = math.floor(x*100)/100
  53. print("\n")
  54. print("Total bytes: "..byteCount(storagesize).." Free Bytes "..byteCount(space))
  55. print("Percent used: "..x.."%")
  56. print("\n")
  57.  
  58. lines = lines + 7
  59. os.sleep(0.5)
  60.  
  61. while timer > 0 do
  62.     timer = timer - 1
  63. term.setCursor(1,lines)
  64. term.clearLine()
  65. print("Time until refresh: "..timer)
  66. os.sleep(1)
  67. end
  68.  
  69. timer = 60
  70. lines = 0
  71.  
  72. term.clear()
  73. end
RAW Paste Data