Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local C1 = peripheral.wrap("crystal_0")
- local m = peripheral.wrap("left")
- local itemList = { } --# place this at or near the beginning of your code
- local function drawScreen() --# place this *before* any calls to this function
- m.setBackgroundColor(colors.red)
- m.clear()
- local tmpY = 1
- m.setCursorPos(1,tmpY)
- for i = 1, #itemList do
- m.write(itemList[i].name .. " QTY: " .. tostring(itemList[i].qty))
- tmpY = tmpY + 1
- m.setCursorPos(1,tmpY)
- end
- end
- function CheckItems()
- itemList = { }
- local InvSize = C1.getInventorySize()
- for CurrSlot = 1, InvSize-1 do --Checking slots
- local slot = C1.getStackInSlot(CurrSlot)
- if slot ~= nil then -- Slots with stuff in them
- local match = false
- if #itemList == 0 then --# if there are no entries yet, add the first one
- itemList[1] = { name = slot.name }
- itemList[1].slots = { }
- itemList[1].slots[1] = { slot = CurrSlot }
- itemList[1].slots[1].qty = slot.qty
- itemList[1].qty = slot.qty
- else
- for i = 1, #itemList do --# cycle through the master item list
- if slot.name == itemList[i].name then --# if the new item's name matches the name of item [i] in the master list then update the info
- itemList[i].slots[#itemList[i].slots+1] = { }
- itemList[i].slots[#itemList[i].slots] = { slot = CurrSlot }
- itemList[i].slots[#itemList[i].slots].qty = slot.qty
- itemList[i].qty = itemList[i].qty + slot.qty
- match = true
- break
- end
- end
- if not match then --# if the item isn't already in the list, add it
- itemList[#itemList+1] = { name = slot.name }
- itemList[#itemList].slots = { }
- itemList[#itemList].slots[1] = { slot = CurrSlot }
- itemList[#itemList].slots[1].qty = slot.qty
- itemList[#itemList].qty = slot.qty
- end
- end
- end
- end
- end
- CheckItems()
- drawScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement