Guest User

emeralde

a guest
Nov 7th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. trade = peripheral.wrap("right") -- The side of the trading post
  2. pages = {}
  3.  
  4. function getId() -- Retuns the villager ids needed for trading
  5.   return trade.getVillagerIds()
  6. end
  7.  
  8. function getTradeInfo(id) -- Returns trading information needed
  9.   local sold = trade.getItemSold(id,0)
  10.   local bought = trade.getItemBought(id,0)
  11.   return sold.name, sold.qty, sold.rawName, bought.name, bought.qty, id
  12. end
  13.  
  14. loadPages()
  15. while true do
  16.     ids = getId() -- First get the ids of all close villagers
  17.     term.clear()
  18.     term.setCursorPos(1,1)
  19.     for index, idnum in pairs(ids) do -- Loop through the ids
  20.         sold,soldQty ,rawName,bought,boughtQty, id = getTradeInfo(idnum) -- Get information on what the villagers is trading
  21.         if rawName == "item.emerald" then -- if it is a page and i dont already have it
  22.             if trade.performTrade(id, 0) then -- Then buy it
  23.                 print("New page added!")
  24.             else
  25.                 print("Failed to buy page!") -- Probably not enough emeralds
  26.             end
  27.         end
  28.     end
  29.     sleep(3)
  30. end
Advertisement
Add Comment
Please, Sign In to add comment