Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. local component=require("component")
  2. local event = require("event")
  3. local robot = require("robot")
  4. local name_client = "cli"
  5. local serialization = require("serialization")
  6. local modem = component.modem
  7. port_list = 12000
  8. port_dst = 22000
  9. friend = nil
  10. robot_authkey = 121212
  11. list = {}
  12. rlist = {}
  13.  
  14. function Left(num) --1..3
  15.     for i=1,num,1 do robot.turnLeft() end
  16. end
  17.  
  18. function clear()
  19.     for i = 1,16,1 do robot.select(i) robot.dropUp() end
  20. end
  21.  
  22. function dropall()
  23.     for i = 1,16,1 do robot.select(i) robot.drop() end
  24. end
  25.  
  26. function inlist(name)
  27.     if rlist==nil then
  28.         return false
  29.     elseif rlist[name]~=nil then
  30.         return true
  31.     else
  32.         return false
  33.     end
  34. end
  35.  
  36. function addlist(name,lbl,side)
  37.     if not inlist(name) then
  38.         list[#list+1] = {name,lbl,0,0}
  39.         rlist[name] = side - 1
  40.     end
  41. end
  42.  
  43. function getlist()
  44.     clear()
  45.     for i=1,4,1 do
  46.         num = 1
  47.         robot.select(num)
  48.         while robot.suck() do
  49.             tit=component.inventory_controller.getStackInInternalSlot(num)
  50.             addlist(tit.name,tit.label,i)
  51.             num = num + 1
  52.             robot.select(num)
  53.         end
  54.         dropall()
  55.         Left(1)
  56.     end
  57. end
  58.  
  59. function auth()
  60.     modem.open(port_list)
  61.     modem.broadcast(port_dst,serialization.serialize({name_client,"getlist",robot_authkey,list}))
  62.     _,_,friend,_,_,answ = event.pull(10,"modem")
  63.     if answ~=nil then answ = serialization.unserialize(answ) end
  64.     while answ==nil or answ[3]~=robot_authkey do
  65.         _,_,friend,_,_,answ = event.pull(10,"modem")
  66.         if answ~=nil then answ = serialization.unserialize(answ) end
  67.     end
  68. end
  69.  
  70.  
  71. getlist()
  72. auth()
  73. while true do
  74.     answ = nil
  75.     _,_,from,_,_,answ = event.pull(10,"modem")
  76.     if answ~=nil then answ = serialization.unserialize(answ) end
  77.     while from~=friend do
  78.         _,_,from,_,_,answ = event.pull(10,"modem")
  79.         if answ~=nil then answ = serialization.unserialize(answ) end
  80.     end
  81.     ky = answ[3]
  82.     answ = answ[4]
  83.     Left(rlist[answ[1]])
  84.     num = 1
  85.     robot.select(num)
  86.     tit = nil
  87.     while robot.suck() do
  88.         tit=component.inventory_controller.getStackInInternalSlot(num)
  89.         if tit.name == answ[1] then break end
  90.         num = num + 1
  91.         robot.select(num)
  92.     end
  93.     if tit~=nil and tit.size >= answ[2] then
  94.         modem.broadcast(port_dst,serialization.serialize({name_client,"answer",ky,"good"}))
  95.         robot.select(num)
  96.         robot.dropUp(answ[2])
  97.     else
  98.         modem.broadcast(port_dst,serialization.serialize({name_client,"answer",ky,"bad"}))
  99.     end
  100.     dropall()
  101.     Left(4-rlist[answ[1]])
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement