Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function proxy(componentType)
- local address = component.list(componentType)()
- return address and component.proxy(address) or error("No component " .. componentType)
- end
- local robot, modem, keyboard = proxy("robot"), proxy("modem"), proxy("keyboard")
- local a,b = 6,6
- local list = {
- --w = 0x11, a = 0x1E, s = 0x1F, d = 0x20, lshift = 0x2A, lctrl = 0x1D
- --движение робота
- ['17.0'] = function(name_key) robot.move(3) end,
- ['31.0']= function(name_key) robot.move(2) end,
- ['32.0']= function(name_key) robot.turn(true) end,
- ['30.0']= function(name_key) robot.turn(false) end,
- ['58.0']= function(name_key) robot.move(1) end,
- ['29.0']= function(name_key) robot.move(0) end
- }
- local function sleep(timeout)
- local deadline = computer.uptime() + timeout
- repeat
- computer.pullSignal(deadline - computer.uptime())
- until computer.uptime() >= deadline
- end
- function start()
- modem.open(6791)
- modem.open(7000)
- modem.setWakeMessage('')
- modem.setStrength(50000)
- checkPort()
- end
- function checkPort()
- if modem.isOpen(6791) and modem.isOpen(7000) then
- modem.broadcast(7000, 'Я ожил!')
- end
- end
- function ferma()
- while true do
- for i = 1, a do
- robot.move(3)
- robot.use(0)
- end
- robot.turn(false)
- robot.move(3)
- robot.use(0)
- robot.turn(false)
- for l = 1, b do
- robot.move(3)
- robot.use(0)
- end
- robot.turn(false)
- robot.move(3)
- robot.use(0)
- robot.turn(false)
- end
- end
- start()
- while true do
- e, _, _, code, _, msg = computer.pullSignal()
- if e == 'key_down' then
- sleep(.2)
- name_key = tostring(code)
- --modem.broadcast(7000, name_key)
- if list[name_key] then
- list[name_key]()
- end
- elseif e == 'modem_message' then
- if msg == "StartFarm" then
- ferma()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement