Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Program that monitors ME storage and outputs
- -- to a display
- -- Author: moomoocat28
- -- Initialization
- local ME = peripheral.wrap("back") -- which side the ME bridge is connected
- local monitor = peripheral.wrap("bottom") -- which side the monitors are connected
- local minAmount = 100 -- minimum quantity for an item to be displayed
- local space = 8 -- i honestly dont remember what this does
- monX, monY = monitor.getSize()
- local title = "ME Storage Monitor"
- local lineBreak = ""
- local tableTitle = "Quantity Item"
- for x = 0, monX, 1 do
- lineBreak = lineBreak .. "-"
- end
- while true do
- local outputTable = ME.listAll()
- local testTable
- -- Functions
- function loadTable()
- end
- function getTotalItems()
- local count = 0
- for i, data in ipairs(ME.listAll()) do
- for k, v in pairs(data) do
- if k ~= nil then
- if k == "amount" then
- count = count + v
- end
- end
- end
- end
- return count
- end
- function centerText(text)
- for x = 1, math.floor((monX - string.len(text)) / 2), 1 do
- monitor.write(" ")
- end
- end
- function reformatInt(int)
- local formatted = int
- while true do
- formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", "%1,%2")
- if k == 0 then
- break
- end
- end
- return formatted
- end
- function printTable()
- local count = 1
- local line = 9
- local length = 0
- local spaces = ""
- for i, data in ipairs(outputTable) do
- table.sort(data)
- for k, v in pairs(data) do
- if k~= nil then
- if k == "amount" and v > minAmount then
- length = string.len(reformatInt(v))
- monitor.setCursorPos(space / 2, line)
- monitor.write("x" .. reformatInt(v))
- end
- if k == "displayName" and length ~= 0 then
- spaces = ""
- for x = 0, space - length, 1 do
- spaces = spaces .. " "
- end
- monitor.write(spaces .. reformatInt(v))
- line = line + 1
- length = 0
- end
- end
- end
- end
- end
- function compare(a, b)
- if a[1] and b[1] ~= nil then
- return a[1][2] < b[1][2]
- end
- end
- -- Program
- monitor.clear()
- monitor.setTextColour(colors.white)
- monitor.setCursorPos(1, 1)
- centerText(title)
- monitor.write(title)
- monitor.setCursorPos(1, 2)
- monitor.write(lineBreak)
- monitor.setCursorPos(1, 4)
- monitor.setTextColour(colors.red)
- monitor.write("Items Stored: ")
- monitor.setTextColour(colors.green)
- monitor.write(reformatInt(getTotalItems()))
- monitor.setTextColour(colors.white)
- monitor.setCursorPos(1, 7)
- centerText(tableTitle)
- monitor.write(tableTitle)
- monitor.setCursorPos(1, 9)
- monitor.setTextColour(colors.green)
- table.sort(outputTable, compare)
- printTable()
- monitor.setCursorPos(1, monY)
- for x = 0, monX, 1 do
- monitor.write(" ")
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment