Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if fs.exists("playerData")==false then
- print("Bitte Lege einen Owner fest:")
- fp=fs.open("playerData",'w')
- fp.write("owner='"..io.read().."'")
- fp.close()
- shell.run("playerData")
- print("Bitte Item in Kiste legen und Taste druecken")
- os.pullEvent("key")
- scan()
- else
- shell.run("playerData")
- end
- --Funktionen
- function wrapP(peripheralName)
- if os.version()~="CraftOS 1.5" then
- if peripheralName==nil then
- print("Fehler")
- end
- local peripherals = peripheral.getNames()
- local i = 1
- while i < #peripherals and peripheral.getType(peripherals[i])~=peripheralName do
- i=i+1
- end
- if peripheral.getType(peripherals[i])==peripheralName then
- return peripheral.wrap(peripherals[i]),peripherals[i]
- else
- return nil
- end
- else
- local sides={"top","bottom","left","right","front","back"}
- for i=1,#sides do
- if peripheral.getType(sides[i])==peripheralName then
- return peripheral.wrap(sides[i]),sides[i]
- end
- end
- end
- end
- function wrapPs(peripheralName)
- periTab={}
- sideTab={}
- if peripheralName==nil then
- print("Fehler")
- end
- local peripherals = peripheral.getNames()
- local i2 = 1
- for i =1, #peripherals do
- if peripheral.getType(peripherals[i])==peripheralName then
- periTab[i2]=peripheral.wrap(peripherals[i])
- sideTab[i2]=peripherals[i]
- i2=i2+1
- end
- end
- if periTab~={} then
- return periTab,sideTab
- else
- return nil
- end
- end
- function loadDeals()
- deals={}
- if fs.exists("selling") then
- files=fs.list("selling/")
- else
- shell.run("mkdir selling")
- files=fs.list("selling/")
- end
- local i=1
- if files~=nil then
- for i=1,#files do
- shell.run("selling/"..files[i])
- deals[i]=recipe
- end
- return true
- end
- end
- --Peripheralien
- pim=wrapP("pim")
- dr,drSide=wrapP("drive")
- mon=wrapP("monitor")
- me=wrapP("tileinterface")
- is=wrapP("openperipheral_selector")
- chest=wrapP("chest")
- --Variablen
- currentDeal=1
- function printDeal()
- detail={id="EnderIO:itemMaterial, dmg=9"}
- is.setSlot(5,detail)
- detail.id="ExtraUtilities:nodeUpgrade"
- detail.dmg=9
- is.setSlot(4,detail)
- end
- function nextDeal()
- if currentDeal < #deals then
- currentDeal=currentDeal+1
- else
- currentDeal=1
- end
- is.setSlot(1,deals[currentDeal][1].fingerprint)
- is.setSlot(2,deals[currentDeal][2].fingerprint)
- end
- function prevDeal()
- if currentDeal > 1 then
- currentDeal=currentDeal-1
- else
- currentDeal=#deals
- end
- is.setSlot(1,deals[currentDeal][1].fingerprint)
- is.setSlot(2,deals[currentDeal][2].fingerprint)
- end
- function say(string)
- print(string)
- if mon~=nil then
- mon.setCursorPos()
- mon.clear()
- mon.write(string)
- end
- end
- function getInventory()
- if pim.getInventoryName=="pim" then
- say("Bitte auf den PIM stellen")
- else
- items=pim.getAllStacks()
- invSpace=1
- itemsByID={}
- for i=1, pim.getInventorySize() do
- if items[i]~=nil then
- item=items[i].all()
- itemsByID[item.id.."/"..item.dmg]={slot=i,size=item.qty,fingerprint={id=item.id,dmg=item.dmg}}
- invSpace=invSpace+1
- end
- end
- end
- return itemsByID, invSpace
- end
- function hasItem(fingerprint,size)
- itemsByID, invSpace = getInventory()
- local bol = true
- if itemsByID[fingerprint.id]==nil then
- bol=false
- else
- if itemsByID[fingerprint.id].size<size then
- bol=false
- end
- end
- bol=itemsByID[fingerprint.id].slot
- end
- function buy(recipe)
- itemsByID, invSpace = getInventory()
- if invSpace and hasItem(recipe[2].fingerprint.id,recipe[2].size) and hasItem(recipe[1].fingerprint.id,recipe[1].size) then
- me.pullItem("up",hasItem(recipe[2].fingerprint.id,recipe[2].size),recipe[2].size)
- me.exportItem(recipe[1],'up',1)
- end
- end
- function scan()
- if fs.exists("selling")==false then
- fs.makeDir("selling")
- end
- recipe={}
- detail=pim.getStackInSlot(1)
- if detail ~=nil then
- recipe.fingerprint={id=detail.id,dmg=detail.dmg}
- recipe.size=detail.qty
- print("Wie viel soll "..recipe.fingerprint.id.." kosten?")
- recipe.price=tonumber(io.read())
- print("Speichern als:")
- name=io.read()
- recipe.name=name
- fp=fs.open("selling/"..name,'w')
- fp.write('recipe='..textutils.serialize(recipe))
- fp.close()
- loadDeals()
- else
- print("Bitte Item in 1. Inventar Slot legen")
- end
- end
- function createCard()
- if pim.getInventoryName~="pim" then
- if dr.isDiskPresent() then
- creditcard={}
- creditcard.credit=0
- creditcard.owner=pim.getInventoryName()
- fp=fs.open("disk/.creditcard",'w')
- fp.writeLine("--o \n")
- fp.writeLine("creditcard="..textutils.serialize(creditcard))
- fp.close()
- dr.setDiskLabel(pim.getInventoryName())
- else
- print("keine Floppy gefunden")
- end
- end
- end
- function getCard()
- shell.run("disk/.creditcard")
- end
- function menu()
- term.clear()
- term.setCursorPos(1,2) term.write("Willkommen "..pim.getInventoryName())
- term.setCursorPos(1,2) term.write("Item Auswaehlen")
- term.setCursorPos(1,3) term.write("Guthaben aufladen")
- term.setCursorPos(1,5)
- event,button,x,y=os.pullEvent("mouse_click")
- if y=="2" then selectItem() end
- if y=="3" then loadCard() end
- end
- function selectItem()
- getCard()
- if loadDeals then
- xMax,yMax=term.getSize()
- term.clear()
- term.setCursorPos(1,1)
- term.write("Bitte Item auswaehlen")
- term.setCursorPos(1,2)
- term.write("Item")
- term.setCursorPos(xMax-#"Preis",1)
- term.write("Preis")
- for i=1,#deals do
- term.setCursorPos(1,i+2)
- term.write(deals[i].name)
- term.setCursorPos(xMax-#tostring(deals[i].price),i+2)
- term.write(deals[i].price)
- end
- term.setCursorPos(1,2)
- term.write("Zurueck")
- event,button,x,y=os.pullEvent("mouse_click")
- if y>2 and y<#deals+2 then
- deal=deals[y-2]
- term.clear()
- term.setCursorPos(1,1)
- print("Wie viele "..deal.fingerprint.id.." moechtest du kaufen?")
- offer=tonumber(io.read())
- if creditcard.credit >= deal.price then
- --Hier weitermachen
- end
- else
- menu()
- end
- end
- end
- function main()
- event, slot, side = os.pullEvent("slot_click")
- if slot == 5 then
- nextDeal()
- end
- if slot == 4 then
- if pim.getInventoryName~="pim" then
- if pim.getInventoryName==owner then
- scan()
- else
- buy(deals[currentDeal])
- end
- end
- end
- if slot == 9 then
- prevDeal()
- end
- end
- loadDeals()
- selectItem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement