Posted 22 July 2013 - 01:22 PM
Hello all, I have been using comptuercraft for a while to control the stargates plugin on my server, however currently it requires the user to type in the destination.
I would very much like to have a list they can scroll through and select which address they want to go to.
Below is the URL that serves the list of names.
http://projectbuilder.info/fetch.php?cmd=page&ID=gatedirectory
I'm still rather new to LUA, so I cannot figure out how to split this string up into an array, and then make a list from it, any help would be appreciated.
Below is my current code(I would still like an option in the menu to allow them to enter a custom address, as not all addresses are "public"):
Any help would be much appreciated.
I would very much like to have a list they can scroll through and select which address they want to go to.
Below is the URL that serves the list of names.
http://projectbuilder.info/fetch.php?cmd=page&ID=gatedirectory
I'm still rather new to LUA, so I cannot figure out how to split this string up into an array, and then make a list from it, any help would be appreciated.
Below is my current code(I would still like an option in the menu to allow them to enter a custom address, as not all addresses are "public"):
for k,v in pairs( peripheral.getNames()) do
if peripheral.getType(v) == "monitor" then
mon = peripheral.wrap(v)
end
end
local function centerprint(msg, y)
local w, h = term.getSize()
term.setCursorPos(math.floor((w-#msg)/2) + (#msg % 2 == 0 and 1 or 0), y or h/2)
print(msg)
end
local function moncenterprint(msg, y)
local w, h = mon.getSize()
mon.setCursorPos(math.floor((w-#msg)/2) + (#msg % 2 == 0 and 1 or 0), y or h/2)
mon.write(msg)
end
os.pullEvent=os.pullEventRaw
cb = peripheral.wrap("bottom")
out = peripheral.wrap("top")
id = os.getComputerLabel()
while true do
moncenterprint("StarGate Dialing", 1)
moncenterprint("Computer", 2)
centerprint("Stargate Auto Dialer", 2)
centerprint("Please enter a destination:", 3)
destination = read()
content = http.get("http://smp.projectbuilder.info/fetch.php?cmd=page&ID=dialgate&buffer=0&name=" .. destination)
s = content.readAll()
if s == 0 then
centerprint("Sorry, but you are not authorized to connect to this gate.")
mon.clear()
moncenterprint("Connection Not", 1)
moncenterprint("Authorized", 2)
elseif s == "" then
centerprint("Sorry but your destination does not seem to exist. Try being less specific.")
mon.clear()
moncenterprint("Destination Does", 1)
moncenterprint("Not Exist", 2)
else
centerprint("Dialing '".. s .. "'", 4)
mon.clear()
moncenterprint("Dialing", 1)
moncenterprint("'".. s .. "'", 2)
cb.setCommand("gate activate " .. id .. " " .. s)
cb.runCommand()
end
sleep(10)
term.clear()
mon.clear()
end
Any help would be much appreciated.