lgrocks11

Untitled

Mar 11th, 2024 (edited)
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. --Variables
  2.  
  3. local Connected_Inventories = {}
  4. local Inventory = {}
  5. local Slot_Count = 16
  6.  
  7. --Functions
  8.  
  9. local function readInventory(InventoryIndex,InventoryID)
  10. --make a list of every item,its count,and slot number.
  11. print("Reading inventory",InventoryIndex)
  12. local ItemInfo_List = {}
  13. local InventoryPeripheral = peripheral.wrap(InventoryID)
  14. Slot_Count = InventoryPeripheral.size()
  15. for i = 1,Slot_Count do
  16. local ItemInfo = InventoryPeripheral.getItemDetail(i)
  17. if ItemInfo then
  18. if ItemInfo[1] ~= nil and ItemInfo[2] ~= nil then
  19. local Item_Info = {ItemInfo[1],ItemInfo[2],i}
  20. table.insert(ItemInfo_List,Item_Info)
  21. end
  22. end
  23. end
  24. return ItemInfo_List
  25. end
  26.  
  27. local function addItemToInvList(ItemInfos)
  28. --Add item and count to the general Inventory list.
  29. table.insert(Inventory,ItemInfos)
  30. end
  31.  
  32. local function moveInfo(Inventory_List)
  33. for Item_Index,Item_Information in pairs(Inventory_List) do
  34. addItemToInvList(Item_Information)
  35. end
  36. end
  37.  
  38. local function takeInventory()
  39. for Inventory_Index,Inventory_ID in pairs(Connected_Inventories) do
  40. local Current_Inventory = Inventory_ID
  41. local Inventory_Name,Peripheral_Type = peripheral.getType(Inventory_ID)
  42. local InvList = readInventory(Inventory_Index,Inventory_ID)
  43. --for every item in the readInventory lists, add its name and its count to the general Inventory list.
  44. moveInfo(InvList)
  45. end
  46. return Inventory
  47. end
  48.  
  49. local function printInventory()
  50. takeInventory()
  51. print("Inventory: ")
  52. for ItemIndex,ItemInformation in pairs(Inventory) do
  53. print(tostring(ItemInformation[1])..";"..tostring(ItemInformation[2]))
  54. end
  55. end
  56.  
  57. --Program starts
  58.  
  59. for Peripheral_Index,Peripheral_ID in pairs(peripheral.getNames()) do
  60. local Current_Peripheral = Peripheral_ID
  61. local Peripheral_Name,Peripheral_Type = peripheral.getType(Current_Peripheral)
  62. if Peripheral_Type == "inventory" then
  63. table.insert(Connected_Inventories,Current_Peripheral)
  64. end
  65. end
  66.  
  67. printInventory()
Advertisement
Add Comment
Please, Sign In to add comment