Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --DSU Display
- function exists(path)
- local file = assert(io.open(path, "r"))
- if file ~= nil then
- file:close()
- return true
- end
- return false
- end
- function getTable(path)
- if exists(path) then
- local file = io.open(path, "r")
- local lines = {}
- local i = 1
- local line = file:read("*l")
- while line ~= nil do
- lines[i] = line
- line = file:read("*l")
- i = i + 1
- end
- file:close()
- return lines
- end
- return {}
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- function formateNumber(n) --http://richard.warburton.it
- local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
- return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
- end
- -- Variables
- local dsus = {}
- local id = os.getComputerID()
- local config = getTable(id.."/config")
- local begin = tonumber(string.sub(config[1],string.find(config[1],":")+2))
- local stop = tonumber(string.sub(config[2],string.find(config[2],":")+2))
- local monitorvalue = tonumber(string.sub(config[3],string.find(config[3],":")+2))
- local monitor = peripheral.wrap("monitor_" .. monitorvalue)
- local x, y = monitor.getSize()
- local n = 1
- for i = begin, stop do
- dsus[n] = peripheral.wrap("deep_storage_unit_" .. i)
- n = n + 1
- end
- if tablelength(dsus) > y then
- print("Monitor zu klein..")
- sleep(5)
- end
- monitor.clear()
- while true do
- local line = 1
- local line2 = 1 + begin
- for _ in pairs(dsus) do
- if dsus[line].getStoredItems() ~= nil then
- local qty = dsus[line].getStoredItems()["qty"]
- local name = dsus[line].getStoredItems()["display_name"]
- monitor.setCursorPos(1, line)
- monitor.clearLine()
- monitor.setTextColor(colors.orange)
- monitor.write(formateNumber(qty) .. "x ")
- monitor.setTextColor(colors.lime)
- monitor.write(name .. "'s")
- else
- monitor.setCursorPos(1, line)
- monitor.clearLine()
- monitor.setTextColor(colors.red)
- monitor.write("DSU ".. line2 .. " ist leer!")
- end
- line = line + 1
- line2 = line2+ 1
- end
- sleep(0)
- end
Add Comment
Please, Sign In to add comment