Advertisement
AlexMastang

boom

Sep 10th, 2023 (edited)
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.63 KB | None | 0 0
  1. -- variables
  2. -- constants
  3. local bp = true
  4. --local pw = "iboom45" -- doesn't make difference if you use lower or uppercase
  5. local pwu = ""
  6. local t = 15.0 -- seconds
  7. local s = 0.0
  8. local m = 0.0
  9. local td = 0.1
  10. local ts = 0.0
  11. local tf = t
  12. local data = "data.txt"
  13. local data_path = ""
  14. local scrt_path = ""
  15. -- sides responsible for input & output
  16. local inp = "bottom"
  17. local out = "left"
  18.  
  19. -- all the sides possible
  20. local sides = {
  21.     "top",
  22.     "bottom",
  23.     "right",
  24.     "left",
  25.     "front",
  26.     "back"
  27. }
  28.  
  29. -- FUNCTIONS
  30. -- divider
  31. local function divider(char)
  32.     term.setTextColor(colors.white)
  33.     local w, h = term.getSize()
  34.     for i=1,w do
  35.         write(char)
  36.     end
  37. end
  38.  
  39. -- checks if the file exists
  40. local function file_exists(file)
  41.     local f = io.open(file, "rb")
  42.     if f then f:close() end
  43.     return f ~= nil
  44. end
  45.  
  46. -- creates the file
  47. local function create_file(file)
  48.     local f = io.open(file, "w")
  49.     f:close()
  50. end
  51.  
  52. -- NON FUNZIONA CAZZO, COSA DOVREI USARE???
  53. -- spits out the file path the script in running in
  54. local function script_path()
  55.     local str = debug.getinfo(2, "S").source:sub(2)
  56.     return str:match("(.*/)")
  57. end
  58.  
  59. local function get_lines(file)
  60.     local lines = {}
  61.     -- io.lines returns an iterator, so we need to manually unpack it into an array
  62.     for line in io.lines(file) do
  63.         lines[#lines+1] = line
  64.     end
  65.     return lines
  66. end
  67.  
  68.  
  69. -- MAIN
  70. -- if a monitor is detected, it redirects the output to that
  71. local monitor = peripheral.find("monitor")
  72. if monitor then
  73.     term.redirect(monitor)
  74. end
  75.  
  76. -- does all the scap responsible for the security
  77. scrt_path = script_path()
  78. data_path = scrt_path .. data
  79. -- checks if the file exists in the first place
  80. print("Checking data file in " .. scrt_path .. "...")
  81. if not file_exists(data_path) then
  82.     -- if not then it creates it and lets the user pick the new password
  83.     print("The file has not been found")
  84.     print("Creating data file in " .. scrt_path .. "...")
  85.     create_file(data_path)
  86.     print("Created!")
  87.     -- new password input
  88.     term.clear()
  89.     term.setTextColor(colors.white)
  90.     term.setCursorPos(1,1)
  91.     print("MISSILE PASSWORD SELECTOR")
  92.     divider("=")
  93.     print("Insert the new password:")
  94.     write("-> ")
  95.     pwu = read("*")
  96.     local f = io.open(data_path, "w")
  97.     f:write(pwu)
  98.     -- all done
  99.     print("The new password has been selected")
  100.     print("Rebooting...")
  101.     os.reboot()
  102. else
  103.     -- if it exists it just reads it from it
  104.     print("File has been found")
  105.     print("Reading data...")
  106.     local f = get_lines(data_path)
  107.     pw = f[1]
  108. end
  109. f:close()
  110. print("All done!")
  111.  
  112. -- resets all the sides redstone outputs to 0
  113. for g=1,#sides do
  114.     rs.setOutput(sides[g], false)
  115. end
  116. os.sleep(1)
  117. term.clear()
  118.  
  119. -- password
  120. pw = string.lower(pw)
  121. while bp do
  122.     term.clear()
  123.     term.setTextColor(colors.white)
  124.     term.setCursorPos(1,1)
  125.     print("MISSILE SEQUENCE VERIFIER")
  126.     divider("=")
  127.     print("Insert the password:")
  128.     write("-> ")
  129.     pwu = read("*")
  130.     if string.lower(pwu) == pw then
  131.         bp = false
  132.         term.setTextColor(colors.lime)
  133.         print("CORRECT PASSWORD, YOU MAY PROCEED")
  134.         os.sleep(3)
  135.     else
  136.         term.setTextColor(colors.red)
  137.         local x, y = term.getCursorPos()
  138.         for i=5,0,-1 do
  139.             term.setCursorPos(x, y)
  140.             print("INCORRECT PASSWORD, PLEASE RETRY IN: " .. i .. "s")
  141.             os.sleep(1)
  142.         end
  143.     end
  144. end
  145.  
  146. -- checks for an input on the said side, if it does it lets that side powered
  147. term.clear()
  148. term.setTextColor(colors.white)
  149. term.setCursorPos(1,1)
  150. print("WAITING FOR SIGNAL")
  151. divider("=")
  152. while not rs.getInput(inp) do
  153.     os.sleep(0.02)
  154. end
  155. rs.setOutput(inp, true)
  156.  
  157. -- timer
  158. term.clear()
  159. term.setCursorPos(1,2)
  160. divider("=")
  161. -- loop
  162. for g=t,0.0,-td do
  163.     term.setCursorPos(1,1)
  164.     -- color for the main text
  165.     if tf-g > 0.5 then
  166.         tf = g
  167.         term.setTextColor(colors.red)
  168.     else
  169.         term.setTextColor(colors.yellow)
  170.     end
  171.     print("MISSILE LAUNCH SISTEM")
  172.     -- real timer
  173.     term.setCursorPos(1,3)
  174.     write("-> ")
  175.     ts = g/t
  176.     if ts > 0.5 then
  177.         term.setTextColor(colors.lime)
  178.     elseif ts > 0.2 and ts < 0.5 then
  179.         term.setTextColor(colors.yellow)
  180.     else
  181.         term.setTextColor(colors.red)
  182.     end
  183.     s = g
  184.     m = s / 60
  185.     s = math.floor(s % 60)
  186.     m = math.floor(m % 60)
  187.     write(m .. ":" .. s .. "." .. math.floor((g-math.floor(g))*10) .. "    ")
  188.     print()
  189.     os.sleep(td)
  190. end
  191. term.setTextColor(colors.white)
  192.  
  193. -- final output
  194. rs.setOutput(out, true)
  195. divider("=")
  196. print("MISSILE LAUNCHED")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement