Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---@diagnostic disable: undefined-global, undefined-field, need-check-nil, lowercase-global
- inventories = {}
- combinedInventories = {}
- turtleamount = 48
- totals = {}
- progressBarWidth = 10
- monitor = peripheral.find("monitor")
- oldTerm = term.redirect(monitor)
- table.reduce = function(list, fn, init)
- local acc = init
- for k, v in ipairs(list) do
- if 1 == k and not init then
- acc = v
- else
- acc = fn(acc, v)
- end
- end
- return acc
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- function mysplit(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t = {}
- for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
- table.insert(t, str)
- end
- return t
- end
- function drawLine(x, y, length, color)
- oldBgColor = term.getBackgroundColor()
- for i = x, (length + x) do
- term.setCursorPos(i, y)
- term.setBackgroundColor(color)
- term.write(" ")
- end
- term.setBackgroundColor(oldBgColor)
- end
- function listen()
- peripheral.find("modem", rednet.open)
- received = false
- while not received do
- local id, msg = rednet.receive()
- if msg ~= nil or msg ~= false then
- inventories[id] = msg[1]
- totals[id] = msg[2]
- received = true
- end
- end
- end
- function getPercentage()
- local used = 0
- local maximum = 0
- for name, amount in pairs(combinedInventories) do
- used = used + amount
- end
- for key, value in pairs(totals) do
- maximum = maximum + value
- end
- if (used / maximum) == 0 then return 0.0 end
- return (used / maximum)
- end
- function updateMonitor()
- monitor.clear()
- local width, height = monitor.getSize()
- percent = getPercentage()
- w = math.floor(percent * progressBarWidth)
- drawLine(width / 2 - progressBarWidth / 2, height / 2, w , colors.white)
- local str = tostring(percent * 10):sub(1,5) .. "%"
- monitor.setCursorPos((width / 2 - progressBarWidth / 2) + (monitor.getTextScale() * #str), (height / 2) + 2)
- monitor.write(str)
- end
- while true do
- combinedInventories = {}
- listen()
- for key, value in pairs(inventories) do
- for name, amount in pairs(value) do
- if combinedInventories[name] ~= nil then
- combinedInventories[name] = combinedInventories[name] + amount
- else
- combinedInventories[name] = amount
- end
- end
- end
- updateMonitor()
- end
Add Comment
Please, Sign In to add comment