Posted 19 June 2015 - 05:38 PM
[PS: If this post are not in the good section, please tell me !]
I create this program but i got a problem :
1. I set the password : login pass (for example). This draw gui..
2. When i type wrong text, i can pass.
You can download the program : pastebin get FUiBZ6DJ login
It's the program :
I create this program but i got a problem :
1. I set the password : login pass (for example). This draw gui..
2. When i type wrong text, i can pass.
You can download the program : pastebin get FUiBZ6DJ login
It's the program :
--Login program for MC - ComputerCraft Mod
--By Redall - This program is with GNU Public License, you can : modify, copy, rewrite the code, modify and post to me ([url="/cdn-cgi/l/email-protection"][email protected][/url]<script cf-hash='f9e31' type="text/javascript"> /* */</script>) or in the forum (http://www.computercraft.info/forums2/) !
--Lock computer with args
local tArgs = {...}
--Check pass on args
if #tArgs == 0 then
print("Usage: login <password>")
return
end
--CenterPrint API
function centerPrint(sText)
local w, h = term.getSize()
local x, y = term.getCursorPos()
x = math.max(math.floor((w / 2) - (#sText / 2)), 0)
term.setCursorPos(x, y)
print(sText)
end
--CRead API
local function cread()
local input = ''
local x,y = term.getCursorPos()
term.setCursorBlink(true)
repeat
term.setCursorPos(x,y)
term.write(input)
local ev, p1 = os.pullEvent()
if ev == 'char' then
if #input < 48 then
input = input .. p1
end
elseif ev == 'key' then
if p1 == keys.backspace then
term.clearLine()
paintutils.drawLine(1, 7, 51, 7, BackgroundColor)
paintutils.drawLine(2, 7, 49, 7, BackgroundColorForGui)
input = input:sub(1, #input - 1)
end
end
until ev == 'key' and p1 == keys.enter
term.setCursorBlink(false)
return input
end
--Colors settings
-- * Principal colors settings * --
BackgroundColor = colors.orange
TextColor = colors.white
BackgroundColorForGui = colors.red
TextColorForGui = colors.white
-- * Special colors * --
ErrorColor = colors.red
WarningColor = colors.yellow
-- * Settings for terminal size and pos * --
local xTerm, yTerm = term.getSize()
xn, yn = xTerm - (xTerm - 1), yTerm - (yTerm - 1)
xtBox = xBox - (xBox - 1)
yBoxT = yTerm - (yTerm - 3)
--Begin settings
term.setBackgroundColor(BackgroundColor) -- Setting for background color
term.setTextColor(TextColor) -- Setting for text color
--Begin program
function gotopass()
term.clear()
paintutils.drawFilledBox(xn, yn, xTerm, yBoxT, BackgroundColorForGui)
term.setCursorPos(xn, 2)
centerPrint("Computer Locked. Please enter password.")
term.setBackgroundColor(BackgroundColor)
term.setCursorPos(xn, 5)
centerPrint("Enter password :")
paintutils.drawLine(2, 7, 49, 7, BackgroundColorForGui)
term.setCursorPos(2, 7)
cread()
if input == pass then
term.setBackgroundColor(BackgroundColor)
term.clear()
paintutils.drawFilledBox(xn, yn, xTerm, yBoxT, BackgroundColorForGui)
term.setCursorPos(xn, 2)
centerPrint("You can pass.")
sleep(1)
term.setBackgroundColor(colors.black)
term.clear()
return
else
term.setBackgroundColor(BackgroundColor)
term.clear()
paintutils.drawFilledBox(xn, yn, xTerm, yBoxT, BackgroundColorForGui)
term.setCursorPos(xn, 2)
centerPrint("Wrong pass.")
sleep(1)
term.setBackgroundColor(colors.black)
term.clear()
gotopass()
end
end
gotopass()