lego11

Computer centrale RGBasics

May 9th, 2026
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ben = peripheral.wrap("top")
  2. m = peripheral.wrap("left")
  3. print("Programma avviato")
  4. while true do
  5.  
  6.     local storage = false
  7.     local productsRaw = http.get("http://192.168.13.103/api.php").readAll()
  8.     products = textutils.unserialize(productsRaw)
  9.     local orders = textutils.unserialize(http.get("http://192.168.13.103/checkOrders.php").readAll())
  10.   if(type(orders) ~= "table") then
  11.     os.reboot()
  12.   end
  13.     for k, v in pairs(products) do
  14.         for a,b in pairs(orders) do
  15.             local qnt = 0
  16.             local counter = 0          
  17.             if(v.id == b.id and v.modId == b.modId and tonumber(b.sendTo) ~= nil)  then
  18.              --   redstone.setBundledOutput("bottom", tonumber(b.sendTo))
  19.                 m.setFreq(tonumber(b.sendTo))
  20.                 print(b.sendTo)
  21.                 print("Ritiro ordine")
  22.                 qnt = a + 1
  23.                 local item = ben.getItemIdentifierIDFor(tonumber(v.id), tonumber(v.modId))
  24.                 ben.getAvailableItems()
  25.                 i,j = os.pullEvent("available_items_return")
  26.                 for p, q in pairs(j) do
  27.                     if((ben.getItemName(j[p][1]) ==  "ME 64k Storage") and b.id == "4361") then
  28.                         ben.makeRequest(j[p][1], tonumber(b.qty))
  29.                     else
  30.                         storage = true
  31.  
  32.                     end
  33.                 end
  34.                 if(storage) then
  35.                     ben.makeRequest(item, tonumber(b.qty))
  36.                 end
  37.                 local fulfillRaw = http.get("http://192.168.13.103/fulfill_order.php?uuid=" .. tostring(b.uuid)).readAll()
  38.                 sleep(0.2)
  39.                
  40.                 local function sendDataToServer(stock)
  41.     local requestStock = http.post("http://192.168.13.103/stock.php", "stock=" .. stock)
  42.     print(requestStock.readAll()) --Read and print contents of page
  43. end
  44.  
  45.     local productsRaw = http.get("http://192.168.13.103/api.php").readAll()
  46.     local products = textutils.unserialize(productsRaw)
  47.     local stock = ""
  48.    
  49.     ben.getAvailableItems()
  50.     local eventName, eventData = os.pullEvent("available_items_return")
  51.     local len = #products
  52.  
  53.     for k = 1, len do
  54.         local v = products[k]
  55.  
  56.         if v.id ~= nil and v.modId ~= nil then
  57.             local lp = ben.getItemIdentifierIDFor(tonumber(v.id), tonumber(v.modId))
  58.             for a, b in pairs(eventData) do
  59.                 if b[1] == lp then
  60.                     if stock == "" then
  61.                         stock = v.nome .. "-" .. b[2]
  62.                     else
  63.                         stock = stock .. "-" .. v.nome .. "-" .. b[2]
  64.                     end
  65.                 end
  66.             end
  67.         end
  68.     end
  69.  
  70.     sendDataToServer(stock)
  71.  
  72.  
  73.             end
  74.         end
  75. end
  76.  end
Add Comment
Please, Sign In to add comment