Vladimir_Pruskalyow

ShopRobot.lua

Mar 10th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local modem = component.modem
  4. local robot = require("robot")
  5. local port = 222
  6.  
  7. modem.open(port)
  8.  
  9. while true do
  10.     local e = { event.pull()}
  11.  
  12.     if e[1] == "modem_message" then
  13.         if e[6] == "SServer->SRobot" then
  14.             if e[7] == "DOIT" then
  15.                 for i = 1, 2 do
  16.                         robot.forward()
  17.                     end
  18.                 robot.suck(e[8])
  19.                 local ok
  20.                 if robot.count() == e[8] then
  21.                     ok = true
  22.                 else
  23.                     ok = false
  24.                 end
  25.                 modem.broadcast(port, "SRobot->SServer", "Taken", ok)
  26.                 if ok then
  27.                     robot.turnAround()
  28.                     for i = 1, 3 do
  29.                         robot.forward()
  30.                     end
  31.                     robot.drop(e[8])
  32.                     robot.turnAround()
  33.                     robot.forward()
  34.                 else
  35.                     robot.drop(64)
  36.                     robot.turnAround()
  37.                     for i = 1, 2 do
  38.                         robot.forward()
  39.                     end
  40.                     robot.turnAround()
  41.                 end
  42.             end
  43.         end
  44.     end
  45. end
Add Comment
Please, Sign In to add comment