Advertisement
cyber_Ahn

LanteaGate

Dec 24th, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.64 KB | None | 0 0
  1. -- Control Program fo LatenaCraft Stargate
  2.  
  3. local power = true
  4. local i = 3
  5. local fileDataX = {}
  6. --set gate--
  7. shell.run("delete caAPI")
  8. shell.run("pastebin get EDLdR1nF caAPI")
  9. os.loadAPI("caAPI")
  10. local hr = caAPI.get_hardware("stargate")
  11. if hr == "stargate_off" then
  12. shell.run("clear")
  13. else
  14. local sg = peripheral.wrap(hr)
  15. end
  16.  
  17. --install database--
  18. shell.run("mkdir database")
  19. local found = fs.exists("database/gate.db")
  20. if found == false then
  21. local file = fs.open("database/gate.db","w")
  22. file.writeLine("Example Gate#DAAQAALAA")
  23. file.close()
  24. end
  25.  
  26. --monitor set--
  27. monitor_number = caAPI.get_hardware("monitor")
  28. local found = fs.exists("config/monitor.cfg")
  29. if found == true then
  30. file = fs.open("config/monitor.cfg","r")
  31. local fileData = {}
  32. local line = file.readLine()
  33. repeat
  34. table.insert(fileData,line)
  35. line = file.readLine()
  36. until line == nil
  37. file.close()
  38. monitor_number = fileData[1]
  39. end
  40. local mon = peripheral.wrap(monitor_number)
  41.  
  42. -- get sg data--
  43. function get_sg_data()
  44.  
  45. end
  46.  
  47. --add gate to db--
  48. function add_gate()
  49. mon.setTextColor(colors.black)
  50. mon.setBackgroundColor(colors.white)
  51. mon.setCursorPos(1,26)
  52. mon.write("Name:")
  53. nam = read()
  54. mon.setCursorPos(25,26)
  55. mon.write("Address:")
  56. ad = read()
  57. save = nam.."#"..ad
  58. local file = fs.open("database/gate.db","a")
  59. file.writeLine(save)
  60. file.close()
  61. mon.setCursorPos(2,25)
  62. mon.write(save)
  63. sleep(10)
  64. gate_list()
  65. end
  66.  
  67. --delete gate from db--
  68. function del_gate()
  69. mon.setTextColor(colors.black)
  70. mon.setBackgroundColor(colors.white)
  71. mon.setCursorPos(1,26)
  72. mon.write("Line Number:")
  73. num = read()
  74. table.remove(fileDataX,num)
  75. local file = fs.open("database/gate.db","w")
  76. for iux=1,#fileDataX do
  77. file.writeLine(fileDataX[iux])
  78. end
  79. file.close()
  80. gate_list()
  81. end
  82.  
  83. --gate list
  84. function gate_list()
  85. mon.clear()
  86. mon.setBackgroundColor(colors.white)
  87. mon.clear()
  88. mon.setBackgroundColor(colors.white)
  89. mon.clear()
  90. mon.setTextColor(colors.cyan)
  91. mon.setBackgroundColor(colors.black)
  92. mon.setCursorPos(25,1)
  93. mon.write("Gate List")
  94. mon.setCursorPos(1,1)
  95. mon.write("Gate Control V 0.1")
  96. mon.setCursorPos(50,1)
  97. mon.write("X")
  98. mon.setBackgroundColor(colors.cyan)
  99. mon.setCursorPos(1,2)
  100. mon.write("                                                  ")
  101. mon.setCursorPos(1,26)
  102. mon.write("                                                  ")
  103. mon.setBackgroundColor(colors.gray)
  104. mon.setCursorPos(13,3)
  105. mon.write("Add Gate")
  106. mon.setCursorPos(25,3)
  107. mon.write("Delete Gate")
  108. mon.setBackgroundColor(colors.black)
  109. mon.setCursorPos(2,4)
  110. mon.write("Name")
  111. mon.setCursorPos(25,4)
  112. mon.write("Address")
  113. file = fs.open("database/gate.db","r")
  114. fileDataX = {}
  115. local line = file.readLine()
  116. repeat
  117. table.insert(fileDataX,line)
  118. line = file.readLine()
  119. until line == nil
  120. file.close()
  121. mon.setTextColor(colors.black)
  122. local startcursor = 5
  123. for iu=1,#fileDataX do
  124. data = fileDataX[iu]
  125. index = string.find(data,"#")
  126. mon.setBackgroundColor(colors.gray)
  127. mon.setCursorPos(2,startcursor)
  128. mon.write(iu.."."..string.sub(data,1,index-1))
  129. mon.setBackgroundColor(colors.white)
  130. mon.setCursorPos(25,startcursor)
  131. mon.write(string.sub(data,index+1))
  132. startcursor = startcursor + 1
  133. end
  134. db_power = true
  135. while db_power == true do
  136. event,side,x,y = os.pullEvent()
  137. if event == "monitor_touch" then
  138. if x == 50 and y == 1 then
  139. db_power = false
  140. shell.run("monitor",monitor_number,"Stargate")
  141. end
  142. if x >= 12 and x <= 21 and y == 3 then
  143. add_gate()
  144. end
  145. if x >= 24 and x <= 36 and y == 3 then
  146. del_gate()
  147. end
  148. if y == 5 then
  149. data = fileDataX[1]
  150. index = string.find(data,"#")
  151. sg.dial(string.sub(data,index+1))
  152. sleep(60)
  153. sg.disconnect()
  154. gate_list()
  155. end
  156. if y == 6 then
  157. data = fileDataX[2]
  158. index = string.find(data,"#")
  159. sg.dial(string.sub(data,index+1))
  160. sleep(60)
  161. sg.disconnect()
  162. gate_list()
  163. end
  164. if y == 7 then
  165. data = fileDataX[3]
  166. index = string.find(data,"#")
  167. sg.dial(string.sub(data,index+1))
  168. sleep(60)
  169. sg.disconnect()
  170. gate_list()
  171. end
  172. if y == 8 then
  173. data = fileDataX[4]
  174. index = string.find(data,"#")
  175. sg.dial(string.sub(data,index+1))
  176. sleep(60)
  177. sg.disconnect()
  178. gate_list()
  179. end
  180. if y == 9 then
  181. data = fileDataX[5]
  182. index = string.find(data,"#")
  183. sg.dial(string.sub(data,index+1))
  184. sleep(60)
  185. sg.disconnect()
  186. gate_list()
  187. end
  188. if y == 10 then
  189. data = fileDataX[6]
  190. index = string.find(data,"#")
  191. sg.dial(string.sub(data,index+1))
  192. sleep(60)
  193. sg.disconnect()
  194. gate_list()
  195. end
  196. if y == 11 then
  197. data = fileDataX[7]
  198. index = string.find(data,"#")
  199. sg.dial(string.sub(data,index+1))
  200. sleep(60)
  201. sg.disconnect()
  202. gate_list()end
  203. if y == 12 then
  204. data = fileDataX[8]
  205. index = string.find(data,"#")
  206. sg.dial(string.sub(data,index+1))
  207. sleep(60)
  208. sg.disconnect()
  209. gate_list()
  210. end
  211. if y == 13 then
  212. data = fileDataX[9]
  213. index = string.find(data,"#")
  214. sg.dial(string.sub(data,index+1))
  215. sleep(60)
  216. sg.disconnect()
  217. gate_list()
  218. end
  219. if y == 14 then
  220. data = fileDataX[10]
  221. index = string.find(data,"#")
  222. sg.dial(string.sub(data,index+1))
  223. sleep(60)
  224. sg.disconnect()
  225. gate_list()
  226. end
  227. if y == 15 then
  228. data = fileDataX[11]
  229. index = string.find(data,"#")
  230. sg.dial(string.sub(data,index+1))
  231. sleep(60)
  232. sg.disconnect()
  233. gate_list()
  234. end
  235. if y == 16 then
  236. data = fileDataX[12]
  237. index = string.find(data,"#")
  238. sg.dial(string.sub(data,index+1))
  239. sleep(60)
  240. sg.disconnect()
  241. gate_list()
  242. end
  243. if y == 17 then
  244. data = fileDataX[13]
  245. index = string.find(data,"#")
  246. sg.dial(string.sub(data,index+1))
  247. sleep(60)
  248. sg.disconnect()
  249. gate_list()
  250. end
  251. if y == 18 then
  252. data = fileDataX[14]
  253. index = string.find(data,"#")
  254. sg.dial(string.sub(data,index+1))
  255. sleep(60)
  256. sg.disconnect()
  257. gate_list()
  258. end
  259. if y == 19 then
  260. data = fileDataX[15]
  261. index = string.find(data,"#")
  262. sg.dial(string.sub(data,index+1))
  263. sleep(60)
  264. sg.disconnect()
  265. gate_list()
  266. end
  267. if y == 20 then
  268. data = fileDataX[16]
  269. index = string.find(data,"#")
  270. sg.dial(string.sub(data,index+1))
  271. sleep(60)
  272. sg.disconnect()
  273. gate_list()
  274. end
  275. end
  276. end
  277. end
  278.  
  279. --dial--
  280. function dial(address)
  281. sg.dial(address)
  282. sleep(60)
  283. sg.disconnect()
  284. shell.run("monitor",monitor_number,"Stargate")
  285. end
  286.  
  287. --input address--
  288. function input_add()
  289. mon.setCursorPos(22,16)
  290. add = read()
  291. if(add == "disconnect") then
  292. sg.disconnect()
  293. else
  294. dial(add)
  295. end
  296. end
  297.  
  298. --draw screen--
  299. function draw_screen()
  300. mon.clear()
  301. mon.setTextColor(colors.cyan)
  302. mon.setBackgroundColor(colors.black)
  303. mon.clear()
  304. mon.setCursorPos(1,1)
  305. mon.write("Gate Control V 0.5  "..hr)
  306. mon.setCursorPos(50,1)
  307. mon.write("X")
  308. mon.setBackgroundColor(colors.cyan)
  309. mon.setCursorPos(1,2)
  310. mon.write("                                                  ")
  311. mon.setCursorPos(1,26)
  312. mon.write("                                                  ")
  313. while i<26 do
  314. mon.setCursorPos(1,i)
  315. mon.write(" ")
  316. mon.setCursorPos(50,i)
  317. mon.write(" ")
  318. i = i+1
  319. end
  320. i=3
  321. mon.setBackgroundColor(colors.black)
  322. draw_gate(22,8)
  323. mon.setBackgroundColor(colors.gray)
  324. mon.setCursorPos(16,16)
  325. mon.write("Dial:")
  326. mon.setCursorPos(3,17)
  327. mon.write("Gate List")
  328. mon.setCursorPos(30,17)
  329. mon.write("Shotdown Wormhole")
  330. mon.setBackgroundColor(colors.black)
  331. end
  332.  
  333. --draw gate--
  334. function draw_gate(posx,posy)
  335. mon.setBackgroundColor(colors.cyan)
  336. mon.setCursorPos(posx,posy)
  337. mon.write("  ")
  338. mon.setBackgroundColor(colors.black)
  339. mon.setCursorPos(posx+2,posy)
  340. mon.write("v")
  341. mon.setBackgroundColor(colors.cyan)
  342. mon.setCursorPos(posx+3,posy)
  343. mon.write("  ")
  344. mon.setCursorPos(posx-2,posy+1)
  345. mon.write("  ")
  346. mon.setCursorPos(posx+5,posy+1)
  347. mon.write("  ")
  348. mon.setBackgroundColor(colors.black)
  349. mon.setCursorPos(posx-3,posy+2)
  350. mon.write(">")
  351. mon.setCursorPos(posx+7,posy+2)
  352. mon.write("<")
  353. mon.setBackgroundColor(colors.cyan)
  354. mon.setCursorPos(posx-4,posy+3)
  355. mon.write(" ")
  356. mon.setCursorPos(posx+8,posy+3)
  357. mon.write(" ")
  358. mon.setCursorPos(posx-4,posy+4)
  359. mon.write(" ")
  360. mon.setCursorPos(posx+8,posy+4)
  361. mon.write(" ")
  362. mon.setBackgroundColor(colors.black)
  363. mon.setCursorPos(posx-3,posy+5)
  364. mon.write(">")
  365. mon.setCursorPos(posx+7,posy+5)
  366. mon.write("<")
  367. mon.setBackgroundColor(colors.cyan)
  368. mon.setCursorPos(posx-2,posy+6)
  369. mon.write("  ")
  370. mon.setCursorPos(posx+5,posy+6)
  371. mon.write("  ")
  372. mon.setCursorPos(posx,posy+7)
  373. mon.write("     ")
  374. mon.setBackgroundColor(colors.black)
  375. mon.setCursorPos(posx+1,posy+7)
  376. mon.write("^")
  377. mon.setCursorPos(posx+3,posy+7)
  378. mon.write("^")
  379. end
  380.  
  381. --input-touch--
  382. function input_touch()
  383. power = true
  384. while power == true do
  385. event,side,x,y = os.pullEvent()
  386. if event == "monitor_touch" then
  387. if x == 50 and y == 1 then
  388. power = false
  389. shell.run("clear")
  390. end
  391. if x >= 15 and x <= 21 and y == 16 then
  392. input_add()
  393. end
  394. if x >= 2 and x <= 12 and y == 17 then
  395. power = false
  396. gate_list()
  397. end
  398. if x >= 30 and x <= 48 and y == 17 then
  399. sg.disconnect()
  400. shell.run("monitor",monitor_number,"Stargate")
  401. end
  402. end
  403. end
  404. end
  405.  
  406. --program--
  407. draw_screen()
  408. get_sg_data()
  409. input_touch()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement