Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- remoteTurtle = function()
- controls = {
- "forward/back = \24/\25",
- "left/right = \27/\26",
- "up/down = pageUp/pageDown",
- "break = delete",
- "place = insert",
- }
- bearRight = {
- north = 'east',
- east = 'south',
- south = 'west',
- west = 'north',
- }
- bearLeft = {
- north = 'west',
- east = 'north',
- south = 'east',
- west = 'south',
- }
- movePos = {
- north = { 0, 0,-1},
- east = { 1, 0, 0},
- south = { 0, 0, 1},
- west = {-1, 0, 0},
- }
- inv = {
- 00,00,00,00,
- 00,00,00,00,
- 00,00,00,00,
- 00,00,00,00,
- }
- getBearing = function()
- pos = {x=0,y=0,z=0}
- pos.x, pos.y, pos.z = gps.locate()
- turtle.forward()
- diffX, diffY, diffZ = gps.locate()
- turtle.back()
- if not diffX then
- print("Unable to triangulate GPS")
- else
- diffX = diffX - pos.x
- diffZ = diffZ - pos.z
- if diffX ~= 0 then
- if diffX > 0 then
- bearing = "east"
- else bearing = "west" end
- elseif diffZ > 0 then
- bearing = "south"
- else bearing = "north" end
- end
- end
- left = function()
- if turtle.turnLeft() then
- bearing = bearLeft[bearing]
- end
- end
- right = function()
- if turtle.turnRight() then
- bearing = bearRight[bearing]
- end
- end
- fwd = function()
- change = movePos[bearing]
- if turtle.forward() then
- pos.x = pos.x - change[1]
- pos.z = pos.z - change[3]
- end
- end
- back = function()
- change = movePos[bearing]
- if turtle.back() then
- pos.x = pos.x - change[1]
- pos.z = pos.z - change[3]
- end
- end
- up = function()
- if turtle.up() then
- pos.y = pos.y + 1
- end
- end
- down = function()
- if turtle.down() then
- pos.y = pos.y - 1
- end
- end
- dig = function()
- if turtle.dig() then
- end
- end
- put = function()
- if turtle.place() then
- end
- end
- shell.run("clear")
- getBearing()
- firstRun = true
- while true do
- if not firstRun then
- evt,key,cmd = os.pullEvent("rednet_message")
- else firstRun = false end
- if cmd == keys.enter then
- break
- elseif cmd == keys.left or cmd == "left" then
- left()
- elseif cmd == keys.right or cmd == "right" then
- right()
- elseif cmd == keys.up or cmd == "forward" then
- fwd()
- elseif cmd == keys.down or cmd == "back" then
- back()
- elseif cmd == keys.pageUp or cmd == "up" then
- up()
- elseif cmd == keys.pageDown or cmd == "down" then
- down()
- elseif cmd == keys.delete or cmd == "dig" then
- dig()
- elseif cmd == keys.insert or cmd == "place" then
- put()
- else
- os.queueEvent("yield")
- os.pullEvent("yield")
- end
- x,y = term.getCursorPos()
- term.setCursorPos(1,1)
- term.clearLine()
- print("Bearing: "..bearing)
- term.setCursorPos(1,2)
- term.clearLine()
- print("Position: "..pos.x,pos.y,pos.z)
- mX,mY = term.getSize()
- for i = #controls,1,-1 do
- term.setCursorPos(1,mY-#controls+i)
- write(controls[i])
- end
- term.setCursorPos(x,y)
- end
- end
- remoteMob = function()
- controls = {
- "forward/back = \24/\25",
- "left/right = \27/\26",
- "jump = pageUp *WIP",
- }
- movePos = {
- north = { 0, 0,-1},
- east = { 1, 0, 0},
- south = { 0, 0, 1},
- west = {-1, 0, 0},
- }
- mobBearing = function()
- pos = {x=0,y=0,z=0}
- pos.x, pos.y, pos.z = gps.locate()
- pos.x = math.floor(pos.x)
- pos.y = math.floor(pos.y)
- pos.z = math.floor(pos.z)
- yaw = math.abs(peripheral.wrap("back").getMetaOwner().yaw)
- if math.abs(180-yaw) < 45 then
- bearing = "north"
- mob.look(180,0)
- elseif math.abs(270-yaw) < 45 then
- bearing = "east"
- mob.look(270,0)
- elseif math.abs(0-yaw) < 45 then
- bearing = "south"
- mob.look(0,0)
- elseif math.abs(90-yaw) < 45 then
- bearing = "west"
- mob.look(90,0)
- end
- yaw = math.abs(peripheral.wrap("back").getMetaOwner().yaw)
- end
- shell.run("clear")
- firstRun = true
- while true do
- if not firstRun then
- evt = {os.pullEvent("rednet_message")}
- cmd = evt[3]
- else
- firstRun = false
- cmd = nil
- end
- mob = peripheral.wrap("back")
- mobBearing()
- if cmd == false then
- break
- elseif cmd == "left" then
- newYaw = yaw - 90
- if newYaw < 0 then
- newYaw = 360 + newYaw
- end
- mob.look(newYaw,0)
- elseif cmd == "right" then
- newYaw = yaw + 90
- if newYaw > 360 then
- newYaw = newYaw - 360
- end
- mob.look(newYaw,0)
- elseif cmd == "forward" then
- change = movePos[bearing]
- if pcall(mob.walk(change[1],change[2],change[3])) then
- pos.x = pos.x - change[1]
- pos.z = pos.z - change[3]
- mob.look(yaw,0)
- end
- elseif cmd == "back" then
- change = movePos[bearing]
- if pcall(mob.walk(-change[1],change[2],-change[3])) then
- pos.x = pos.x + change[1]
- pos.z = pos.z + change[3]
- mob.look(yaw,0)
- end
- elseif cmd == "up" then
- mob.launch(0,-90,1)
- else
- os.queueEvent("yield")
- os.pullEvent("yield")
- end
- mobBearing()
- term.setCursorPos(1,1)
- term.clearLine()
- print("Bearing: "..bearing)
- term.setCursorPos(1,2)
- term.clearLine()
- print("Position: "..pos.x,pos.y,pos.z)
- mX,mY = term.getSize()
- for i = #controls,1,-1 do
- term.setCursorPos(1,mY-#controls+i)
- write(controls[i])
- end
- end
- end
- modem = peripheral.find("modem")
- if not modem then
- print("[Error] No modem")
- else
- rednet.open(peripheral.getName(modem))
- if not gps.locate() then
- print("[Error] No GPS")
- else
- if turtle then
- remoteTurtle()
- elseif peripheral.getType("back") == "neuralInterface" then
- if peripheral.wrap("back").hasModule("plethora:kinetic") then
- remoteMob()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment