Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local io = peripheral.wrap("right")
- pos = {}
- if(not peripheral.isPresent("left")) then
- turtle.select(1)
- turtle.equipLeft()
- ent = peripheral.wrap("left")
- pos = ent.getPos()
- turtle.equipLeft()
- else
- ent = peripheral.wrap("left")
- pos = ent.getPos()
- end
- if io.isConnected() then
- io.disconnect()
- end
- local key=fs.open("key","r").readAll()
- io.connect("turtle.sandhose.fr:4321/turtle","key="..key.."&name="..os.getComputerLabel())
- --[[local timerPending = false--]]
- nextDirs = {left = {WEST="SOUTH", SOUTH="EAST", EAST="NORTH", NORTH="WEST"}, right = {SOUTH="WEST", EAST="SOUTH", NORTH="EAST", WEST="NORTH"}}
- moveDirs = {
- NORTH = {0, 0, -1}, SOUTH = {0, 0, 1}, EAST = {1, 0, 0}, WEST = {-1, 0, 0}, up = {0, 1, 0}, down = {0, -1, 0}
- }
- oppositeDirs = {WEST = "EAST", EAST = "WEST", NORTH = "SOUTH", SOUTH = "NORTH"}
- function addVectorToPos(v)
- pos.X = pos.X + v[1]
- pos.Y = pos.Y + v[2]
- pos.Z = pos.Z + v[3]
- end
- function updatePos(a)
- if(pos ~= {}) then
- if(a == "left" or a == "right") then
- pos.dir = nextDirs[a][pos.dir]
- end
- if(a == "forward") then
- addVectorToPos(moveDirs[pos.dir])
- end
- if(a == "back") then
- addVectorToPos(moveDirs[oppositeDirs[pos.dir]])
- end
- if(a == "up" or a == "down") then
- addVectorToPos(moveDirs[a])
- end
- end
- end
- while true do
- if io.isConnected() then
- if peripheral.isPresent("left") then
- if(ent == nil) then ent = peripheral.wrap("left") end
- pos = ent.getPos()
- local entities = ent.getNearbyEnt()
- io.emit("update entities", entities)
- end
- if(pos ~= {}) then
- io.emit("set location", pos)
- end
- io.emit("update data", { fuel=turtle.getFuelLevel() })
- --[[
- if timerPending == false then
- os.startTimer(0.5)
- timerPending = true
- end
- --]]
- local event, p1, p2 = os.pullEvent("socketio_event")
- if event == "socketio_event" then
- if p1 == "command" then
- if p2 == "turnLeft" then
- turtle.turnLeft()
- updatePos("left")
- elseif p2 == "turnRight" then
- turtle.turnRight()
- updatePos("right")
- elseif p2 == "forward" then
- turtle.forward()
- updatePos("forward")
- elseif p2 == "back" then
- turtle.back()
- updatePos("back")
- elseif p2 == "up" then
- turtle.up()
- updatePos("up")
- elseif p2 == "down" then
- turtle.down()
- updatePos("down")
- elseif p2 == "swap" then
- turtle.equipLeft()
- elseif p2 == "attack" then
- turtle.attack()
- else
- print("Unknown Command")
- end
- end
- elseif event == "timer" then
- print("tick")
- timerPending = false
- end
- --[[
- if timerPending == false then
- os.startTimer(0.5)
- timerPending = true
- end
- --]]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment