Advertisement
Guest User

books

a guest
Jan 24th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. local data = {}
  2. rednet.open("left")
  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.       if slot == 1 then
  13.         name = "Spawn"
  14.       elseif slot == 2 then
  15.         name = "Monster"
  16.       elseif slot == 3 then
  17.         name = "Portail END"  
  18.       elseif slot == 4 then
  19.         name = "END"
  20.       elseif slot == 5 then
  21.         name = "Nthr Blazes"
  22.       elseif slot == 6 then
  23.         name = "Syn'"
  24.       elseif slot == 7 then
  25.         name = "Contact Levy"
  26.       end  
  27. --      print(name)
  28.       data[slot]=name
  29.    end
  30.    rednet.send(id,"done")
  31. end
  32.  
  33. function removeSlot(slot)
  34.    p.pushItem("up", slot, 1)
  35.    rs.setOutput("left", true)
  36.    sleep(1)
  37.    rs.setOutput("left", false)
  38. end
  39.  
  40. function book(slot,id)
  41.    p.pushItem("up", slot, 1)
  42.    turtle.select(1)
  43.    turtle.drop()
  44.    sleep(5)
  45.    getBook()
  46.    turtle.select(1)
  47.    turtle.dropDown()
  48.    rednet.send(tonumber(id), "done")
  49. end
  50.  
  51. function getBook()
  52.    turtle.suck()
  53. end
  54.  
  55. function getNames(id)
  56.    local nameTbl = textutils.serialize(data)
  57.    rednet.send(tonumber(id), nameTbl)
  58. end
  59.  
  60. while true do
  61.    local id, msg, dis = rednet.receive()
  62.    local newmsg = string.match(msg, "%a+")
  63. --   print(msg)
  64.    if newmsg == "checkSlots" then
  65.      checkSlots(id)
  66.    elseif newmsg == "getNames" then
  67.      getNames(id)
  68.    elseif newmsg == "remove" then
  69.      removeSlot(tonumber(string.match(msg, "%d+")))
  70.      rednet.send(id,"done")
  71.    elseif newmsg == "books" then
  72.      slot = string.match(msg, "%d+")
  73.      book(tonumber(slot), id)
  74.    end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement