Savage_Me55iah

AE storage

Jun 26th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. function find_peripheral(t, e)
  2.   e = e or nil
  3.   sides = {[1] = "front", [2] = "back", [3] = "left", [4] = "right", [5] = "top", [6] = "bottom"}
  4.   peripheral_found = false
  5.   for num=1, 6 do
  6.     type = peripheral.getType(sides[num])
  7.     if type == t then
  8.       if e == "wireless" then
  9.         if peripheral.call(sides[num], "isWireless") then
  10.           return sides[num]
  11.         end
  12.       elseif e == "remote" then
  13.         if not peripheral.call(sides[num], "isWireless") then
  14.           return sides[num]
  15.         end
  16.       elseif e == nil then
  17.         return sides[num]
  18.       end
  19.     end
  20.   end
  21.   print("No " .. t .. " attached to the computer")
  22. end
  23.  
  24. function change_colors(command, color_1, color_2)
  25.   command.setTextColor(color_1 or colors.white)
  26.   command.setBackgroundColor(color_2 or colors.black)
  27. end
  28.  
  29. function writes(text1, command, xpos, ypos, color1, color2)
  30. command.setCursorPos(xpos, ypos)
  31. change_colors(command, color1, color2)
  32. command.write(text1:upper())
  33. change_colors(command)
  34. end
  35.  
  36. me = peripheral.wrap(find_peripheral("me_drive"))
  37.  
  38. while true do
  39. term.clear()
  40. bytes_used = me.getTotalBytes() - me.getFreeBytes()
  41. byte_perc = math.floor(bytes_used / me.getTotalBytes())
  42. types_used = me.getTotalItemTypes() - me.getRemainingItemTypes()
  43. type_perc = math.floor(types_used / me.getTotalItemTypes())
  44. text = "bytes: " .. bytes_used .. "/" .. me.getTotalBytes() .. " - " .. byte_perc .. "%"
  45. writes(text, term, 2, 2, colors.black, colors.white)
  46. text = "types: " .. types_used .. "/" .. me.getTotalItemTypes() .. " - " .. type_perc .. "%"
  47. writes(text, term, 2, 4, colors.black, colors.white)
  48. if byte_perc > 90 or type_perc > 90 then
  49. text = "status = need more storage"
  50. else
  51. text = "status = stable"
  52. end
  53. writes(text, term, 2, 6, colors.black, colors.white)
  54. os.startTimer(20)
  55. os.pullEvent("timer")
  56. end
Advertisement
Add Comment
Please, Sign In to add comment