Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local r = require('robot')
- local computer = require('computer')
- local component = require('component')
- local fs = require('filesystem')
- local modem = component.modem
- local inv = component.inventory_controller
- local event = require('event')
- RoodList = {}
- OthodList = {}
- FuelList = {}
- modem.open(8)
- local friend
- local fs = io.open("friendAdres", "r")
- if not fs then
- local SECRET_KEY_INPUT = "lkwejbhvlkwejbkjwerbfjwhvbjkehfvbejbwejb"
- while true do
- local _, _, sender, _, _, message = event.pull("modem_message")
- if message == SECRET_KEY_INPUT then
- friend = sender
- break
- end
- end
- local SECRET_KEY_OUTPUT = "wqerfwevwegwergverbertgbvertesger"
- os.sleep(2)
- modem.send(friend, 8, SECRET_KEY_OUTPUT)
- fs = io.open("friendAdres", "w")
- fs:write(friend)
- fs:close()
- else
- friend = fs:read()
- fs:close()
- end
- --[[os.sleep(2)
- modem.send(friend, 8, "hello")
- --]]
- -- ============================ NAVIGATION =============================--
- loc = {x=0, y=0, z=0, b=0}
- function forward()
- attempt = 0
- while r.detect() do
- r.swing()
- attempt = attempt + 1
- if attempt > 20 then
- snos(3)
- attempt = 0
- end
- end
- while not r.forward() do r.swing() end
- if loc.b == 0 then loc.y = loc.y+1
- elseif loc.b == 1 then loc.x = loc.x+1
- elseif loc.b == 2 then loc.y = loc.y-1
- else loc.x = loc.x-1 end
- return true
- end
- function back()
- if not r.back() then
- r.turnAround()
- while not r.forward() do
- r.swing()
- end
- r.turnAround()
- end
- if loc.b == 0 then loc.y = loc.y-1
- elseif loc.b == 1 then loc.x = loc.x-1
- elseif loc.b == 2 then loc.y = loc.y+1
- else loc.x = loc.x+1 end
- return true
- end
- function up()
- attempt = 0
- while r.detectUp() do
- r.swingUp()
- attempt = attempt +1
- if attempt > 20 then
- snos(1)
- attempt = 0
- end
- end
- while not r.up() do r.swingUp() end
- loc.z = loc.z+1
- return true
- end
- function down()
- attempt = 0
- while r.detectDown() do
- r.swingDown()
- attempt = attempt + 1
- if attempt > 20 then
- snos(1)
- attempt = 0
- end
- end
- while not r.down() do r.swingDown() end
- loc.z = loc.z-1
- return true
- end
- function turnRight()
- loc.b = (loc.b+3)%4
- r.turnRight()
- end
- function turnAround()
- loc.b = (loc.b+2)%4
- r.turnAround()
- end
- function turnLeft()
- loc.b = (loc.b+1)%4
- r.turnLeft()
- end
- function povernut(side)
- if side == 0 and loc.b == 3 then
- turnLeft()
- elseif side == 3 and loc.b == 0 then
- turnRight()
- else
- while (loc.b < side) do
- turnLeft()
- end
- while (loc.b > side) do
- turnRight()
- end
- end
- end
- function goTo(x, y, z, b)
- while z > loc.z do
- up()
- end
- while z < loc.z do
- down()
- end
- if x > loc.x then
- povernut(1)
- elseif x < loc.x then
- povernut(3)
- end
- while x ~= loc.x do
- forward()
- end
- if y > loc.y then
- povernut(0)
- elseif y < loc.y then
- povernut(2)
- end
- while y ~= loc.y do
- forward()
- end
- povernut(b)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement