Advertisement
PasaP

Direwolf Shop

Jan 24th, 2019
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. me=peripheral.wrap("right")
  2. ch=peripheral.wrap("ender_chest_2")
  3.  
  4. function indexToFP(FPIndex)
  5.  return({id=string.sub(FPIndex,1,string.find(FPIndex,'/')-1),dmg=tonumber(string.sub(FPIndex,string.find(FPIndex,'/')+1))})
  6. end
  7.  
  8. itemPos={}
  9.  
  10. function getItems(inv)
  11.     local items={}
  12.     allStacks=inv.getAllStacks()
  13.     n2=1
  14.     for n1=1, inv.getInventorySize() do
  15.         if allStacks[n1]~=nil then
  16.             items[#items+1]=allStacks[n1].all()
  17.             itemPos[#itemPos+1]=n1
  18.         end
  19.     end
  20.     return items
  21. end
  22.  
  23.  
  24. while true do
  25.  
  26. http1=http.get("http://gecco34.bplaced.net/Shop/bestellung.gecco34")
  27. http2=textutils.unserialize(http1.readAll())
  28.  
  29.  
  30. sufficientFunds=false
  31. sufficientItems=false
  32.  
  33. --setzt frequenz
  34. ch.setFrequency(http2.frequency)
  35.  
  36. --ueberpruefung, ob Zahlungsmittel ausreichend sind
  37. items=getItems(ch)
  38. price=0
  39. for i=1,#items do
  40.   if items[i].id==http2.price.fingerprint.id and items[i].dmg==http2.price.fingerprint.dmg then
  41.     price=price+items[i].qty
  42.   end
  43. end
  44. if price>=http2.price.count then
  45.  sufficientFunds=true
  46. end
  47.  
  48. --Ueberpruefung, ob genuegend Items zum verkaufen da sind
  49. items2=me.getItemDetail(http2.item.fingerprint)
  50. if items2~=nil then
  51.   items2=items2.all()
  52.   if items2.qty>=http2.item.count then
  53.     sufficientItems=true
  54.   end
  55. end
  56.  
  57. --Austauschen der Items
  58. if sufficientFunds==true and sufficientItems==true then
  59.   --Bezahlung annnehmen
  60.   funds=0
  61.   for i=1,#itemPos do
  62.     funds=ch.pushItem("SOUTH",itemPos[i],http2.price.count-funds)+funds
  63.   end
  64.   --Item geben
  65.   if funds==http2.price.count then
  66.     me.exportItem(http2.item.fingerprint,"EAST",http2.item.count)
  67.     print("Zahlung erfolgreich")
  68.   end
  69. end
  70.  
  71. sleep(0.5)
  72.  
  73. --shell.run("lua")
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement