Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local state = "open"
- local doorSide = "back"
- local PWD = "123"
- local openTime = 3
- --pistonok: alsó = narancs
- -- felette = cyan
- -- oldalsó = fehér
- --zárolás: piros
- local function openDoor()
- local side = doorSide
- rs.setBundledOutput(side,colors.combine(colors.white,colors.cyan))
- sleep(0.2)
- rs.setBundledOutput(side,colors.white)
- sleep(0.2)
- rs.setBundledOutput(side,0)
- sleep(0.2)
- rs.setBundledOutput(side,colors.orange)
- sleep(0.2)
- rs.setBundledOutput(side,colors.combine(colors.orange,colors.cyan))
- sleep(0.2)
- rs.setBundledOutput(side,colors.orange)
- sleep(0.2)
- rs.setBundledOutput(side,0)
- sleep(0.2)
- rs.setBundledOutput(side,colors.cyan)
- sleep(0.2)
- rs.setBundledOutput(side,0)
- sleep(0.2)
- end
- local function closeDoor()
- local side = doorSide
- rs.setBundledOutput(side,colors.orange)
- sleep(0.2)
- rs.setBundledOutput(side,0)
- sleep(0.2)
- rs.setBundledOutput(side,colors.white)
- sleep(0.2)
- rs.setBundledOutput(side,colors.combine(colors.white,colors.orange))
- sleep(0.2)
- rs.setBundledOutput(side,colors.white)
- sleep(0.2)
- end
- local buttons = {}
- --buttons[1] = "ok2"
- --buttons[2] = "ok3"
- --print(table.getn(buttons))
- function setButton(name,text,x,y,w,h,textcolor,bgcolor)
- buttons[name] = {name=name,text=text,x=x,y=y,w=w,h=h,textcolor=textcolor,bgcolor=bgcolor}
- end
- --setButton("teszt","1",1,4,1,1,colors.white,colors.orange)
- function fillButtons()
- local num = 0
- for i=0,2 do
- for j=0,2 do
- num = num+1
- print(num)
- setButton("n"..num,num.."",j*4+3,i*2+3,3,1,colors.white,colors.orange)
- end
- end
- setButton("n0","0",7,9,3,1,colors.white,colors.orange)
- setButton("cancel"," ",3,9,3,1,colors.white,colors.red)
- setButton("enter"," ",11,9,3,1,colors.white,colors.green)
- end
- function clearMons(bgColor)
- local mons = {peripheral.find("monitor")}
- for mKey,mon in pairs(mons) do
- mon.setBackgroundColor(bgColor)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- end
- clearMons(colors.black)
- function drawButtons(side)
- local mons = {peripheral.find("monitor")}
- function draw(side)
- local mon = peripheral.wrap(side)
- for bKey,button in pairs(buttons) do
- local offsetX = button.w/2 - string.len(button.text)/2
- -- local offsetY = button.h/2 - string.len(button.text)/2
- local text = button.text
- for i=offsetX+string.len(button.text)+1,button.w do
- text=text.." "
- end
- for i=1,offsetX do
- text=" "..text
- end
- mon.setTextScale(0.5)
- for i=1,button.h do
- mon.setCursorPos(button.x,button.y+i-1)
- for j=1,string.len(text) do
- mon.setBackgroundColor(button.bgcolor)
- mon.write(" ")
- end
- end
- mon.setCursorPos(button.x,button.y+button.h/2)
- mon.setBackgroundColor(button.bgcolor)
- mon.setTextColor(button.textcolor)
- mon.write(text)
- --print("ok")
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- end
- end
- if side == "all" then
- for mKey,mon in pairs(mons) do
- draw(peripheral.getName(mon))
- end
- else
- draw(side)
- end
- end
- --setButton("n1","1",2,2,1,1,colors.white,colors.orange)
- fillButtons()
- local currentPass = {}
- local mons = {peripheral.find("monitor")}
- function resetAllPass()
- currentPass = {}
- for mKey,mon in pairs(mons) do
- currentPass[peripheral.getName(mon)] = ""
- end
- end
- resetAllPass()
- function drawPass(side)
- function draw(side,pass)
- local mon = peripheral.wrap(side)
- mon.setCursorPos(2,1)
- mon.setBackgroundColor(colors.cyan)
- mon.write(" ")
- mon.setCursorPos(3,1)
- for i=1,string.len(pass) do
- if i <= 11 then
- mon.write("*")
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- if side == "all" then
- for mKey,mon in pairs(mons) do
- local name = peripheral.getName(mon)
- draw(name,currentPass[name])
- end
- else
- draw(side,currentPass[side])
- end
- end
- function touched(side,xPos,yPos)
- for bKey,button in pairs(buttons) do
- if xPos >= button.x and xPos < button.x+button.w and yPos >= button.y and yPos < button.y+button.h then
- local ocolor = button.bgcolor
- buttons[bKey].bgcolor = colors.cyan
- drawButtons(side)
- local isNumber = false
- local num = 0
- while (not isNumber) and num <= 9 do
- isNumber = bKey == "n"..num
- num = num+1
- end
- if isNumber then
- currentPass[side] = currentPass[side]..button.text
- --print("SZAM")
- elseif bKey == "cancel" then
- currentPass[side] = ""
- elseif bKey == "enter" then
- if currentPass[side] == PWD then
- openDoor()
- sleep(openTime)
- closeDoor()
- else
- end
- currentPass[side] = ""
- end
- drawPass(side)
- sleep(0.1)
- buttons[bKey].bgcolor = ocolor
- drawButtons(side)
- end
- end
- end
- local function printLocked(side)
- local mon = peripheral.wrap(side)
- mon.setBackgroundColor(colors.red)
- mon.setTextColor(colors.white)
- mon.clear()
- mon.setCursorPos(5,5)
- mon.write("ZAROLVA")
- end
- --printLocked("monitor_3")
- function printAllLocked()
- for kMon,mon in pairs(mons) do
- printLocked(peripheral.getName(mon))
- end
- end
- clearMons(colors.black)
- drawPass("all")
- drawButtons("all")
- local locked = false
- local mainTimer = os.startTimer(1)
- while true do
- event,side,xPos,yPos = os.pullEvent()
- if event == "monitor_touch" and (not locked) then
- touched(side,xPos,yPos)
- elseif event == "redstone" or event == "timer" then
- local rsInput = rs.getBundledInput(doorSide)
- local toLock = colors.test(rsInput,colors.red)
- if (not locked) and toLock then
- locked = true
- printAllLocked()
- elseif locked and (not toLock) then
- locked = false
- resetAllPass()
- clearMons(colors.black)
- drawPass("all")
- drawButtons("all")
- end
- end
- --print(event)
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement