Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get 01J5smWq portalt
- local data = {}
- rednet.open("right")
- function writeFile()
- file = io.open("locs", "w")
- outp = textutils.serialize(data)
- file:write(outp)
- file:flush()
- file:close()
- end
- function readFile()
- file = io.open("locs", "r")
- if file == nil then writeFile() else
- inp = file:read()
- data = textutils.unserialize(inp)
- end
- file:close()
- end
- function printFile()
- file = io.open("locs", "r")
- print(file:read())
- file:close()
- end
- function addName(slot,name)
- data[slot] = name
- writeFile()
- end
- function removeSlot(slot)
- turtle.select(slot)
- --turtle.down()
- turtle.dropDown()
- data[slot] = null
- writeFile()
- --turtle.up()
- turtle.select(1)
- end
- function checkSlots(id)
- for i = 1,12 do
- if turtle.getItemCount(i) > 0 and data[i] == null then
- print("send")
- rednet.send(id, "getName")
- local id, msg, dist = rednet.receive()
- addName(i, msg)
- end
- if turtle.getItemCount(i) == 0 and data[i] ~= null then
- data[i] = null
- writeFile()
- end
- end
- rednet.send(id,"done")
- end
- function book(slot,id)
- turtle.select(slot)
- turtle.drop()
- sleep(5)
- getBook()
- turtle.select(1)
- rednet.send(tonumber(id), "done")
- end
- function getBook()
- rs.setBundledOutput("back", 1)
- sleep(1.5)
- --turtle.down()
- turtle.suck()
- --turtle.up()
- rs.setBundledOutput("back", 0)
- end
- function getNames(id)
- local nameTbl = textutils.serialize(data)
- rednet.send(tonumber(id), nameTbl)
- end
- readFile()
- while true do
- printFile()
- local id, msg, dis = rednet.receive()
- local newmsg = string.match(msg, "%a+")
- print(msg)
- if newmsg == "checkSlots" then
- checkSlots(id)
- elseif newmsg == "getNames" then
- getNames(id)
- elseif newmsg == "remove" then
- removeSlot(tonumber(string.match(msg, "%d+")))
- rednet.send(id,"done")
- elseif newmsg == "books" then
- slot = string.match(msg, "%d+")
- book(tonumber(slot), id)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement