-- These are two ComputerCraft Lua programs that I've made for a Capture the Flag game in Tekkit.
-- This is a rough program and not considered complete. I'm posting it here for a RFC.
-- Check out my reddit thread at http://www.reddit.com/r/tekkit/comments/131787/work_in_progress_any_ideas_for_a_ctf_map/
-- Referee
-- The referee is a ComputerCraft computer that's intended to be in an observation area. It's programmed
-- to read signals from three bundled cables, and then provide a simple display on a monitor.
-- The bundled cable off the right is for the red team, the left is for the blue team, and the back is
-- reserved for a transmitter that signals the start of the game.
function checkError()
-- this will check to see if there's an error for either team's computer and return a bool
if (redstone.testBundledInput("left", colors.orange)) or (redstone.testBundledInput("right", colors.orange)) then
return true
else
return false
end
end
function checkReady()
-- this will check to see that both teams are ready to start the game
if (redstone.testBundledInput("left", colors.lime)) and (redstone.testBundledInput("right", colors.lime)) then
return true
else
return false
end
end
function setStart()
redstone.setBundledOutput("back", colors.white)
end
while true do
print("Please wait five seconds while I make sure there are no errors.\n")
sleep(5)
if (checkError()) then
print("There has been an error and I am unable to continue.")
print("Make sure there is a disk in the left disk drive of each team's computer.")
break
end
print("Ready to start.")
print("Waiting for each team to signal that they are ready.\n")
while true do
os.pullEvent("redstone")
if checkReady() then
print("Both teams ready!")
print("Starting game!")
setStart()
break
end
end
local win = false
while true do
monitor = peripheral.wrap("top")
monitor.setTextScale(1.5)
term.redirect(monitor)
os.pullEvent("redstone")
term.clear()
term.setCursorPos(10,1)
term.write("RED")
term.setCursorPos(20,1)
term.write("BLUE")
term.setCursorPos(1,2)
term.write("FLAG")
-- stuff for flag here
if (redstone.testBundledInput("right", colors.magenta)) then
term.setCursorPos(10,2)
term.write("STOLEN")
end
if (redstone.testBundledInput("left", colors.magenta)) then
term.setCursorPos(20,2)
term.write("STOLEN")
end
if (redstone.testBundledInput("left", colors.lightBlue)) then
-- red team has captured blue flag
term.setCursorPos(10,2)
term.write("CAPTURED!")
end
if (redstone.testBundledInput("right", colors.lightBlue)) then
term.setCursorPos(20,2)
term.write("CAPTURED!")
end
if (redstone.testBundledInput("left", colors.yellow)) then
term.clear()
term.setCursorPos(20,4)
term.write("GAME OVER!")
term.setCursorPos(20,5)
term.write("BLUE TEAM WINS!")
win = true
break
end
if (redstone.testBundledInput("right", colors.yellow)) then
term.clear()
term.setCursorPos(20,4)
term.write("GAME OVER!")
term.setCursorPos(17,5)
term.write("RED TEAM WINS!")
win = true
break
end
end
if win then
term.setCursorPos(1,18)
term.restore()
break
end
end
-- RedTeamBase
-- Each base has a ComputerCraft setup with two disk drives with bundled cable off the back, and
-- transmitters/receivers. The "flags" for the game are labeled floppy disks for ComputerCraft. The
-- program for each base is identical except where the red/blue things have been transposed.
function isStolen()
if disk.hasData("left") then
label = disk.getLabel("left")
if label == "Red Flag" then
return false
end
end
if disk.hasData("right") then
label = disk.getLabel("right")
if label == "Red Flag" then
return false
end
end
return true
end
function isCaptured()
if disk.hasData("left") then
label = disk.getLabel("left")
if label == "Blue Flag" then
return true
end
end
if disk.hasData("right") then
label = disk.getLabel("right")
if label == "Blue Flag" then
return true
end
end
return false
end
function amReady()
if disk.hasData("left") then
label = disk.getLabel("left")
if label == "Red Flag" then
return true
else
disk.setLabel("left", "Red Flag")
return true
end
else
return false
end
end
while true do
redstone.setBundledOutput("back",0)
if amReady() then
print("Ready to start!")
print("Press any key to signal the referee that your team is ready to start.")
local event, param1 = os.pullEvent("key")
print("Regeree signaled. Game will start once other team is ready.")
curOut = redstone.getBundledOutput("back")
newOut = colors.combine(curOut, colors.lime)
redstone.setBundledOutput("back",newOut)
while true do
if redstone.testBundledInput("back",colors.white) then -- start signal is on
print("Game started!")
while true do
if (isStolen()) then
-- turn on "stolen" signal
curOut = redstone.getBundledOutput("back")
newOut = colors.combine(curOut, colors.magenta)
redstone.setBundledOutput("back",newOut)
print("Flag stolen!")
else
-- turn off the "stolen" signal
curOut = redstone.getBundledOutput("back")
newOut = colors.subtract(curOut, colors.magenta)
redstone.setBundledOutput("back",newOut)
if isCaptured() then
-- turn on "captured" signal
curOut = redstone.getBundledOutput("back")
newOut = colors.combine(curOut, colors.lightBlue)
redstone.setBundledOutput("back",newOut)
print("Enemy flag captured! You must now wait 30 seconds before claiming victory.")
sleep(30) -- the team must hold onto the flag for a while before claiming victory
if not (isStolen()) and (isCaptured()) then
-- turn on win signal
curOut = redstone.getBundledOutput("back")
newOut = colors.combine(curOut, colors.yellow)
redstone.setBundledOutput("back",newOut)
print("Win conditions met. Check referee for final result.")
break
else
-- turn off captured signal
curOut = redstone.getBundledOutput("back")
newOut = colors.subtract(curOut, colors.lightBlue)
redstone.setBundledOutput("back",newOut)
print("Enemy flag retaken! Game continues!")
end
end
end
sleep(1)
end
break
else
sleep(1)
end
end
break
else
-- turn on the error signal
curOut = redstone.getBundledOutput("back")
newOut = colors.combine(curOut, colors.orange)
redstone.setBundledOutput("back",newOut)
print("ERROR: There must be a disk in the left drive before I can start.")
print("Insert a disk and restart the computer.")
break
end
end