Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rp = require("robotplus")
- local r = require("robot")
- local modem = require("component").modem
- local event = require("event")
- dofile("/var/props.lua")
- modem.open(in_port)
- local last_id
- while true do
- local _, _, host, _, _, id, name, x, z, farm_type = event.pull("modem_message")
- if last_id ~= id then
- last_id = id
- if name == "farmbot_check" then
- print("responding to check")
- modem.send(host, out_port, "ok", r.name())
- else
- local pos = rp.findWPByName(name, 40)
- if pos then
- print("moving to " .. name)
- rp.jump(pos.position, jump_height)
- local action = (farm_type == "break") and r.swingDown or r.useDown
- current = { x = 0, z = 0 }
- y = pos.position[2]
- if x < 0 then
- current.x = x + 1
- rp.moveX(current.x)
- x = math.abs(x)
- end
- if z < 0 then
- current.z = z + 1
- rp.moveZ(current.z)
- z = math.abs(z)
- end
- rp.turnEast()
- for i = 1, z do
- action()
- for j = 2, x do
- r.forward()
- if i % 2 == 0 then
- current.x = current.x - 1
- else
- current.x = current.x + 1
- end
- action()
- end
- if i == z then
- break
- end
- if i % 2 == 0 then
- r.turnLeft()
- r.forward()
- r.turnLeft()
- else
- r.turnRight()
- r.forward()
- r.turnRight()
- end
- current.z = current.z + 1
- event.pull() --yield
- end
- rp.moveX(-current.x)
- rp.moveZ(-current.z)
- local drop = rp.findWPByName(dropoff, 40)
- rp.jump(drop.position, jump_height - y)
- for i = 1, 16 do
- r.select(i)
- r.dropDown()
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement