Chaos_Cash

shopChestManager

Oct 6th, 2024 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1.     for k,v in pairs(peripheral.getNames()) do
  2.         if peripheral.getType(peripheral.getNames()[k]) == "modem" then
  3.         rednet.open(peripheral.getNames()[k])
  4.         end
  5.     end
  6.    
  7. chest = peripheral.wrap("bottom")
  8.    
  9.    
  10.     while true do
  11.    
  12.     info1,info2,info3,info4 = os.pullEvent()
  13.    
  14.    
  15.         if info1 == "rednet_message" then
  16.        
  17.             if type(info3) == "table" then
  18.            
  19.            
  20.                 if info3["action"] == "getItemCount" then
  21.                 itemCount = nil
  22.                 itemCount = chest.getItemDetail(info3["item"])
  23.                     if itemCount == nil then
  24.                     itemCount = 0
  25.                     else
  26.                     itemCount = itemCount["count"]
  27.                     end
  28.                 rednet.send(info2,{["action"]="sendingItemCount",["itemCount"]=itemCount})
  29.                 end
  30.            
  31.            
  32.                 if info3["action"] == "buy" then
  33.                     for k,v in pairs(info3["order"]) do
  34.                         repeat
  35.                         chest.pushItems("front",info3["order"][k]["slot"],info3["order"][k]["amount"])
  36.                         info3["order"][k]["amount"] = info3["order"][k]["amount"]-64
  37.                         until info3["order"][k]["amount"] < 1
  38.                     end
  39.                 end
  40.                
  41.                
  42.                 if info3["action"] == "getItemNames" then
  43.                 items = {}
  44.                 slots = {}
  45.                
  46.                     for k,v in pairs(chest.list()) do
  47.                     table.insert(items,chest.getItemDetail(k)["displayName"])
  48.                     table.insert(slots,k)
  49.                     end
  50.                    
  51.                 rednet.send(info2,{["action"]="sendingItemNames",["itemNames"]=items,["itemSlots"]=slots})
  52.                
  53.                 end
  54.                
  55.             end
  56.        
  57.         end
  58.    
  59.     end
Add Comment
Please, Sign In to add comment