Posted 21 October 2012 - 03:50 PM
Welcome to turtle control
ok so i have been working on a program that will let you control turtles wirelessly. it will do the following things.
turn left
turn right
go left
go right
go forward
go back
dig around its self
go up
go down
and will even drop tnt
Note to drop tnt place the tnt in the bottom right slot of the turtle.
i will soon add more features like outputting redstone signals placing blocks ete. how ever im limited because the gui is in a menu form. so i can only do the ammount of options that fit on the screen.
anyway, to use its quite easy. just put the turtle code on a wireless mining turtle and run it.
for the client you have to make 2 modifications. you must enter the id of the turtle. and type in where the modem is on the computer
(left, right, top, bottom, front, back)
heres the code:
client:
Spoiler
id = 15 --change to turtle id
n=1
options = {
"Drop Payload",
"Go Up",
"Go Down",
"Go Left",
"Go Right",
"Go Forward",
"Go Backward",
"Dig",
"Turn Left",
"Turn Right",
}
local function opt(m,mY)
l=#m
while true do
for i=1, l, 1 do
if i==n then
local x, y = term.getSize()
local b = string.len(">"..m[i].."<")/2
local x = (x/2)-b
term.setCursorPos(x,i+mY)
term.clearLine()
print(">"..m[i].."<")
else
local x, y = term.getSize()
b = string.len(m[i])/2
x = (x/2)-b
term.setCursorPos(x,i+mY)
term.clearLine()
print(m[i]) end
end
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
while true do
term.clear()
rednet.open("side") --Change to the side of your modem
local input = opt(options,0)
if input == 1 then
rednet.send(id,"payload,1")
elseif input == 2 then
rednet.send(id,"up,1")
elseif input == 3 then
rednet.send(id,"down,1")
elseif input == 4 then
rednet.send(id,"left,1")
elseif input == 5 then
rednet.send(id,"right,1")
elseif input == 6 then
rednet.send(id,"forward,1")
elseif input == 7 then
rednet.send(id,"back,1")
elseif input == 8 then
rednet.send(id,"dig,1")
elseif input == 9 then
rednet.send(id,"lLeft,1")
elseif input == 10 then
rednet.send(id,"lRight,1")
end
end
turtle:
Spoiler
rednet.open("right")
function LookLeft(distance)
for i = 1,distance do
turtle.turnLeft()
end
end
function LookRight(distance)
for i = 1,distance do
turtle.turnRight()
end
end
function forward(distance)
for i = 1,distance do
turtle.forward()
end
end
function back(distance)
for i = 1,distance do
turtle.back()
end
end
function mine(distance)
for i = 1,distance do
turtle.dig()
sleep(1.5)
turtle.digUp()
sleep(1.5)
turtle.digDown()
end
end
function up(distance)
for i = 1,distance do
turtle.up()
end
end
function left(distance)
turtle.turnLeft()
for i = 1,distance do
turtle.forward()
end
turtle.turnRight()
end
function down(distance)
for i = 1,distance do
turtle.down()
end
end
function right(distance)
turtle.turnRight()
for i = 1,distance do
turtle.forward()
end
turtle.turnLeft()
end
function payload(distance)
redstone.setOutput("bottom", true)
turtle.select(9)
for i = 1,distance do
turtle.placeDown()
sleep(1)
end
redstone.setOutput("bottom", false)
turtle.select(1)
end
while true do
local id,msg,dist = rednet.receive()
local command,dist = string.match(msg, "(%w+),(%w+)")
if command == "forward" then
forward(tonumber(dist))
elseif command == "back" then
back(tonumber(dist))
elseif command == "dig" then
mine(tonumber(dist))
elseif command == "up" then
up(tonumber(dist))
elseif command == "down" then
down(tonumber(dist))
elseif command == "left" then
left(tonumber(dist))
elseif command == "right" then
right(tonumber(dist))
elseif command == "payload" then
payload(tonumber(dist))
elseif command == "lRight" then
LookRight(tonumber(dist))
elseif command == "lLeft" then
LookLeft(tonumber(dist))
end
end
all suggestions are welcome and please let me know if you have errors and what part the errors are in!
thanks -Cheeky
p.s A MAJOR THANKS TO CRANIUM FOR HELPING ME WITH THE MENUE!!!!