Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- me=peripheral.wrap("right")
- ch=peripheral.wrap("ender_chest_2")
- function indexToFP(FPIndex)
- return({id=string.sub(FPIndex,1,string.find(FPIndex,'/')-1),dmg=tonumber(string.sub(FPIndex,string.find(FPIndex,'/')+1))})
- end
- itemPos={}
- function getItems(inv)
- local items={}
- allStacks=inv.getAllStacks()
- n2=1
- for n1=1, inv.getInventorySize() do
- if allStacks[n1]~=nil then
- items[#items+1]=allStacks[n1].all()
- itemPos[#itemPos+1]=n1
- end
- end
- return items
- end
- while true do
- http1=http.get("http://gecco34.bplaced.net/Shop/bestellung.gecco34")
- http2=textutils.unserialize(http1.readAll())
- sufficientFunds=false
- sufficientItems=false
- --setzt frequenz
- ch.setFrequency(http2.frequency)
- --ueberpruefung, ob Zahlungsmittel ausreichend sind
- items=getItems(ch)
- price=0
- for i=1,#items do
- if items[i].id==http2.price.fingerprint.id and items[i].dmg==http2.price.fingerprint.dmg then
- price=price+items[i].qty
- end
- end
- if price>=http2.price.count then
- sufficientFunds=true
- end
- --Ueberpruefung, ob genuegend Items zum verkaufen da sind
- items2=me.getItemDetail(http2.item.fingerprint)
- if items2~=nil then
- items2=items2.all()
- if items2.qty>=http2.item.count then
- sufficientItems=true
- end
- end
- --Austauschen der Items
- if sufficientFunds==true and sufficientItems==true then
- --Bezahlung annnehmen
- funds=0
- for i=1,#itemPos do
- funds=ch.pushItem("SOUTH",itemPos[i],http2.price.count-funds)+funds
- end
- --Item geben
- if funds==http2.price.count then
- me.exportItem(http2.item.fingerprint,"EAST",http2.item.count)
- print("Zahlung erfolgreich")
- end
- end
- sleep(0.5)
- --shell.run("lua")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement