Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dir = "+Y"
- n = 0
- local directions = { [0]=0,[1]=1,[2]=2,[3]=3,[4]=4,[5]=5,["down"] = 0, ["up"] = 1, ["-Z"] = 2, ["+Z"] = 3, ["-X"] = 4, ["+X"] = 5, ["+Y"] = 1, ["-Y"] = 0}
- sorter = peripheral.wrap("back")
- function getitem(dir,invdir)
- itemcount = 0
- for id,count in pairs(sorter.list(directions[invdir])) do
- itemid = id
- itemcount = itemcount + count
- end
- end
- function update()
- getitem("back",dir)
- n = n + 1
- print("Sent update #"..n)
- if itemcount > 0 then
- item = { [1]="item", [2]=itemname, [3]=itemcount }
- text = textutils.serialize(item)
- rednet.broadcast(text)
- else
- item = { [1]="item", [2]=itemname, [3]=0 }
- text = textutils.serialize(item)
- rednet.broadcast(text)
- end
- end
- if fs.exists("i") then
- local file = io.open("i","r")
- itemname = file.read()
- print("Item name: "..itemname)
- rednet.open("bottom")
- update()
- active = true
- else
- print("No itemname!")
- active = false
- end
- while active do
- event,id,message = os.pullEvent()
- if event == "rednet_message" then
- order = textutils.unserialize(message)
- if message == "updatestock" then
- update()
- end
- if string.sub(message,1,1) == "{" then
- if order[1] == "order"..itemname then
- extracted = order[2]
- while extracted > 0 do
- if extracted >= 64 then
- sorter.extract(directions[dir],itemid,directions["-Y"],64)
- extracted = extracted - 64
- else
- sorter.extract(directions[dir],itemid,directions["-Y"],extracted)
- extracted = 0
- end
- os.sleep(0.2)
- end
- update()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment