Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ComputerCraft StarGate Control, made by Parlocameon
- --Variables
- SMVERSION = "1.4"
- peripheralName = "stargate_2"
- defaultTermColor = colors.blue
- --Init
- function split(input)
- splitTable = {}
- for match in string.gmatch(input,"[^%s]+") do
- table.insert(splitTable,match)
- end
- return splitTable
- end
- function c_print(text,color)
- term.setTextColor(color)
- print(text)
- term.setTextColor(defaultTermColor)
- end
- term.setTextColor(defaultTermColor)
- stargate = peripheral.wrap(peripheralName)
- print("StarGate Management v"..SMVERSION)
- print()
- addressTable = {}
- if not fs.exists("stargate/") then
- fs.makeDir("stargate")
- print("Made stargate dir")
- end
- if fs.exists("stargate/address.table") then
- local fH = fs.open("stargate/address.table","r")
- addressTable = textutils.unserialize(fH.readAll())
- fH.close()
- c_print("Addresses imported successfully!",colors.green)
- else
- c_print("You're missing an address table!",colors.red)
- c_print("Please use assign <name> <address> on",colors.red)
- c_print("each address you would like to include",colors.red)
- c_print("and run the export command",colors.red)
- end
- while true do
- print()
- command = read()
- print()
- commandArgs = split(command)
- if commandArgs[1] == "dial" then
- address = string.sub(command,6)
- if stargate.energyToDial(address) > stargate.energyAvailable() then
- c_print("You have insufficient power",colors.red)
- c_print("In order to dial this address you need "..tostring(energyToDial()).."RF", colors.red)
- c_print("The current available power is "..tostring(energyAvailable()).."RF", colors.red)
- else
- print("Dialing "..address)
- stargate.dial(address)
- end
- elseif command == "disconnect" then
- c_print("Disconnected Stargate",colors.green)
- stargate.disconnect()
- elseif commandArgs[1] == "assign" then
- table.insert(addressTable,{ name = commandArgs[2], address = commandArgs[3]})
- print("Assigned name "..commandArgs[2].." to address "..commandArgs[3])
- elseif command == "listGates" then
- for k,table in pairs(addressTable) do
- print("ID: "..k.." Name: "..table.name.." Address: "..table.address)
- end
- elseif commandArgs[1] == "qdial" then
- qDTable = addressTable[tonumber(commandArgs[2])]
- if stargate.energyToDial(qDTable.address) > stargate.energyAvailable() then
- c_print("You have insufficient power",colors.red)
- c_print("In order to dial "..qDTable.name.." you need "..tostring(stargate.energyToDial(qDTable.address)).."RF", colors.red)
- c_print("The current available power is "..tostring(stargate.energyAvailable()).."RF",colors.red)
- else
- print("Dialing "..qDTable.name)
- stargate.dial(qDTable.address)
- end
- elseif command == "export" then
- local fH = fs.open("stargate/address.table","w")
- fH.writeLine(textutils.serialize(addressTable))
- fH.close()
- c_print("Exported addresses successfully",colors.green)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement