Elrol

clientStartup

Apr 10th, 2020 (edited)
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. local guiColor = colors.green
  2. local port = 1 --The port to the server
  3. local id = 2 --The port to this terminal
  4. local name = "Test Terminal" --The display name of this terminal
  5. local side = "back"
  6.  
  7. os.loadAPI("client")
  8. os.loadAPI("menu")
  9.  
  10. local logs = {
  11.     {
  12.         "log1",
  13.         "04.08.2020",
  14.         "Updated the firmware of the terminal.",
  15.         "This should allow me to log the happenings of the vault from here on out."
  16.     },
  17.     {
  18.         "log2",
  19.         "04.10.2020",
  20.         "Rewrote a lot of the software to allow the terminals to connect to a server."
  21.     }
  22. }
  23.  
  24. function saveTable(table,name)
  25.     local file = fs.open(name,"w")
  26.     file.write(textutils.serialize(table))
  27.     file.close()
  28. end
  29.  
  30. function loadTable(name)
  31.     local t = nil
  32.     local file = fs.open(name,"r")
  33.     if file then
  34.         local data = file.readAll()
  35.         t = textutils.unserialize(data)
  36.         file.close()
  37.     end
  38.     return t
  39. end
  40.  
  41. local logMenu = {}
  42. local temp = loadTable("logs.txt")
  43. if temp then logs = temp end
  44.  
  45. for index = 1, #logs do
  46.     local value = logs[index]
  47.     local key = ""
  48.     local v1 = ""
  49.     local v2 = ""
  50.     for nameCount = 1, #value do
  51.         if nameCount == 1 then key = value[nameCount]
  52.         elseif nameCount == 2 then v1 = value[nameCount]
  53.         else v2 = v2..value[nameCount].." " end
  54.     end
  55.     menu.newText(key, v1, v2)
  56.     logMenu[#logMenu +1] = {"read "..key, v1}
  57. end
  58. logMenu[#logMenu +1] = {"open start", "Back"}
  59. saveTable(logs, "logs.txt")
  60.  
  61. menu.newMenu("start", "Overseer's Terminal", {
  62.     --To add a bundled option: {colors.color, "Label", inverted}
  63.     {"open ".."tools", "Management"},
  64.     {"open ".."people", "Residents"},
  65.     {"open ".."log", "Logs"}
  66. })
  67.  
  68. menu.newMenu("tools", "Vault Management", {
  69.     {"toggle "..colors.white, "Lights", true},
  70.     {"trigger "..colors.red, "Overseer's Tunnel", false},
  71.     {"open ".."start", "Back"}
  72. })
  73.  
  74. menu.newMenu("people", "Residents", {
  75.     {"read ".."resElrol", "Elrol_Arrowsend"},
  76.     {"read ".."resMage", "_BlackMage_"},
  77.     {"read ".."resToby", "BaconEater_Toby"},
  78.     {"open ".."start", "Back"}
  79. })
  80.  
  81. menu.newMenu("log", "Logs", logMenu)
  82.  
  83. menu.newText("resElrol", "Elrol_Arrowsend", "Overseer of Vault 404")
  84. menu.newText("resMage", "_BlackMage_", "Manipulator of worlds")
  85. menu.newText("resToby", "BaconEater_Toby", "Apprentice to _BlackMage_")
  86.  
  87. client.init(guiColor, port, id, name, side)
  88.  
Add Comment
Please, Sign In to add comment