View difference between Paste ID: bxeKZRHa and dKdXBsDD
SHOW: | | - or go back to the newest paste.
1
local data = {}
2
rednet.open("left")
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
   clearInv()
14
   data = {}
15
   local slot
16
   local name
17
   local slots = p.getAllStacks()
18
   for i,j in pairs(slots) do
19
      slot = i
20
      name = j["myst_book"]["destination"]
21
--      print(name)
22
      data[slot]=name
23
   end
24
   rednet.send(id,"done")
25
end
26
27
function removeSlot(slot)
28
   p.pushItem("up", slot, 1)
29
   rs.setOutput("left", true)
30
   sleep(2)
31
   rs.setOutput("left", false)
32
end
33
34
function book(slot,id)
35
   p.pushItem("up", slot, 1)
36
   turtle.select(1)
37
   turtle.drop()
38
   sleep(5)
39
   getBook()
40
   turtle.select(1)
41
   turtle.dropDown()
42
   rednet.send(tonumber(id), "done")
43
end
44
45
function getBook()
46
   turtle.suck()
47
end
48
49
function getNames(id)
50
   local nameTbl = textutils.serialize(data)
51
   rednet.send(tonumber(id), nameTbl)
52
end
53
54
clearInv()
55
56
while true do
57
   local id, msg, dis = rednet.receive()
58
   local newmsg = string.match(msg, "%a+")
59
--   print(msg)
60
   if newmsg == "checkSlots" then
61
     checkSlots(id) 
62
   elseif newmsg == "getNames" then
63
     getNames(id)
64
   elseif newmsg == "remove" then
65
     removeSlot(tonumber(string.match(msg, "%d+")))
66
     rednet.send(id,"done")
67
   elseif newmsg == "books" then
68
     slot = string.match(msg, "%d+")
69
     book(tonumber(slot), id)
70
   end
71
end