· 10 months ago · Feb 26, 2025, 06:50 PM
1-- Fallout Terminal for ComputerCraft 1.12.2
2-- Features: Hacking Minigame, Door Control, Auto-Reset
3
4local doorSide = "bottom" -- Change to where the redstone signal is sent
5local resetTime = 5 * 60 -- Time in seconds before terminal resets
6local idleTime = 120 -- Time in seconds before auto-reset due to inactivity
7local hacked = false
8local words = {"VAULT", "CODES", "LOCKS", "TERMS", "ROBOT", "STEEL", "HACKS"}
9local password = words[math.random(#words)]
10local chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*"
11local grid = {}
12local selected = nil
13local highlighted = nil
14
15-- Function to generate corrupted logs
16local function generateCorruptData()
17 local data = "DATA CORRUPTED\n"
18 for i = 1, 10 do
19 local line = ""
20 for j = 1, math.random(10, 25) do
21 line = line .. chars:sub(math.random(1, #chars), math.random(1, #chars))
22 end
23 data = data .. line .. "\n"
24 end
25 return data
26end
27
28-- Function to pulse a bundled cable signal
29local function pulseBundledSignal(color)
30 for i = 1, 8 do
31 redstone.setBundledOutput(doorSide, color)
32 sleep(0.2)
33 redstone.setBundledOutput(doorSide, 0)
34 sleep(0.2)
35 end
36end
37
38-- Function to draw the hacking grid
39local function drawHackingGrid()
40 term.clear()
41 term.setCursorPos(1, 1)
42 print("== VAULT SECURITY TERMINAL ==")
43 print("Select the correct password")
44
45 for y = 1, 10 do
46 grid[y] = {}
47 for x = 1, 10 do
48 grid[y][x] = chars:sub(math.random(1, #chars), math.random(1, #chars))
49 if highlighted and highlighted[1] == x and highlighted[2] == y then
50 term.setTextColor(colors.yellow)
51 else
52 term.setTextColor(colors.white)
53 end
54 term.setCursorPos((x * 2) - 1, y + 2)
55 term.write(" " .. grid[y][x])
56 end
57 end
58 term.setTextColor(colors.white)
59end
60
61-- Function to handle mouse input
62local function handleMouseInput()
63 local event, button, x, y = os.pullEvent("mouse_click")
64 if button == 1 then -- Left click
65 local row = math.floor((y - 2) / 1) + 1
66 local col = math.floor(x / 2) + 1
67 if grid[row] and grid[row][col] then
68 selected = grid[row][col]
69 grid[row][col] = " "
70 drawHackingGrid()
71 end
72 end
73end
74
75-- Function to handle mouse hover
76local function handleMouseHover()
77 while true do
78 local event, button, x, y = os.pullEvent("mouse_move")
79 local row = math.floor((y - 2) / 1) + 1
80 local col = math.floor(x / 2) + 1
81 if row >= 1 and row <= 10 and col >= 1 and col <= 10 then
82 highlighted = {col, row}
83 else
84 highlighted = nil
85 end
86 drawHackingGrid()
87 end
88end
89
90-- Function to simulate hacking minigame
91local function hackingGame()
92 drawHackingGrid()
93 parallel.waitForAny(handleMouseHover, handleMouseInput)
94
95 local attempts = 5
96 local startTime = os.clock()
97
98 while attempts > 0 do
99 if os.clock() - startTime > idleTime then
100 print("Timeout: Security system reset.")
101 sleep(2)
102 return false
103 end
104
105 local event = {os.pullEvent()}
106 if event[1] == "mouse_click" then
107 handleMouseInput()
108 if selected == password then
109 hacked = true
110 print("Access granted!")
111 sleep(1)
112 return true
113 else
114 attempts = attempts - 1
115 print("Incorrect! Attempts left: " .. attempts)
116 selected = nil
117 end
118 end
119 end
120
121 print("Security Lockout Engaged")
122 sleep(30)
123 return false
124end
125
126-- Function to show the terminal menu
127local function terminalMenu()
128 while hacked do
129 term.clear()
130 term.setCursorPos(1, 1)
131 print("== VAULT SECURITY TERMINAL ==")
132 print("1) Open Door")
133 print("2) Close Door")
134 print("3) Check Access Logs")
135 print("4) Exit")
136
137 write("[>] ")
138 local choice = read()
139
140 if choice == "1" then
141 print("Opening Door...")
142 pulseBundledSignal(colors.green)
143 elseif choice == "2" then
144 print("Closing Door...")
145 pulseBundledSignal(colors.red)
146 elseif choice == "3" then
147 print("Retrieving logs...")
148 sleep(1)
149 print(generateCorruptData())
150 sleep(4)
151 elseif choice == "4" then
152 print("Exiting terminal...")
153 sleep(1)
154 break
155 else
156 print("Invalid selection!")
157 sleep(1)
158 end
159 end
160end
161
162-- Function to reset the terminal after X minutes
163local function resetTimer()
164 sleep(resetTime)
165 hacked = false
166 password = words[math.random(#words)] -- Select a new random password
167 print("System reset. Hacking required again.")
168end
169
170-- Main execution
171while true do
172 if not hacked then
173 if hackingGame() then
174 parallel.waitForAny(terminalMenu, resetTimer)
175 else
176 password = words[math.random(#words)] -- Reset password after failed attempts
177 sleep(5)
178 end
179 else
180 terminalMenu()
181 end
182end
183