Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ben = peripheral.wrap("top")
- m = peripheral.wrap("left")
- print("Programma avviato")
- while true do
- local storage = false
- local productsRaw = http.get("http://192.168.13.103/api.php").readAll()
- products = textutils.unserialize(productsRaw)
- local orders = textutils.unserialize(http.get("http://192.168.13.103/checkOrders.php").readAll())
- if(type(orders) ~= "table") then
- os.reboot()
- end
- for k, v in pairs(products) do
- for a,b in pairs(orders) do
- local qnt = 0
- local counter = 0
- if(v.id == b.id and v.modId == b.modId and tonumber(b.sendTo) ~= nil) then
- -- redstone.setBundledOutput("bottom", tonumber(b.sendTo))
- m.setFreq(tonumber(b.sendTo))
- print(b.sendTo)
- print("Ritiro ordine")
- qnt = a + 1
- local item = ben.getItemIdentifierIDFor(tonumber(v.id), tonumber(v.modId))
- ben.getAvailableItems()
- i,j = os.pullEvent("available_items_return")
- for p, q in pairs(j) do
- if((ben.getItemName(j[p][1]) == "ME 64k Storage") and b.id == "4361") then
- ben.makeRequest(j[p][1], tonumber(b.qty))
- else
- storage = true
- end
- end
- if(storage) then
- ben.makeRequest(item, tonumber(b.qty))
- end
- local fulfillRaw = http.get("http://192.168.13.103/fulfill_order.php?uuid=" .. tostring(b.uuid)).readAll()
- sleep(0.2)
- local function sendDataToServer(stock)
- local requestStock = http.post("http://192.168.13.103/stock.php", "stock=" .. stock)
- print(requestStock.readAll()) --Read and print contents of page
- end
- local productsRaw = http.get("http://192.168.13.103/api.php").readAll()
- local products = textutils.unserialize(productsRaw)
- local stock = ""
- ben.getAvailableItems()
- local eventName, eventData = os.pullEvent("available_items_return")
- local len = #products
- for k = 1, len do
- local v = products[k]
- if v.id ~= nil and v.modId ~= nil then
- local lp = ben.getItemIdentifierIDFor(tonumber(v.id), tonumber(v.modId))
- for a, b in pairs(eventData) do
- if b[1] == lp then
- if stock == "" then
- stock = v.nome .. "-" .. b[2]
- else
- stock = stock .. "-" .. v.nome .. "-" .. b[2]
- end
- end
- end
- end
- end
- sendDataToServer(stock)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment