Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This script is intended to be used with one
- --connected ME terminal (crafting or normal)
- --and one ComputerCraft monitor (either type.
- --Items to display go below. The system will
- --only show as many items as there are lines
- --on your monitor, based on text size. Items
- --need to be entered as "Name:ID:Metadata".
- --Lines can be entered as "line".
- local itemList = {"Steel Ingot:7798:0","Stainless Steel Ingot:9630:44"}
- --Character to use for line separators.
- local lineChar = "-"
- --If using an advanced monitor, these
- --set the text colors for names/values.
- local itemNameColor = colors.white
- local itemNumberColor = colors.green
- local lineColor = colors.yellow
- --Other necessary information
- local textSize = 1
- local monitorName = "monitor_26"
- local terminalName = "right"
- local connectDelay = 1
- local updateDelay = 10
- --Do not touch, used internally
- local monitor = nil
- local terminal = nil
- local screenX = 1
- local screenY = 1
- local nameMax = 1
- local curItem = {}
- local iName
- local iID
- local iMeta
- local qty
- local qStr
- local function getSetup()
- print("Finding terminal.")
- while terminal == nil do
- terminal = peripheral.wrap(terminalName)
- if reactor == nil then
- print("Waiting for terminal peripheral.")
- os.sleep(connectDelay)
- end
- end
- print("Terminal found. Looking for monitor.")
- while monitor == nil do
- monitor = peripheral.wrap(monitorName)
- if monitor == nil then
- print("Waiting for monitor.")
- os.sleep(connectDelay)
- end
- end
- print("Monitor found. Determining sizes.")
- monitor.clear()
- monitor.setTextScale(textSize)
- screenX, screenY = monitor.getSize()
- nameMax = screenX - 6
- print("Monitor can display "..screenY.." items.")
- print("Display names can be "..nameMax.." characters or less.")
- end
- function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- local function formatNumber(theNumber)
- local tempNum = 0
- local tempStr = ""
- if theNumber > 1000000000 then
- tempNum = math.floor(theNumber / 1000000)
- tempStr = tempNum + "M"
- elseif theNumber > 1000000 then
- tempNum = math.floor(theNumber / 1000)
- tempStr = tempNum + "K"
- else
- tempStr = tostring(theNumber)
- end
- return tempStr
- end
- local function formatName(toFormat)
- if string.len(toFormat) > nameMax then
- return string.sub(toFormat, 1, nameMax)
- else
- return toFormat
- end
- end
- local function writeItems()
- for k,v in ipairs(itemList) do
- if k <= screenY then
- if v == "line" then
- qStr = ""
- for x=1,screenX,1 do
- qStr = qStr..lineChar
- end
- monitor.setCursorPos(1,k)
- if monitor.isColor() then
- monitor.setTextColor(lineColor)
- end
- monitor.write(qStr)
- else
- curItem = split(v, "\:")
- if #curItem ~= 3 then
- print(curItem[1].." entry is malformed.")
- else
- iName = curItem[1]
- iID = tonumber(curItem[2])
- iMeta = tonumber(curItem[3])
- monitor.setCursorPos(1,k)
- if monitor.isColor() then
- monitor.setTextColor(itemNameColor)
- end
- monitor.write(formatName(iName))
- if terminal.containsItemType(iID, iMeta) then
- qty = terminal.countOfItemType(iID, iMeta)
- else
- qty = 0
- end
- qStr = formatNumber(qty)
- monitor.setCursorPos(screenX - string.len(qStr), k)
- if monitor.isColor() then
- monitor.setTextColor(itemNumberColor)
- end
- monitor.write(qStr)
- end
- end
- end
- end
- end
- getSetup()
- print("Executing main display loop.")
- while true do
- monitor.clear()
- writeItems()
- os.sleep(updateDelay)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement