Created
July 18, 2012 12:16
-
-
Save varesa/3135864 to your computer and use it in GitHub Desktop.
Lock for ComputerCraft (Minecraft mod)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- This is a program to lock a chest/door with computercraft | |
-- Made by Esa Varemo | |
-- | |
-- | |
-- NOTE: This file must be named 'startup', for the computer to load the program on startup | |
-- | |
file = io.open("password","r") | |
pwd = file:read() | |
file = io.open("admin_pwd","r") | |
admin_pwd = file:read() | |
local function clear() | |
term.clear() | |
term.setCursorPos(1,1) | |
end | |
local function reDraw() | |
clear() | |
write(prompt) | |
end | |
prompt = "Password:\n>>" | |
reDraw() | |
answer = "" | |
run = true | |
while run do | |
event, key = os.pullEventRaw() | |
if event == "char" then | |
answer = answer .. key | |
prompt = prompt .. "*" | |
reDraw() | |
elseif key == 14 then -- BACKSPACE | |
if string.len(answer) >= 1 then | |
answer = string.sub(answer, 1, -2) | |
prompt = string.sub(prompt , 1, -2) | |
reDraw() | |
end | |
elseif key == 28 then -- ENTER | |
if answer == pwd then | |
clear() | |
write("Correct!") | |
redstone.setOutput("back",true) | |
sleep(3) | |
redstone.setOutput("back",false) | |
os.shutdown() | |
elseif answer == admin_pwd then | |
clear() | |
run = false | |
else | |
clear() | |
print("Wrong") | |
sleep(1) | |
os.reboot() | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment