Posted 27 March 2012 - 02:40 AM
I created a new thread for all my scripts, it can be found here: http://www.computercraft.info/forums2/index.php?/topic/3266-cc-v141squares-scripts-cccomunicator-and-more/
Computer Craft Communicator, or CCC, is a program, or 3 programs actually, I have developed that interact with each other.
You can send messages to other computers and turtles and even call programs for them to run.
To use a terminal must have a modem, and turtles must be wireless.
The Computer/Turtle your sending to must be currently running the receive program for it to receive commands.
the code,
send
receive(Terminal Version)
receive(Turtle Version)
Current programs you can call:
Turtles:
Move
Excavate
Tunnel
Lumberjack(Must have Tikiana's Lumberjack Script or other lumberjack program)
Dance
Terminals:
DJ
More Program Options to come!
I also made a modified version of Tikiana's Lumberjack Script that replants the tree when its done being cut down if there is a sapling in the bottom right corner of the turtle inventory.
Code,
Download(If you cant/don't want to copy paste)
[attachment=133:CCCommunicator V2.0.zip]
Feel free to leave comments and suggestions in the replies!
Change Log
Added modem side select instead of typing
Minor Changes to program select engine
Modified Tikiana's Lumberjack Script
Computer Craft Communicator, or CCC, is a program, or 3 programs actually, I have developed that interact with each other.
You can send messages to other computers and turtles and even call programs for them to run.
To use a terminal must have a modem, and turtles must be wireless.
The Computer/Turtle your sending to must be currently running the receive program for it to receive commands.
the code,
send
Spoiler
function menu()
local n = 1
while true do
local x, y = term.getCursorPos()
term.clearLine()
if n == 1 then
write("[YES] NO")
else
write("YES [NO]")
end
term.setCursorPos(x, y)
a, b = os.pullEvent()
while a ~= "key" do
a, b = os.pullEvent()
end
if b == 203 and n == 2 then n = 1 end
if b == 205 and n == 1 then n = 2 end
if b == 28 then
print("")
break
end
end
if n == 1 then return true end
if n == 2 then return false end
return false
end
function programSelect(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a program[arrow up/arrow down]")
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
function modemSideSelect(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("What side is your modem on?")
print("Select a side[arrow up/arrow down]")
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
------------------------------------------------------------------------------------------------------------
print("Are You Calling A Program?")
local choice = menu()
local sides = {"Right", "Back", "Left", "Front", "Top", "Bottom"}
local modemSide = modemSideSelect(sides)
if modemSide == 1 then
rednet.open("right")
elseif modemSide == 2 then
rednet.open("back")
elseif modemSide == 3 then
rednet.open("left")
elseif modemSide == 4 then
rednet.open("front")
elseif modemSide == 5 then
rednet.open("top")
elseif modemSide == 6 then
rednet.open("bottom")
end
print("What ID is your Turtle/PC?")
ID = io.read() --Find the ID of the receiving Turtle/PC
ID = tonumber(ID)
if choice == true then
print("Are You Sending To a Turtle?")
local choice2 = menu()
if choice2 == true then
while true do
local programs = {"Excavate", "Tunnel", "Lumberjack", "Dance", "Move", "Exit"}
local program = programSelect(programs)
if program == 1 then
info = "Excavate"
rednet.send(ID, info)
local TID, question = rednet.receive(10)
if TID == ID then
print(question)
info2 = io.read()
rednet.send(ID, info2)
else
print("Out-of-Range or Interferance, try again later.")
end
elseif program == 2 then
info = "Tunnel"
rednet.send(ID, info)
local TID, question = rednet.receive(10)
if TID == ID then
print(question)
info2 = io.read()
rednet.send(ID, info2)
else
print("Out-of-Range or Interferance, try again later.")
end
elseif program == 3 then
info = "Lumberjack"
rednet.send(ID, info)
elseif program == 4 then
info = "Dance"
rednet.send(ID, info)
elseif program == 5 then
local dirs = {"Right", "Back", "Left", "Forward", "Up", "Down", "Back"}
while true do
local dir = programSelect(dirs)
if dir == 1 then
info = "right"
rednet.send(ID, info)
elseif dir == 2 then
info = "back"
rednet.send(ID, info)
elseif dir == 3 then
info = "left"
rednet.send(ID, info)
elseif dir == 4 then
info = "forward"
rednet.send(ID, info)
elseif dir == 5 then
info = "up"
rednet.send(ID, info)
elseif dir == 6 then
info = "down"
rednet.send(ID, info)
elseif dir == 7 then
break
end
end
elseif program == 6 then
break
end
end
else
local programs = {DJ}
local program = programSelect(programs)
if program == 1 then
info = "DJ"
rednet.send(ID, info)
end
end
else
term.write("Info to send:")
local info = io.read() --Gather the info/program to send/run
end
if choice == false then
rednet.send(ID, info) -- Send the info
end
receive(Terminal Version)
Spoiler
function modemSideSelect(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("What side is your modem on?")
print("Select a side[arrow up/arrow down]")
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
local sides = {"Right", "Back", "Left", "Front", "Top", "Bottom"}
local modemSide = modemSideSelect(sides)
if modemSide == 1 then
rednet.open("right")
elseif modemSide == 2 then
rednet.open("back")
elseif modemSide == 3 then
rednet.open("left")
elseif modemSide == 4 then
rednet.open("front")
elseif modemSide == 5 then
rednet.open("top")
elseif modemSide == 6 then
rednet.open("bottom")
end
print("Now Listening forever for a message, press Ctl+T to exit")
id, message = rednet.receive() -- listen indefinatly for a message
if message == "DJ" then
shell.run("dj")
else
print("Incoming Info From PC/Turtle #",id)
print("Info:")
print(message)
end
end
receive(Turtle Version)
Spoiler
while true do
rednet.open("right") -- open ports so the turtle can "hear"
print("Now Listening forever for a message, press Ctl+T to exit")
id, message = rednet.receive() -- listen indefinatly for a message
if message == "Excavate" then
rednet.send(id, "Radius:")
local id2, answer = rednet.receive(10)
if id2 == id then
answer = tonumber(answer)
shell.run("Excavate ", answer)
else
print("Out-of-Range or Interferance, try again later.")
end
elseif message == "Tunnel" then
rednet.send(id, "How Far?")
local id2, answer = rednet.receive(10)
if id2 == id then
answer = tonumber(answer)
shell.run("Tunnel ", answer)
else
print("Out-of-Range or Interferance, try again later.")
end
elseif message == "Lumberjack" then
shell.run("Lumberjack")
elseif message == "Dance" then
shell.run("Dance")
elseif message == "right" then
turtle.turnRight()
turtle.forward()
elseif message == "back" then
turtle.back()
elseif message == "left" then
turtle.turnLeft()
turtle.forward()
elseif message == "forward" then
turtle.forward()
elseif message == "up" then
turtle.up()
elseif message == "down" then
turtle.down()
else
print("Incoming Info From PC/Turtle #",id)
print("Info:")
print(message)
end
end
Current programs you can call:
Turtles:
Move
Excavate
Tunnel
Lumberjack(Must have Tikiana's Lumberjack Script or other lumberjack program)
Dance
Terminals:
DJ
More Program Options to come!
I also made a modified version of Tikiana's Lumberjack Script that replants the tree when its done being cut down if there is a sapling in the bottom right corner of the turtle inventory.
Code,
Spoiler
while turtle.detect() do
print("Chopping")
turtle.dig()
turtle.digUp()
print("Moving")
turtle.up()
end
while not turtle.detect() and not turtle.detectDown() do
print("Moving down")
turtle.down()
print("Job done!")
programHasRan = 1
end
if programHasRan == 1 then
turtle.select(9)
turtle.place()
end
Download(If you cant/don't want to copy paste)
[attachment=133:CCCommunicator V2.0.zip]
Feel free to leave comments and suggestions in the replies!
Change Log
Spoiler
V 2.0Spoiler
Added Turtle movement controlsAdded modem side select instead of typing
Minor Changes to program select engine
Modified Tikiana's Lumberjack Script