lgrocks11

Untitled

Mar 11th, 2024 (edited)
63
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. local Item_Info = {ItemInfo[1],ItemInfo[2],i}
  19. print(Item_Info)
  20. table.insert(ItemInfo_List,Item_Info)
  21. end
  22. end
  23. return ItemInfo_List
  24. end
  25.  
  26. local function addItemToInvList(ItemInfos)
  27. --Add item and count to the general Inventory list.
  28. table.insert(Inventory,ItemInfos)
  29. end
  30.  
  31. local function moveInfo(Inventory_List)
  32. for Item_Index,Item_Information in pairs(Inventory_List) do
  33. addItemToInvList(Item_Information)
  34. end
  35. end
  36.  
  37. local function takeInventory()
  38. for Inventory_Index,Inventory_ID in pairs(Connected_Inventories) do
  39. local Current_Inventory = Inventory_ID
  40. local Inventory_Name,Peripheral_Type = peripheral.getType(Inventory_ID)
  41. local InvList = readInventory(Inventory_Index,Inventory_ID)
  42. --for every item in the readInventory lists, add its name and its count to the general Inventory list.
  43. moveInfo(InvList)
  44. end
  45. return Inventory
  46. end
  47.  
  48. local function printInventory()
  49. takeInventory()
  50. print("Inventory: ")
  51. for ItemIndex,ItemInformation in pairs(Inventory) do
  52. if ItemInformation[1] and ItemInformation[2] then
  53. print(ItemInformation[1]..";"..ItemInformation[2])
  54. end
  55. end
  56. end
  57.  
  58. --Program starts
  59.  
  60. for Peripheral_Index,Peripheral_ID in pairs(peripheral.getNames()) do
  61. local Current_Peripheral = Peripheral_ID
  62. local Peripheral_Name,Peripheral_Type = peripheral.getType(Current_Peripheral)
  63. if Peripheral_Type == "inventory" then
  64. table.insert(Connected_Inventories,Current_Peripheral)
  65. end
  66. end
  67.  
  68. printInventory()
Advertisement
Add Comment
Please, Sign In to add comment