Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- drone.lua:
- targetx=0
- targety=0
- targetz=0
- local navi=component.proxy(component.list('navigation')())
- local xyz={navi.getPosition()}
- local x=math.floor(xyz[1])
- local y=math.floor(xyz[2])
- local z=math.floor(xyz[3])
- local modem=component.proxy(component.list('modem')())
- modem.open(1337)
- local function respond(...)
- local args=table.pack(...)
- pcall(function() modem.broadcast(1337, table.unpack(args)) end)
- end
- local function receive()
- while true do
- local e, _, _, _, _, cmd=computer.pullSignal()
- if e == "modem_message" then return load(cmd) end
- end
- end
- function getDroneXYZ()
- pcall(function() modem.broadcast(1337, navi.getPosition()) end)
- end
- function getDroneX()
- pcall(function() modem.broadcast(1337, x) end)
- end
- function geDronetY()
- pcall(function() modem.broadcast(1337, y) end)
- end
- function getDroneZ()
- pcall(function() modem.broadcast(1337, z) end)
- end
- while true do
- if targetx ~= 0 or targety ~= 0 or targetz ~= 0 then
- nx = targetx - x
- ny = targety - y
- nz = targetz - z
- coords = nx .. ", " .. ny .. ", " .. nz
- pcall(function() modem.broadcast(1337, "coords=" .. coords) end)
- --drone.setStatusText(coords)
- drone.move(nx, ny, nz)
- targetx = 0
- targety = 0
- targetz = 0
- end
- local result, reason = pcall(function()
- local result, reason = receive()
- if not result then return respond(reason) end
- respond(result())
- end)
- if not result then respond(reason) end
- end
- tablet.lua:
- local component = require('component')
- local modem = component.modem
- local event = require("event")
- local term = require("term")
- coords=""
- modem.broadcast(1337, "drone=component.proxy(component.list('drone')())")
- function printblockinfo(eventname, data)
- modem.broadcast(1337, "targetx=" .. data['posX'])
- modem.broadcast(1337, "targety=" .. data['posY'])
- modem.broadcast(1337, "targetz=" .. data['posZ'])
- term.clear()
- print("X: " .. data['posX'])
- print("Y: " .. data['posY'])
- print("Z: " .. data['posZ'])
- end
- --print("listening for tablet_use events")
- event.listen("tablet_use", printblockinfo)
- function transmit()
- term.clear()
- print("-----Transmit-----")
- while true do
- msg=io.read()
- if msg == "leave" then
- break
- else
- pcall(function() modem.broadcast(1337, msg) end)
- print(select(6, event.pull(6, "modem_message")))
- end
- end
- event.pull("interrupted")
- event.ignore("tablet_use", printblockinfo)
- end
- function main()
- print("send")
- print("leave")
- while true do
- if coords ~= "" then
- modem.broadcast(1337, "drone.move(" .. coords .. ")")
- end
- input=io.read()
- if input == "send" then
- transmit()
- elseif input == "leave" then
- -- event.pull("interrupted")
- -- event.ignore("tablet_use", printblockinfo)
- -- print("done")
- break
- end
- end
- end
- main()
- event.pull("interrupted")
- event.ignore("tablet_use", printblockinfo)
- print("done")
Advertisement
Add Comment
Please, Sign In to add comment