1ng0

Mystcr. & CC Books

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