Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component=require("component")
- local event = require("event")
- local robot = require("robot")
- local name_client = "cli"
- local serialization = require("serialization")
- local modem = component.modem
- port_list = 12000
- port_dst = 22000
- friend = nil
- robot_authkey = 121212
- list = {}
- rlist = {}
- function Left(num) --1..3
- for i=1,num,1 do robot.turnLeft() end
- end
- function clear()
- for i = 1,16,1 do robot.select(i) robot.dropUp() end
- end
- function dropall()
- for i = 1,16,1 do robot.select(i) robot.drop() end
- end
- function inlist(name)
- if rlist==nil then
- return false
- elseif rlist[name]~=nil then
- return true
- else
- return false
- end
- end
- function addlist(name,lbl,side)
- if not inlist(name) then
- list[#list+1] = {name,lbl,0,0}
- rlist[name] = side - 1
- end
- end
- function getlist()
- clear()
- for i=1,4,1 do
- num = 1
- robot.select(num)
- while robot.suck() do
- tit=component.inventory_controller.getStackInInternalSlot(num)
- addlist(tit.name,tit.label,i)
- num = num + 1
- robot.select(num)
- end
- dropall()
- Left(1)
- end
- end
- function auth()
- modem.open(port_list)
- modem.broadcast(port_dst,serialization.serialize({name_client,"getlist",robot_authkey,list}))
- _,_,friend,_,_,answ = event.pull(10,"modem")
- if answ~=nil then answ = serialization.unserialize(answ) end
- while answ==nil or answ[3]~=robot_authkey do
- _,_,friend,_,_,answ = event.pull(10,"modem")
- if answ~=nil then answ = serialization.unserialize(answ) end
- end
- end
- getlist()
- auth()
- while true do
- answ = nil
- _,_,from,_,_,answ = event.pull(10,"modem")
- if answ~=nil then answ = serialization.unserialize(answ) end
- while from~=friend do
- _,_,from,_,_,answ = event.pull(10,"modem")
- if answ~=nil then answ = serialization.unserialize(answ) end
- end
- ky = answ[3]
- answ = answ[4]
- Left(rlist[answ[1]])
- num = 1
- robot.select(num)
- tit = nil
- while robot.suck() do
- tit=component.inventory_controller.getStackInInternalSlot(num)
- if tit.name == answ[1] then break end
- num = num + 1
- robot.select(num)
- end
- if tit~=nil and tit.size >= answ[2] then
- modem.broadcast(port_dst,serialization.serialize({name_client,"answer",ky,"good"}))
- robot.select(num)
- robot.dropUp(answ[2])
- else
- modem.broadcast(port_dst,serialization.serialize({name_client,"answer",ky,"bad"}))
- end
- dropall()
- Left(4-rlist[answ[1]])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement