Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1)
- screenX, screenY = term.getSize()
- code = ""
- validOption = false
- pass = 22222
- abbruch = 33333
- startXpos = math.ceil(screenX/2) - 5
- startYpos = math.floor(screenY/2)
- t_keypad = {
- {text = "1", xPos = startXpos, yPos = startYpos, color = colours.yellow},
- {text = "2", xPos = startXpos + 4, yPos = startYpos, color = colours.yellow},
- {text = "3", xPos = startXpos + 8, yPos = startYpos, color = colours.yellow},
- {text = "4", xPos = startXpos, yPos = startYpos + 2, color = colours.yellow},
- {text = "5", xPos = startXpos + 4, yPos = startYpos + 2, color = colours.yellow},
- {text = "6", xPos = startXpos + 8, yPos = startYpos + 2, color = colours.yellow},
- {text = "7", xPos = startXpos, yPos = startYpos + 4, color = colours.yellow},
- {text = "8", xPos = startXpos + 4, yPos = startYpos + 4, color = colours.yellow},
- {text = "9", xPos = startXpos + 8, yPos = startYpos + 4, color = colours.yellow},
- {text = "0", xPos = startXpos + 4, yPos = startYpos + 6, color = colours.yellow},
- {text = "CLR", xPos = startXpos - 1, yPos = startYpos + 6, color = colours.lightBlue},
- {text = "ENT", xPos = startXpos + 7, yPos = startYpos + 6, color = colours.red}
- }
- function drawKeyPad()
- term.clear()
- term.setCursorPos(startXpos - 2, startYpos - 4) print("-Zugangscode-")
- term.setCursorPos(startXpos - 2, startYpos - 3) print("-------------")
- term.setCursorPos(startXpos - 2, startYpos - 2) print("|--- ---|")
- term.setCursorPos(startXpos - 2, startYpos - 1) print("-------------\n")
- term.setCursorPos(startXpos - 2, startYpos) print("| | | |")
- term.setCursorPos(startXpos - 2, startYpos + 1) print("-------------")
- term.setCursorPos(startXpos - 2, startYpos + 2) print("| | | |")
- term.setCursorPos(startXpos - 2, startYpos + 3) print("-------------")
- term.setCursorPos(startXpos - 2, startYpos + 4) print("| | | |")
- term.setCursorPos(startXpos - 2, startYpos + 5) print("-------------")
- term.setCursorPos(startXpos - 2, startYpos + 6) print("| | | |")
- term.setCursorPos(startXpos - 2, startYpos + 7) print("-------------")
- for i = 1, #t_keypad do
- term.setCursorPos(t_keypad[i].xPos, t_keypad[i].yPos)
- if type(t_keypad[i].color) == "number" then term.setTextColour(t_keypad[i].color) else term.setTextColour(colours.black) end
- write(t_keypad[i].text)
- end
- end
- function checkMouseClick(_xPos, _yPos)
- clicked = ""
- bool = false
- for i = 1, #t_keypad do
- if _xPos >= t_keypad[i].xPos and _xPos <= (t_keypad[i].xPos + (string.len(t_keypad[i].text) - 1)) and
- _yPos == t_keypad[i].yPos then
- text = t_keypad[i].text
- bool = true
- break
- end
- end
- return bool, text
- end
- drawKeyPad()
- while true do
- term.setCursorPos(startXpos + 2, startYpos - 2)
- write(" ")
- term.setCursorPos(startXpos + 2, startYpos - 2)
- write(string.rep("*", #code))
- event, button, x, y = os.pullEvent()
- if event == "mouse_click" then
- validOption, clicked = checkMouseClick(x, y)
- if validOption then
- if tonumber(clicked) and #code < 5 then
- code = code .. clicked
- elseif clicked == "CLR" then
- code = ""
- elseif clicked == "ENT" then
- code = tonumber(code)
- if code == pass then
- rs.setOutput("bottom",true)
- sleep(3)
- rs.setOutput("bottom",false)
- elseif code == abbruch then
- term.setCursorPos(1, 1)
- term.clear()
- term.setTextColour(colours.red)
- print("Aborted.\n")
- term.setTextColour(colours.black)
- break
- else
- term.setCursorPos(startXpos - 1, startYpos - 2)
- term.setTextColour(colours.red)
- write(" Invalid ")
- sleep(1.5)
- term.setTextColour(colours.white)
- term.setCursorPos(startXpos - 2, startYpos - 2) print("|--- ---|")
- term.setTextColour(colours.red)
- end
- code = ""
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment