Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- peripherals = peripheral.getNames()
- for i,j in pairs(peripherals) do
- if peripheral.getType(j) == "tradingpost" then trade = peripheral.wrap(j) end
- if peripheral.getType(j) == "container_chest" or peripheral.getType(j) == "iron" then chest = peripheral.wrap(j) end
- end
- emerald_buffer = {["direction"]="north",["slot"]=0}
- pages = {}
- function savePages()
- if fs.exists("pages.dat") then
- fs.delete("pages.dat")
- end
- file = fs.open("pages.dat", "w")
- file.write(textutils.serialize(pages))
- file.close()
- end
- function loadPages()
- if fs.exists("pages.dat") then
- file = fs.open("pages.dat", "r")
- pages = textutils.unserialize(file.readAll())
- file.close()
- else
- if not shell.run("pastebin get","pqqGZ2nW","pages.dat") then
- error("Failed to initialise page list, please check http permissions")
- end
- end
- end
- function getTradeInfo(id)
- local sold = trade.getItemSold(id,0)
- if sold == nil then
- sold = {["name"]="nope",["qty"]=0,["rawName"]="nada"}
- end
- return sold.name, sold.qty, sold.rawName, id
- end
- function topUpEmeralds()
- chest.pullItem(emerald_buffer["direction"], emerald_buffer["slot"])
- end
- loadPages()
- topUpEmeralds()
- while true do
- ids = trade.getVillagerIds()
- chest.pullItem(emerald_buffer["direction"], emerald_buffer["slot"])
- for index, idnum in pairs(ids) do
- sold, soldQty, rawName, id = getTradeInfo(idnum)
- if rawName == "item.myst.page" and (sold == "Link Panel" or pages[sold] ~= true) then
- if trade.performTrade(id, 0) then
- print("New "..sold)
- pages[sold] = true
- savePages()
- topUpEmeralds()
- else
- print("Failed to buy "..sold)
- end
- end
- end
- sleep(3)
- end
Advertisement
Add Comment
Please, Sign In to add comment