Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Control Program fo LatenaCraft Stargate
- local power = true
- local i = 3
- local fileDataX = {}
- --set gate--
- shell.run("delete caAPI")
- shell.run("pastebin get EDLdR1nF caAPI")
- os.loadAPI("caAPI")
- local hr = caAPI.get_hardware("stargate")
- if hr == "stargate_off" then
- shell.run("clear")
- else
- local sg = peripheral.wrap(hr)
- end
- --install database--
- shell.run("mkdir database")
- local found = fs.exists("database/gate.db")
- if found == false then
- local file = fs.open("database/gate.db","w")
- file.writeLine("Example Gate#DAAQAALAA")
- file.close()
- end
- --monitor set--
- monitor_number = caAPI.get_hardware("monitor")
- local found = fs.exists("config/monitor.cfg")
- if found == true then
- file = fs.open("config/monitor.cfg","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- monitor_number = fileData[1]
- end
- local mon = peripheral.wrap(monitor_number)
- -- get sg data--
- function get_sg_data()
- end
- --add gate to db--
- function add_gate()
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,26)
- mon.write("Name:")
- nam = read()
- mon.setCursorPos(25,26)
- mon.write("Address:")
- ad = read()
- save = nam.."#"..ad
- local file = fs.open("database/gate.db","a")
- file.writeLine(save)
- file.close()
- mon.setCursorPos(2,25)
- mon.write(save)
- sleep(10)
- gate_list()
- end
- --delete gate from db--
- function del_gate()
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,26)
- mon.write("Line Number:")
- num = read()
- table.remove(fileDataX,num)
- local file = fs.open("database/gate.db","w")
- for iux=1,#fileDataX do
- file.writeLine(fileDataX[iux])
- end
- file.close()
- gate_list()
- end
- --gate list
- function gate_list()
- mon.clear()
- mon.setBackgroundColor(colors.white)
- mon.clear()
- mon.setBackgroundColor(colors.white)
- mon.clear()
- mon.setTextColor(colors.cyan)
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(25,1)
- mon.write("Gate List")
- mon.setCursorPos(1,1)
- mon.write("Gate Control V 0.1")
- mon.setCursorPos(50,1)
- mon.write("X")
- mon.setBackgroundColor(colors.cyan)
- mon.setCursorPos(1,2)
- mon.write(" ")
- mon.setCursorPos(1,26)
- mon.write(" ")
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(13,3)
- mon.write("Add Gate")
- mon.setCursorPos(25,3)
- mon.write("Delete Gate")
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(2,4)
- mon.write("Name")
- mon.setCursorPos(25,4)
- mon.write("Address")
- file = fs.open("database/gate.db","r")
- fileDataX = {}
- local line = file.readLine()
- repeat
- table.insert(fileDataX,line)
- line = file.readLine()
- until line == nil
- file.close()
- mon.setTextColor(colors.black)
- local startcursor = 5
- for iu=1,#fileDataX do
- data = fileDataX[iu]
- index = string.find(data,"#")
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(2,startcursor)
- mon.write(iu.."."..string.sub(data,1,index-1))
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(25,startcursor)
- mon.write(string.sub(data,index+1))
- startcursor = startcursor + 1
- end
- db_power = true
- while db_power == true do
- event,side,x,y = os.pullEvent()
- if event == "monitor_touch" then
- if x == 50 and y == 1 then
- db_power = false
- shell.run("monitor",monitor_number,"Stargate")
- end
- if x >= 12 and x <= 21 and y == 3 then
- add_gate()
- end
- if x >= 24 and x <= 36 and y == 3 then
- del_gate()
- end
- if y == 5 then
- data = fileDataX[1]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 6 then
- data = fileDataX[2]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 7 then
- data = fileDataX[3]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 8 then
- data = fileDataX[4]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 9 then
- data = fileDataX[5]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 10 then
- data = fileDataX[6]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 11 then
- data = fileDataX[7]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()end
- if y == 12 then
- data = fileDataX[8]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 13 then
- data = fileDataX[9]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 14 then
- data = fileDataX[10]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 15 then
- data = fileDataX[11]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 16 then
- data = fileDataX[12]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 17 then
- data = fileDataX[13]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 18 then
- data = fileDataX[14]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 19 then
- data = fileDataX[15]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- if y == 20 then
- data = fileDataX[16]
- index = string.find(data,"#")
- sg.dial(string.sub(data,index+1))
- sleep(60)
- sg.disconnect()
- gate_list()
- end
- end
- end
- end
- --dial--
- function dial(address)
- sg.dial(address)
- sleep(60)
- sg.disconnect()
- shell.run("monitor",monitor_number,"Stargate")
- end
- --input address--
- function input_add()
- mon.setCursorPos(22,16)
- add = read()
- if(add == "disconnect") then
- sg.disconnect()
- else
- dial(add)
- end
- end
- --draw screen--
- function draw_screen()
- mon.clear()
- mon.setTextColor(colors.cyan)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.write("Gate Control V 0.5 "..hr)
- mon.setCursorPos(50,1)
- mon.write("X")
- mon.setBackgroundColor(colors.cyan)
- mon.setCursorPos(1,2)
- mon.write(" ")
- mon.setCursorPos(1,26)
- mon.write(" ")
- while i<26 do
- mon.setCursorPos(1,i)
- mon.write(" ")
- mon.setCursorPos(50,i)
- mon.write(" ")
- i = i+1
- end
- i=3
- mon.setBackgroundColor(colors.black)
- draw_gate(22,8)
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(16,16)
- mon.write("Dial:")
- mon.setCursorPos(3,17)
- mon.write("Gate List")
- mon.setCursorPos(30,17)
- mon.write("Shotdown Wormhole")
- mon.setBackgroundColor(colors.black)
- end
- --draw gate--
- function draw_gate(posx,posy)
- mon.setBackgroundColor(colors.cyan)
- mon.setCursorPos(posx,posy)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(posx+2,posy)
- mon.write("v")
- mon.setBackgroundColor(colors.cyan)
- mon.setCursorPos(posx+3,posy)
- mon.write(" ")
- mon.setCursorPos(posx-2,posy+1)
- mon.write(" ")
- mon.setCursorPos(posx+5,posy+1)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(posx-3,posy+2)
- mon.write(">")
- mon.setCursorPos(posx+7,posy+2)
- mon.write("<")
- mon.setBackgroundColor(colors.cyan)
- mon.setCursorPos(posx-4,posy+3)
- mon.write(" ")
- mon.setCursorPos(posx+8,posy+3)
- mon.write(" ")
- mon.setCursorPos(posx-4,posy+4)
- mon.write(" ")
- mon.setCursorPos(posx+8,posy+4)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(posx-3,posy+5)
- mon.write(">")
- mon.setCursorPos(posx+7,posy+5)
- mon.write("<")
- mon.setBackgroundColor(colors.cyan)
- mon.setCursorPos(posx-2,posy+6)
- mon.write(" ")
- mon.setCursorPos(posx+5,posy+6)
- mon.write(" ")
- mon.setCursorPos(posx,posy+7)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(posx+1,posy+7)
- mon.write("^")
- mon.setCursorPos(posx+3,posy+7)
- mon.write("^")
- end
- --input-touch--
- function input_touch()
- power = true
- while power == true do
- event,side,x,y = os.pullEvent()
- if event == "monitor_touch" then
- if x == 50 and y == 1 then
- power = false
- shell.run("clear")
- end
- if x >= 15 and x <= 21 and y == 16 then
- input_add()
- end
- if x >= 2 and x <= 12 and y == 17 then
- power = false
- gate_list()
- end
- if x >= 30 and x <= 48 and y == 17 then
- sg.disconnect()
- shell.run("monitor",monitor_number,"Stargate")
- end
- end
- end
- end
- --program--
- draw_screen()
- get_sg_data()
- input_touch()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement