Advertisement
ecco7777

Direwolf Shop

Sep 2nd, 2017
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.84 KB | None | 0 0
  1. if fs.exists("playerData")==false then
  2. print("Bitte Lege einen Owner fest:")
  3. fp=fs.open("playerData",'w')
  4. fp.write("owner='"..io.read().."'")
  5. fp.close()
  6. shell.run("playerData")
  7. print("Bitte Item in Kiste legen und Taste druecken")
  8. os.pullEvent("key")
  9. scan()
  10. else
  11. shell.run("playerData")
  12. end
  13.  
  14. --Funktionen
  15. function wrapP(peripheralName)
  16. if os.version()~="CraftOS 1.5" then
  17. if peripheralName==nil then
  18. print("Fehler")
  19. end
  20. local peripherals = peripheral.getNames()
  21. local i = 1
  22. while i < #peripherals and peripheral.getType(peripherals[i])~=peripheralName do
  23. i=i+1
  24. end
  25. if peripheral.getType(peripherals[i])==peripheralName then
  26. return peripheral.wrap(peripherals[i]),peripherals[i]
  27. else
  28. return nil
  29. end
  30. else
  31. local sides={"top","bottom","left","right","front","back"}
  32. for i=1,#sides do
  33. if peripheral.getType(sides[i])==peripheralName then
  34. return peripheral.wrap(sides[i]),sides[i]
  35. end
  36. end
  37. end
  38. end
  39.  
  40.  
  41. function wrapPs(peripheralName)
  42. periTab={}
  43. sideTab={}
  44. if peripheralName==nil then
  45. print("Fehler")
  46. end
  47. local peripherals = peripheral.getNames()
  48. local i2 = 1
  49. for i =1, #peripherals do
  50. if peripheral.getType(peripherals[i])==peripheralName then
  51. periTab[i2]=peripheral.wrap(peripherals[i])
  52. sideTab[i2]=peripherals[i]
  53. i2=i2+1
  54. end
  55. end
  56. if periTab~={} then
  57. return periTab,sideTab
  58. else
  59. return nil
  60. end
  61. end
  62.  
  63. function loadDeals()
  64. deals={}
  65. if fs.exists("selling") then
  66. files=fs.list("selling/")
  67. else
  68. shell.run("mkdir selling")
  69. files=fs.list("selling/")
  70. end
  71. local i=1
  72. if files~=nil then
  73. for i=1,#files do
  74. shell.run("selling/"..files[i])
  75. deals[i]=recipe
  76. end
  77. return true
  78. end
  79. end
  80.  
  81. --Peripheralien
  82.  
  83. pim=wrapP("pim")
  84. dr,drSide=wrapP("drive")
  85. mon=wrapP("monitor")
  86. me=wrapP("tileinterface")
  87. is=wrapP("openperipheral_selector")
  88. chest=wrapP("chest")
  89. --Variablen
  90. currentDeal=1
  91.  
  92. function printDeal()
  93. detail={id="EnderIO:itemMaterial, dmg=9"}
  94. is.setSlot(5,detail)
  95. detail.id="ExtraUtilities:nodeUpgrade"
  96. detail.dmg=9
  97. is.setSlot(4,detail)
  98. end
  99.  
  100. function nextDeal()
  101. if currentDeal < #deals then
  102. currentDeal=currentDeal+1
  103. else
  104. currentDeal=1
  105. end
  106. is.setSlot(1,deals[currentDeal][1].fingerprint)
  107. is.setSlot(2,deals[currentDeal][2].fingerprint)
  108. end
  109.  
  110. function prevDeal()
  111. if currentDeal > 1 then
  112. currentDeal=currentDeal-1
  113. else
  114. currentDeal=#deals
  115. end
  116. is.setSlot(1,deals[currentDeal][1].fingerprint)
  117. is.setSlot(2,deals[currentDeal][2].fingerprint)
  118. end
  119.  
  120. function say(string)
  121. print(string)
  122. if mon~=nil then
  123. mon.setCursorPos()
  124. mon.clear()
  125. mon.write(string)
  126. end
  127. end
  128.  
  129. function getInventory()
  130. if pim.getInventoryName=="pim" then
  131. say("Bitte auf den PIM stellen")
  132. else
  133. items=pim.getAllStacks()
  134. invSpace=1
  135. itemsByID={}
  136. for i=1, pim.getInventorySize() do
  137. if items[i]~=nil then
  138. item=items[i].all()
  139. itemsByID[item.id.."/"..item.dmg]={slot=i,size=item.qty,fingerprint={id=item.id,dmg=item.dmg}}
  140. invSpace=invSpace+1
  141. end
  142. end
  143. end
  144. return itemsByID, invSpace
  145. end
  146.  
  147. function hasItem(fingerprint,size)
  148. itemsByID, invSpace = getInventory()
  149. local bol = true
  150. if itemsByID[fingerprint.id]==nil then
  151. bol=false
  152. else
  153. if itemsByID[fingerprint.id].size<size then
  154. bol=false
  155. end
  156. end
  157. bol=itemsByID[fingerprint.id].slot
  158. end
  159.  
  160. function buy(recipe)
  161. itemsByID, invSpace = getInventory()
  162. if invSpace and hasItem(recipe[2].fingerprint.id,recipe[2].size) and hasItem(recipe[1].fingerprint.id,recipe[1].size) then
  163. me.pullItem("up",hasItem(recipe[2].fingerprint.id,recipe[2].size),recipe[2].size)
  164. me.exportItem(recipe[1],'up',1)
  165. end
  166. end
  167.  
  168. function scan()
  169. if fs.exists("selling")==false then
  170. fs.makeDir("selling")
  171. end
  172. recipe={}
  173. detail=pim.getStackInSlot(1)
  174. if detail ~=nil then
  175. recipe.fingerprint={id=detail.id,dmg=detail.dmg}
  176. recipe.size=detail.qty
  177. print("Wie viel soll "..recipe.fingerprint.id.." kosten?")
  178. recipe.price=tonumber(io.read())
  179. print("Speichern als:")
  180. name=io.read()
  181. recipe.name=name
  182. fp=fs.open("selling/"..name,'w')
  183. fp.write('recipe='..textutils.serialize(recipe))
  184. fp.close()
  185. loadDeals()
  186. else
  187. print("Bitte Item in 1. Inventar Slot legen")
  188. end
  189. end
  190.  
  191. function createCard()
  192. if pim.getInventoryName~="pim" then
  193. if dr.isDiskPresent() then
  194. creditcard={}
  195. creditcard.credit=0
  196. creditcard.owner=pim.getInventoryName()
  197. fp=fs.open("disk/.creditcard",'w')
  198. fp.writeLine("--o \n")
  199. fp.writeLine("creditcard="..textutils.serialize(creditcard))
  200. fp.close()
  201. dr.setDiskLabel(pim.getInventoryName())
  202. else
  203. print("keine Floppy gefunden")
  204. end
  205. end
  206. end
  207.  
  208. function getCard()
  209. shell.run("disk/.creditcard")
  210. end
  211.  
  212. function menu()
  213. term.clear()
  214. term.setCursorPos(1,2) term.write("Willkommen "..pim.getInventoryName())
  215. term.setCursorPos(1,2) term.write("Item Auswaehlen")
  216. term.setCursorPos(1,3) term.write("Guthaben aufladen")
  217. term.setCursorPos(1,5)
  218. event,button,x,y=os.pullEvent("mouse_click")
  219. if y=="2" then selectItem() end
  220. if y=="3" then loadCard() end
  221. end
  222.  
  223. function selectItem()
  224. getCard()
  225. if loadDeals then
  226. xMax,yMax=term.getSize()
  227. term.clear()
  228. term.setCursorPos(1,1)
  229. term.write("Bitte Item auswaehlen")
  230. term.setCursorPos(1,2)
  231. term.write("Item")
  232. term.setCursorPos(xMax-#"Preis",1)
  233. term.write("Preis")
  234. for i=1,#deals do
  235. term.setCursorPos(1,i+2)
  236. term.write(deals[i].name)
  237. term.setCursorPos(xMax-#tostring(deals[i].price),i+2)
  238. term.write(deals[i].price)
  239. end
  240. term.setCursorPos(1,2)
  241. term.write("Zurueck")
  242. event,button,x,y=os.pullEvent("mouse_click")
  243. if y>2 and y<#deals+2 then
  244. deal=deals[y-2]
  245. term.clear()
  246. term.setCursorPos(1,1)
  247. print("Wie viele "..deal.fingerprint.id.." moechtest du kaufen?")
  248. offer=tonumber(io.read())
  249. if creditcard.credit >= deal.price then
  250. --Hier weitermachen
  251. end
  252.  
  253.  
  254. else
  255. menu()
  256. end
  257. end
  258. end
  259.  
  260. function main()
  261. event, slot, side = os.pullEvent("slot_click")
  262. if slot == 5 then
  263. nextDeal()
  264. end
  265. if slot == 4 then
  266. if pim.getInventoryName~="pim" then
  267. if pim.getInventoryName==owner then
  268. scan()
  269. else
  270. buy(deals[currentDeal])
  271. end
  272. end
  273. end
  274. if slot == 9 then
  275. prevDeal()
  276. end
  277. end
  278.  
  279. loadDeals()
  280. selectItem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement