Advertisement
Svizel_pritula

[ComputerCraft] Door password program

Feb 26th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.15 KB | None | 0 0
  1. local file="print(\"Booting Svizel pritula's door password program...\")\nsleep(0.1)\n\nlocal h = fs.open(\"properties\", \"r\")\nlocal password=h.readLine()\nlocal wm=h.readLine()\nlocal wo=h.readLine()\nlocal s=h.readLine()\nlocal goodT=h.readLine()*1\nlocal wrongT=h.readLine()*1\nlocal resetT=h.readLine()*1\nlocal invert=h.readLine()==\"true\"\nlocal wrong=h.readLine()\nlocal hide=h.readLine()==\"true\"\n\nh.close()\nlocal monitor = peripheral.wrap(wm)\nlocal event = \"event\"\nlocal side = \"side\"\nlocal x = 0\nlocal y = 0\nlocal key = 0\nlocal code = \"\"\nlocal passOkTimer = \"nothing\"\nlocal passWrongTimer = \"nothing\"\nlocal passTermTimer = \"nothing\"\nlocal passResetTimer = \"nothing\"\nlocal passQuessState=0\nlocal editing = 0\nlocal editingType = 0\nlocal editingValue = \"\"\nlocal editingMaxLenght = 2\nrs.setOutput(s,invert)\n\nfunction saveValue(value, spot)\nlocal save = fs.open(\"properties\", \"w\")\n\nif editing==1 then\nsave.writeLine(value)\nelse\nsave.writeLine(password)\nend\nif editing==3 then\nsave.writeLine(value)\nelse\nsave.writeLine(wm)\nend\nif editing==4 then\nsave.writeLine(value)\nelse\nsave.writeLine(wo)\nend\nif editing==5 then\nsave.writeLine(value)\nelse\nsave.writeLine(s)\nend\nif editing==6 then\nsave.writeLine(value)\nelse\nsave.writeLine(goodT)\nend\nif editing==7 then\nsave.writeLine(value)\nelse\nsave.writeLine(wrongT)\nend\nif editing==8 then\nsave.writeLine(value)\nelse\nsave.writeLine(resetT)\nend\nif editing==2 then\nsave.writeLine(value)\nelse\nsave.writeLine(invert)\nend\nif editing==9 then\nsave.writeLine(value)\nelse\nsave.writeLine(wrong)\nend\nif editing==10 then\nsave.writeLine(value)\nelse\nsave.writeLine(hide)\nend\n\nsave.close()\nos.reboot()\nend\n\nfunction draw()\nmonitor.setBackgroundColor(colors.black)\nmonitor.clear()\nif editingType<4 then\nmonitor.setBackgroundColor(colors.black)\nmonitor.clear()\nmonitor.setTextScale(1)\nmonitor.setBackgroundColor(colors.yellow)\nmonitor.setCursorPos(3,2)\nmonitor.write(\"123\")\nmonitor.setCursorPos(3,3)\nmonitor.write(\"456\")\nmonitor.setCursorPos(3,4)\nmonitor.write(\"789\")\nmonitor.setCursorPos(3,5)\nmonitor.write(\"0\")\nmonitor.setBackgroundColor(colors.red)\nmonitor.setCursorPos(4,5)\nmonitor.write(\"<\")\nmonitor.setBackgroundColor(colors.green)\nmonitor.setCursorPos(5,5)\nmonitor.write(\" \")\n\nif passQuessState==0 then\nmonitor.setBackgroundColor(colors.gray)\nelseif passQuessState==1 then\nmonitor.setBackgroundColor(colors.green)\nelseif passQuessState==2 then\nmonitor.setBackgroundColor(colors.red)\nelseif passQuessState==3 then\nmonitor.setBackgroundColor(colors.blue)\nend\n\nmonitor.setCursorPos(2,1)\nmonitor.write(\"     \")\nmonitor.setCursorPos(2,1)\nif hide then\nmonitor.write(string.rep(\"*\",string.len(code)))\nelse\nmonitor.write(code)\nend\nend\n\nterm.setBackgroundColor(colors.yellow)\nterm.clear()\n\nterm.setBackgroundColor(colors.orange)\nterm.setCursorPos(2,2)\nterm.setTextColor(colors.black)\nterm.write(\"Svizel pritula's door password program\")\n\nif editingType==0 then\n\nterm.setBackgroundColor(colors.yellow)\nterm.setCursorPos(2,4)\nterm.write(\"Actualy entered code: \")\nterm.setTextColor(colors.gray)\nif string.len(code)==0 then\nterm.write(\"none\")\nelse\nterm.write(code)\nend\n\nterm.setTextColor(colors.black)\nterm.setCursorPos(30,4)\nterm.write(\"Password: \")\nterm.setTextColor(colors.gray)\nif string.len(password)==0 then\nterm.write(\"none\")\nelse\nterm.write(password)\nend\nterm.setCursorPos(46,4)\nterm.setBackgroundColor(colors.green)\nterm.setTextColor(colors.black)\nterm.write(\"edit\")\n\nterm.setBackgroundColor(colors.yellow)\nterm.setTextColor(colors.black)\nterm.setCursorPos(2,6)\nterm.write(\"Output: \")\nterm.setTextColor(colors.gray)\nif rs.getOutput(s) then\nterm.write(\"Yes\")\nelse\nterm.write(\"No\")\nend\n\n\nterm.setTextColor(colors.black)\nterm.setCursorPos(14,6)\nterm.write(\"Inverted: \")\nterm.setTextColor(colors.gray)\nif invert then\nterm.write(\"Yes\")\nelse\nterm.write(\"No\")\nend\nterm.setCursorPos(28,6)\nterm.setBackgroundColor(colors.green)\nterm.setTextColor(colors.black)\nterm.write(\"edit\")\n\n\nterm.setBackgroundColor(colors.yellow)\nterm.setTextColor(colors.black)\nterm.setCursorPos(2,8)\nterm.write(\"Monitor: \")\nterm.setTextColor(colors.gray)\nterm.write(wm)\nterm.setCursorPos(22,8)\nterm.setBackgroundColor(colors.green)\nterm.setTextColor(colors.black)\nterm.write(\"edit\")\n\nterm.setBackgroundColor(colors.yellow)\nterm.setTextColor(colors.black)\nterm.setCursorPos(27,8)\nterm.write(\"Activation: \")\nterm.setTextColor(colors.gray)\nterm.write(wo)\nterm.setCursorPos(46,8)\nterm.setBackgroundColor(colors.green)\nterm.setTextColor(colors.black)\nterm.write(\"edit\")\n\nterm.setBackgroundColor(colors.yellow)\nterm.setTextColor(colors.black)\nterm.setCursorPos(2,10)\nterm.write(\"Door: \")\nterm.setTextColor(colors.gray)\nterm.write(s)\nterm.setCursorPos(15,10)\nterm.setBackgroundColor(colors.green)\nterm.setTextColor(colors.black)\nterm.write(\"edit\")\n\nterm.setBackgroundColor(colors.yellow)\nterm.setTextColor(colors.black)\nterm.setCursorPos(20,10)\nterm.write(\"Door open time: \")\nterm.setTextColor(colors.gray)\nterm.write(goodT)\nterm.setCursorPos(39,10)\nterm.setBackgroundColor(colors.green)\nterm.setTextColor(colors.black)\nterm.write(\"edit\")\n\nterm.setBackgroundColor(colors.yellow)\nterm.setTextColor(colors.black)\nterm.setCursorPos(2,12)\nterm.write(\"Wrong password wait time: \")\nterm.setTextColor(colors.gray)\nterm.write(wrongT)\nterm.setCursorPos(31,12)\nterm.setBackgroundColor(colors.green)\nterm.setTextColor(colors.black)\nterm.write(\"edit\")\n\nterm.setBackgroundColor(colors.yellow)\nterm.setTextColor(colors.black)\nterm.setCursorPos(2,14)\nterm.write(\"Password reset time: \")\nterm.setTextColor(colors.gray)\nterm.write(resetT)\nterm.setCursorPos(26,14)\nterm.setBackgroundColor(colors.green)\nterm.setTextColor(colors.black)\nterm.write(\"edit\")\n\nterm.setBackgroundColor(colors.yellow)\nterm.setTextColor(colors.black)\nterm.setCursorPos(31,14)\nterm.write(\"Hide pass: \")\nterm.setTextColor(colors.gray)\nif hide then\nterm.write(\"Yes\")\nelse\nterm.write(\"No\")\nend\nterm.setCursorPos(46,14)\nterm.setBackgroundColor(colors.green)\nterm.setTextColor(colors.black)\nterm.write(\"edit\")\n\nterm.setBackgroundColor(colors.yellow)\nterm.setTextColor(colors.black)\nterm.setCursorPos(2,16)\nterm.write(\"Wrong password output: \")\nterm.setTextColor(colors.gray)\nterm.write(wrong)\nterm.setCursorPos(32,16)\nterm.setBackgroundColor(colors.green)\nterm.setTextColor(colors.black)\nterm.write(\"edit\")\n\nterm.setBackgroundColor(colors.yellow)\nterm.setCursorPos(2,18)\nif passQuessState==0 then\nterm.setTextColor(colors.black)\nterm.write(\"Waiting for password\")\nelseif passQuessState==1 then\nterm.setTextColor(colors.green)\nterm.write(\"Right password!\")\nelseif passQuessState==2 then\nterm.setTextColor(colors.red)\nterm.write(\"Wrong password!\")\nelseif passQuessState==3 then\nterm.setTextColor(colors.blue)\nterm.write(\"Opening redstone activated!\")\nend\n\nelseif editingType==1 then\n\nterm.setBackgroundColor(colors.yellow)\nterm.setCursorPos(2,4)\nterm.write(\"Enter value: \")\nterm.setTextColor(colors.gray)\nif string.len(editingValue)==0 then\nterm.write(\"none\")\nelse\nterm.write(editingValue)\nend\nelseif editingType==2 then\n\nterm.setBackgroundColor(colors.yellow)\nterm.setCursorPos(2,4)\nterm.write(\"Click on the right option: \")\nterm.setTextColor(colors.gray)\nterm.setCursorPos(2,6)\nterm.write(\"Yes\")\nterm.setCursorPos(2,7)\nterm.write(\"No\")\n\nelseif editingType==3 then\n\nterm.setBackgroundColor(colors.yellow)\nterm.setCursorPos(2,4)\nterm.write(\"Click on the right option: \")\nterm.setTextColor(colors.gray)\nterm.setCursorPos(2,6)\nterm.write(\"Left\")\nterm.setCursorPos(2,7)\nterm.write(\"Right\")\nterm.setCursorPos(2,8)\nterm.write(\"Top\")\nterm.setCursorPos(2,9)\nterm.write(\"Bottom\")\nterm.setCursorPos(2,10)\nterm.write(\"Front\")\nterm.setCursorPos(2,11)\nterm.write(\"Back\")\nif editingMaxLenght==1 then\nterm.setCursorPos(2,12)\nterm.write(\"None\")\nend\n\nelseif editingType==4 then\n\nterm.setBackgroundColor(colors.yellow)\nterm.setCursorPos(2,4)\nterm.write(\"Click on the monitor you want to use\")\n\nend\n\nend\n\nwhile true do\ndraw()\nevent, side, x, y = os.pullEvent()\n\nif event==\"redstone\" then\nif not (wo==\"none\") then\nif rs.getInput(wo)==true then\nrs.setOutput(s,not invert)\npassTermTimer = os.startTimer(goodT)\npassQuessState=3\nend\nend\nend\n\nif event==\"timer\" then\nif side==passOkTimer then\ncode=\"\"\npassQuessState=0\nrs.setOutput(s,invert)\nend\nif side==passWrongTimer then\ncode=\"\"\npassQuessState=0\nrs.setOutput(wrong,false)\nend\nif side==passTermTimer then\ncode=\"\"\npassQuessState=0\nrs.setOutput(s,invert)\nend\nif side==passResetTimer and passQuessState==0 then\ncode=\"\"\nend\nend\n\nif event==\"mouse_click\" then\nif editingType==0 then\nif (y==4 and x>45 and x<50) then\nediting = 1\neditingType = 1\neditingMaxLenght = 5\neditingValue = password\nelseif (y==6 and x>27 and x<32) then\nediting = 2\neditingType = 2\nelseif (y==8 and x>21 and x<26) then\nediting = 3\neditingType = 4\nelseif (y==8 and x>45 and x<50) then\nediting = 4\neditingType = 3\neditingMaxLenght=1\nelseif (y==10 and x>14 and x<19) then\nediting = 5\neditingType = 3\neditingMaxLenght=0\nelseif (y==10 and x>38 and x<43) then\nediting = 6\neditingType = 1\neditingMaxLenght = 2\neditingValue = goodT\nelseif (y==12 and x>30 and x<35) then\nediting = 7\neditingType = 1\neditingMaxLenght = 3\neditingValue = wrongT\nelseif (y==14 and x>25 and x<30) then\nediting = 8\neditingType = 1\neditingMaxLenght = 3\neditingValue = resetT\nelseif (y==16 and x>31 and x<36) then\nediting = 9\neditingType = 3\neditingMaxLenght = 1\nelseif (y==14 and x>45 and x<50) then\nediting = 10\neditingType = 2\nend\n\nelseif editingType==2 and (y>5 and y<8) then\nsaveValue(y==6, editing)\n\nelseif editingType==3 and (y>5 and (y<12 or (y<13 and editingMaxLenght==1))) then\nif y==6 then\nsaveValue(\"left\", editing)\nelseif y==7 then\nsaveValue(\"right\", editing)\nelseif y==8 then\nsaveValue(\"top\", editing)\nelseif y==9 then\nsaveValue(\"bottom\", editing)\nelseif y==10 then\nsaveValue(\"front\", editing)\nelseif y==11 then\nsaveValue(\"back\", editing)\nelseif y==12 then\nsaveValue(\"none\", editing)\nend\n\nend\nend\n\nif event==\"key\" then\nif editingType==1 then\nif (side>1 and side<11 and string.len(editingValue)<editingMaxLenght) then\neditingValue=editingValue..side-1\nelseif (side==11 and string.len(editingValue)<editingMaxLenght) then\neditingValue=editingValue..0\nelseif side==14 then\neditingValue=string.sub(editingValue, 0, string.len(editingValue)-1)\nelseif side==28 and (string.len(editingValue)>0 and not (editingValue*1==0)) then\nsaveValue(editingValue, editing)\nend\nend\nend\n\nif event==\"monitor_touch\" then\nif editingType<4 then\nif side==wm then\npassResetTimer=os.startTimer(resetT)\nend\nif (x<6 and x>2 and y<6 and y>1 and side==wm and passQuessState==0) then\nkey = (x-2)+(y-2)*3\nif string.len(code)<5 then\nif key<10 then\ncode = code..key\nend\nif key==10 then\ncode = code..0\nend\nend\nif key==11 then\ncode=string.sub(code, 0, string.len(code)-1)\nend\nif key==12 then\nif code==password then\nrs.setOutput(s,not invert)\npassOkTimer = os.startTimer(goodT)\npassQuessState=1\nelse\nrs.setOutput(wrong,true)\npassWrongTimer = os.startTimer(wrongT)\npassQuessState=2\nend\nend\nend\nelse\nsaveValue(side, editing)\nend\nend\n\nend"
  2.  
  3. local startup = fs.open("startup", "w")
  4. local prop = fs.open("properties", "w")
  5. local run=true
  6. local value=""
  7. local event=""
  8. local x=0
  9. local y=0
  10.  
  11. function direction(a,b,c,e,d)
  12. run=true
  13. while run do
  14. logo()
  15. term.setCursorPos(2,4)
  16. term.write(a)
  17. term.setTextColor(colors.gray)
  18. term.setCursorPos(2,6)
  19. term.write("Left")
  20. term.setCursorPos(2,7)
  21. term.write("Right")
  22. term.setCursorPos(2,8)
  23. term.write("Top")
  24. term.setCursorPos(2,9)
  25. term.write("Bottom")
  26. term.setCursorPos(2,10)
  27. term.write("Front")
  28. term.setCursorPos(2,11)
  29. term.write("Back")
  30. if d then
  31. term.setCursorPos(2,12)
  32. term.write("None")
  33. end
  34. term.setTextColor(colors.black)
  35. term.setCursorPos(2,14)
  36. term.write(b)
  37. term.setCursorPos(2,15)
  38. term.write(c)
  39. term.setCursorPos(2,16)
  40. term.write(e)
  41.  
  42. event, value, x, y=os.pullEvent("mouse_click")
  43. if value==1 and (y>5 and ((y<13 and d)or(y<12 and not d))) then
  44. run=false
  45. if y==6 then
  46. prop.writeLine("left")
  47. elseif y==7 then
  48. prop.writeLine("right")
  49. elseif y==8 then
  50. prop.writeLine("top")
  51. elseif y==9 then
  52. prop.writeLine("bottom")
  53. elseif y==10 then
  54. prop.writeLine("front")
  55. elseif y==11 then
  56. prop.writeLine("back")
  57. elseif y==12 then
  58. prop.writeLine("none")
  59. end
  60. end
  61. end
  62.  
  63. end
  64.  
  65. function number(a,b,c,d,e)
  66. value=d
  67. run=true
  68. while run do
  69. logo()
  70. term.setCursorPos(2,4)
  71. term.write(a)
  72. term.setTextColor(colors.gray)
  73. term.write(value)
  74. term.setTextColor(colors.black)
  75. term.setCursorPos(2,5)
  76. term.write(b)
  77. term.setCursorPos(2,6)
  78. term.write(e)
  79. event,key=os.pullEvent("key")
  80. if string.len(value)<c then
  81. if key>1 and key<11 then
  82. value=value..key-1
  83. end
  84. if key==11 then
  85. value=value..0
  86. end
  87. end
  88. if key==14 then
  89. value=string.sub(value, 0, string.len(value)-1)
  90. end
  91. if key==28 and (string.len(value)>0 and not (value*1==0)) then
  92. prop.writeLine(value)
  93. run=false
  94. end
  95. end
  96.  
  97. end
  98.  
  99. function logo()
  100. term.setBackgroundColor(colors.yellow)
  101. term.setTextColor(colors.black)
  102. term.clear()
  103. term.setCursorPos(2,2)
  104. term.setBackgroundColor(colors.orange)
  105. term.write("Svizel pritula's door password program")
  106. term.setBackgroundColor(colors.yellow)
  107. end
  108.  
  109. logo()
  110. term.setCursorPos(2,4)
  111. term.write("Welcome to Svizel pritula's door password program!")
  112. term.setCursorPos(2,5)
  113. term.write("This is an instalation wizard.")
  114. term.setCursorPos(2,6)
  115. term.write("All the values entered can be changed later.")
  116. term.setCursorPos(2,8)
  117. term.write("Click to continue")
  118. os.pullEvent("mouse_click")
  119.  
  120. number("Enter your password: ","Your password can have 1-5 digits",5,"","")
  121.  
  122. logo()
  123. term.setCursorPos(2,4)
  124. term.write("Click on the monitor you want to use")
  125. event, value=os.pullEvent("monitor_touch")
  126. prop.writeLine(value)
  127.  
  128. direction("Activation redstone: (Click) ","When you send a redstone signal to this side,","the door will open","",true)
  129.  
  130. direction("Door output: ","When you enter the right password, you will","get a redstone signal on this side","Connect this to your door",false)
  131.  
  132. number("Enter output lenght: ","When you enter the good password",2,"5","the output will be on for this many seconds")
  133.  
  134. number("Enter block time: ","When you enter the wrong password",3,"20","the keypad will be locked for this many seconds")
  135.  
  136. number("Enter password reset time: ","The entered password will be deleted when you",3,"10","don't touch the screen for this many seconds")
  137.  
  138. run=true
  139. while run do
  140. logo()
  141. term.setCursorPos(2,4)
  142. term.write("Output inverted:")
  143. term.setTextColor(colors.gray)
  144. term.setCursorPos(2,6)
  145. term.write("Yes")
  146. term.setCursorPos(2,7)
  147. term.write("No")
  148. term.setTextColor(colors.black)
  149. term.setCursorPos(2,9)
  150. term.write("This will make the redstone to be on by default,")
  151. term.setCursorPos(2,10)
  152. term.write("and turn off when you enter the correct password")
  153.  
  154. event, value, x, y=os.pullEvent("mouse_click")
  155. if value==1 and (y>5 and y<8) then
  156. run=false
  157. prop.writeLine(y==6)
  158. end
  159. end
  160.  
  161. direction("Wrong password output: ","If you enter a wrong password, you will","get a redstone signal on this side","",true)
  162.  
  163. run=true
  164. while run do
  165. logo()
  166. term.setCursorPos(2,4)
  167. term.write("Hide password:")
  168. term.setTextColor(colors.gray)
  169. term.setCursorPos(2,6)
  170. term.write("Yes")
  171. term.setCursorPos(2,7)
  172. term.write("No")
  173. term.setTextColor(colors.black)
  174. term.setCursorPos(2,9)
  175. term.write("If you put this on, you won't see the password on")
  176. term.setCursorPos(2,10)
  177. term.write("the monitor")
  178.  
  179. event, value, x, y=os.pullEvent("mouse_click")
  180. if value==1 and (y>5 and y<8) then
  181. run=false
  182. prop.writeLine(y==6)
  183. end
  184. end
  185.  
  186. prop.close()
  187. startup.write(file)
  188. startup.close()
  189.  
  190. logo()
  191. term.setCursorPos(2,4)
  192. term.write("The instalation is complete!")
  193. term.setCursorPos(2,5)
  194. term.write("Make sure no one can get to this computer")
  195. term.setCursorPos(2,6)
  196. term.write("The program will be started when you")
  197. term.setCursorPos(2,7)
  198. term.write("reboot this computer")
  199. term.setCursorPos(2,9)
  200. term.write("Click to reboot")
  201. os.pullEvent("mouse_click")
  202.  
  203. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement