Advertisement
Guest User

books

a guest
Feb 13th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. local data = {}
  2. rednet.open("right")
  3. p = peripheral.wrap("bottom")
  4.  
  5. function checkSlots(id)
  6.    data = {}
  7.    local slot
  8.    local name
  9.    local slots = p.getAllStacks()
  10.    for i,j in pairs(slots) do
  11.       slot = i
  12.       name = j.all()["myst_book"]["destination"]       print(name)
  13.       data[slot]=name
  14.    end
  15.    rednet.send(id,"done")
  16. end
  17.  
  18. function removeSlot(slot)
  19.    p.pushItem("up", slot, 1)
  20.    rs.setOutput("left", true)
  21.    sleep(1)
  22.    rs.setOutput("left", false)
  23. end
  24.  
  25. function book(slot,id)
  26.    p.pushItem("up", slot, 1)
  27.    turtle.select(1)
  28.    turtle.drop()
  29.    sleep(5)
  30.    getBook()
  31.    turtle.select(1)
  32.    turtle.dropDown()
  33.    rednet.send(tonumber(id), "done")
  34. end
  35.  
  36. function getBook()
  37.    turtle.suck()
  38. end
  39.  
  40. function getNames(id)
  41.    local nameTbl = textutils.serialize(data)
  42.    rednet.send(tonumber(id), nameTbl)
  43. end
  44.  
  45. while true do
  46.    local id, msg, dis = rednet.receive()
  47.    local newmsg = string.match(msg, "%a+")
  48. --   print(msg)
  49.    if newmsg == "checkSlots" then
  50.      checkSlots(id)
  51.    elseif newmsg == "getNames" then
  52.      getNames(id)
  53.    elseif newmsg == "remove" then
  54.      removeSlot(tonumber(string.match(msg, "%d+")))
  55.      rednet.send(id,"done")
  56.    elseif newmsg == "books" then
  57.      slot = string.match(msg, "%d+")
  58.      book(tonumber(slot), id)
  59.    end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement