Maschini

inv_prime

Feb 28th, 2023 (edited)
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. local protocol = "inventory_main"
  2.  
  3. rednet.open("top")
  4. rednet.host(protocol, "main")
  5.  
  6. local inventories = {}
  7.  
  8. local function list()
  9.   local l = {}
  10.  
  11.   for key, inv in pairs(inventories) do
  12.     for key, value in pairs(inv) do
  13.       local name = value["name"] or "unknown"
  14.       l[name] = (l[name] or 0) + value["count"]
  15.     end
  16.   end
  17.  
  18.   return l
  19. end
  20.  
  21. while true do
  22.   local id, message = rednet.receive(protocol)
  23.   inventories[("%d_%s"):format(message["id"], message["name"])] = message["data"]
  24.  
  25.   local monitor = peripheral.wrap("down")
  26.   monitor.setTextScale(0.5)
  27.   monitor.clear()
  28.   monitor.setCursorPos(1,1)
  29.  
  30.   local l = list()
  31.   for name, count in pairs(l) do
  32.     print(name, count)
  33.   end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment