Advertisement
Vladimir_Pruskalyow

Lock.lua

Mar 23rd, 2016
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local note = require("note")
  4.  
  5. local info = {password = 1234, adminPass = 228228, redstone = false, RedCorr = 3, RedIncor = 2, network = false, port = 512, sound = false}
  6.  
  7. --Редстоун-сигналы
  8. function redTick(red, side)
  9.     if red then
  10.         if component.isAvailable("redstone") then
  11.             component.redstone.setOutput(tonumber(side), 255)
  12.             os.sleep(0.1)
  13.             component.redstone.setOutput(tonumber(side), 0)
  14.         else
  15.             io.write("\nПлата на красном камне отсутствует. Данный тип сигнала невозможен!")
  16.         end
  17.     end
  18. end
  19. --Беспроводные сигналы
  20. function netSignal(network, port, typeS)
  21.     if network then
  22.         if component.isAvailable("modem") then
  23.             if component.modem.isWireless() then
  24.                 if typeS == 1 then
  25.                     component.modem.broadcast(tonumber(port), "LockSignal", "True_Pass")
  26.                 elseif typeS == 2 then
  27.                     component.modem.broadcast(tonumber(port), "LockSignal", "Bad_Pass")
  28.                 else
  29.                     component.modem.broadcast(tonumber(port), "LockSignal", "Error")
  30.                 end
  31.             else
  32.                 io.write("\nСетевая карта неспособна подовать беспроводные сообщения. Данный тип сигнала невозможен!")
  33.             end
  34.         else
  35.             io.write("\nСетевая карта отсутствует. Данный тип сигнала невозможен!")
  36.         end
  37.     end
  38. end
  39. --Создание конфига
  40. local cfg = io.open("etc/Lock.cfg", "r")
  41. if cfg == nil then
  42.     local CFG = io.open("etc/Lock.cfg", "w")
  43.     CFG:write("password=1234\nadminPass=228228\nsound=true\nredstone=true\nRedCorr=3\nRedIncor=2\nnetwork=false\nport=512\nCreated by Pofigist\nVk: http://vk.com/pofigist_vip")
  44.     CFG:close()
  45.     cfg = io.open("etc/Lock.cfg", "r")
  46. end
  47. --Загрузка из конфига
  48. local buff = cfg:read("*a")
  49. info.password = string.match(buff, "password=".."(%d+)")
  50. info.adminPass = string.match(buff, "adminPass=".."(%d+)")
  51. if string.match(buff, "redstone=".."(%a+)") == "true" then info.redstone = true end
  52. info.RedCorr = string.match(buff, "RedCorr=".."(%d+)")
  53. info.RedIncor = string.match(buff, "RedIncor=".."(%d+)")
  54. if string.match(buff, "network=".."(%a+)") == "true" then info.network = true end
  55. info.port = string.match(buff, "port=".."(%d+)")
  56. if string.match(buff, "sound=".."(%a+)") == "true" then info.sound = true end
  57. --Основной цикл
  58. while true do
  59.     term.clear()
  60.     io.write("Введите пароль: ")
  61.     local err, text = pcall(io.read)
  62.     if text == info.password then
  63.         if info.sound then note.play(90, 0.15) end
  64.         io.write("Успешно разблокировано!")
  65.         redTick(info.redstone, info.RedCorr)
  66.         netSignal(info.network, info.port, 1)
  67.         break
  68.     elseif text == info.adminPass then
  69.         io.write("Приветствуем Администрацию.")
  70.         break
  71.     else
  72.         io.write("Неверный пароль! Повторите попытку. \n")
  73.         if info.sound then note.play(68, 1) end
  74.         redTick(info.redstone, info.RedIncor)
  75.         netSignal(info.network, info.port, 2)
  76.     end
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement