Guest User

Untitled

a guest
Dec 9th, 2019
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local C1 = peripheral.wrap("obsidian_0")
  2. local m = peripheral.wrap("top")
  3. local itemList = { } --# place this at or near the beginning of your code
  4.  
  5. local function drawScreen() --# place this *before* any calls to this function
  6. m.setBackgroundColor(colors.red)
  7. m.clear()
  8. local tmpY = 1
  9. m.setCursorPos(1,tmpY)
  10. for i = 1, #itemList do
  11. m.write(itemList[i].name .. " QTY: " .. tostring(itemList[i].qty))
  12. tmpY = tmpY + 1
  13. m.setCursorPos(1,tmpY)
  14. end
  15. end
  16.  
  17. function CheckItems()
  18. itemList = { }
  19. local InvSize = C1.getInventorySize()
  20. for CurrSlot = 1, InvSize-1 do --Checking slots
  21. local slot = C1.getStackInSlot(CurrSlot)
  22. if slot ~= nil then -- Slots with stuff in them
  23. local match = false
  24. if #itemList == 0 then --# if there are no entries yet, add the first one
  25. itemList[1] = { name = slot.name }
  26. itemList[1].slots = { }
  27. itemList[1].slots[1] = { slot = CurrSlot }
  28. itemList[1].slots[1].qty = slot.qty
  29. itemList[1].qty = slot.qty
  30. else
  31. for i = 1, #itemList do --# cycle through the master item list
  32. 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
  33. itemList[i].slots[#itemList[i].slots+1] = { }
  34. itemList[i].slots[#itemList[i].slots] = { slot = CurrSlot }
  35. itemList[i].slots[#itemList[i].slots].qty = slot.qty
  36. itemList[i].qty = itemList[i].qty + slot.qty
  37. match = true
  38. break
  39. end
  40. end
  41. if not match then --# if the item isn't already in the list, add it
  42. itemList[#itemList+1] = { name = slot.name }
  43. itemList[#itemList].slots = { }
  44. itemList[#itemList].slots[1] = { slot = CurrSlot }
  45. itemList[#itemList].slots[1].qty = slot.qty
  46. itemList[#itemList].qty = slot.qty
  47. end
  48. end
  49. end
  50. end
  51. end
  52.  
  53. CheckItems()
  54. drawScreen()
RAW Paste Data