Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- if not fs.exists("arcui") or args[1] == "true" then
- print("Downloading arcUI...")
- shell.run("pastebin get NuZUGEmn arcui")
- end
- os.loadAPI("arcui")
- local twentyFourHour = true
- local side = nil
- local sideSecond = nil
- local doorOpenSeconds = 5
- local badPasswordSeconds = 2
- local rednetID = nil
- local rednetMsg = nil
- local rednetProtocol = nil
- local exitCode = nil
- local code = nil
- monX, monY = term.getSize()
- arcui.drawWindow("arcLock setup")
- arcui.drawSlider("twenty_slider", 2, 3, "Twenty-four Hour", true)
- arcui.drawTextbox("side_one_txtbox", 1, 5, monX / 2 - 2, "Redstone side", nil, nil, nil, rs.getSides())
- arcui.drawTextbox("side_two_txtbox", monX / 2 + 2, 5, monX, "Redstone side 2", nil, nil, nil, rs.getSides())
- arcui.drawLabel("sec_label", 2, 7, "Open time :")
- arcui.drawLabel("sec_bad_label", monX / 2 + 2, 7, "Bad password :")
- arcui.drawNumeric("seconds_numeric", 2, 8, monX / 2 - 2, 5, 1, math.huge)
- arcui.drawNumeric("seconds_bad_numeric", monX / 2 + 2, 8, monX - 1, 2, 1, math.huge)
- arcui.drawTextbox("open_code_txtbox", 1, 11, monX / 2 - 2, "Open code (4 number)")
- arcui.drawTextbox("exit_code_txtbox", monX / 2 + 2, 11, monX, "Exit code (4 number)")
- arcui.drawLabel("lbl_rednet", 2, 13, "Send a rednet message : (Optional)")
- arcui.drawTextbox("rednet_id_textbox", 1, 14, monX / 2 - 2, "Receiver ID")
- arcui.drawTextbox("rednet_msg_textbox", monX / 2 + 2, 14, monX, "Message")
- arcui.drawTextbox("rednet_protocol_textbox", 1, 16, monX, "Rednet Protocol (Optional)")
- arcui.drawButton("confirm_btn", 1, monY, monX, monY, colors.green, ">")
- function main()
- while true do
- event, a1, a2, a3 = os.pullEvent()
- if event == "button_close_clicked" then
- arcui.closeWindow()
- return true
- elseif event == "slider_state" then
- if a1 == "twenty_slider" then
- twentyFourHour = a2
- end
- elseif event == "numeric_value" then
- if a1 == "seconds_numeric" then
- doorOpenSeconds = a2
- elseif a1 == "seconds_bad_numeric" then
- badPasswordSeconds = a2
- end
- elseif event == "textbox_text" then
- if a1 == "side_one_txtbox" then
- local result = false
- for i = 1, #rs.getSides() do
- if a2 == rs.getSides()[i] then
- result = true
- end
- end
- if result == true then
- side = a2
- elseif a2 == "" then
- --Do nothing
- else
- arcui.openDialog("side_one_dialog", "Invalid side", "You entered an invalid side !")
- arcui.redrawWindow("arcLock setup")
- arcui.changeValue("side_one_txtbox", "value", "")
- end
- elseif a1 == "side_two_txtbox" then
- local result = false
- for i = 1, #rs.getSides() do
- if a2 == rs.getSides()[i] then
- result = true
- end
- end
- if result == true then
- sideSecond = a2
- elseif a2 == "" then
- --Do nothing
- else
- arcui.openDialog("side_two_dialog", "Invalid side", "You entered an invalid side !")
- arcui.redrawWindow("arcLock setup")
- arcui.changeValue("side_two_txtbox", "value", "")
- end
- elseif a1 == "open_code_txtbox" then
- if a2 == "" then
- --Do nothing
- elseif not tonumber(a2) then
- arcui.openDialog("open_code_dialog", "Invalid code", "Code must be a number !")
- arcui.redrawWindow("arcLock setup")
- arcui.changeValue("open_code_txtbox", "value", "")
- elseif #a2 ~= 4 then
- arcui.openDialog("open_code_dialog", "Invalid code", "Code must be 4 numbers !")
- arcui.redrawWindow("arcLock setup")
- arcui.changeValue("open_code_txtbox", "value", "")
- else
- code = tonumber(a2)
- end
- elseif a1 == "exit_code_txtbox" then
- if a2 == "" then
- --Do nothing
- elseif not tonumber(a2) then
- arcui.openDialog("exit_code_dialog", "Invalid code", "Code must be a number !")
- arcui.redrawWindow("arcLock setup")
- arcui.changeValue("exit_code_txtbox", "value", "")
- elseif #a2 ~= 4 then
- arcui.openDialog("exit_code_dialog", "Invalid code", "Code must be 4 numbers !")
- arcui.redrawWindow("arcLock setup")
- arcui.changeValue("exit_code_txtbox", "value", "")
- else
- exitCode = tonumber(a2)
- end
- elseif a1 == "rednet_id_textbox" then
- if tonumber(a2) then
- rednetID = a2
- else
- arcui.openDialog("exit_code_dialog", "Invalid ID", "ID must be a number !")
- arcui.redrawWindow("arcLock setup")
- arcui.changeValue("rednet_id_textbox", "value", "")
- end
- elseif a1 == "rednet_msg_textbox" then
- rednetMessage = a2
- elseif a1 == "rednet_protocol_textbox" then
- rednetProtocol = a2
- end
- elseif event == "button_clicked" then
- if a1 == "confirm_btn" then
- if not code then
- arcui.openDialog("confirm_dialog", "Something is missing...", "You have to enter a code !")
- arcui.redrawWindow("arcLock setup")
- elseif not exitCode then
- arcui.openDialog("confirm_dialog", "Something is missing...", "You have to enter an exit code !")
- arcui.redrawWindow("arcLock setup")
- else
- rep = arcui.openDialog("confirm_dialog", "Save changes", "Do you want to save changes ?")
- arcui.redrawWindow("arcLock setup")
- if rep == true then
- settings.set("arclock.twenty_four_hour", twentyFourHour)
- if side then
- settings.set("arclock.door_side", side)
- end
- if sideSecond then
- settings.set("arclock.door_side_second", sideSecond)
- end
- settings.set("arclock.door_open_seconds", doorOpenSeconds)
- settings.set("arclock.bad_password_seconds", badPasswordSeconds)
- settings.set("arclock.code", code)
- settings.set("arclock.exit_code", exitCode)
- if rednetID and rednetMessage then
- settings.set("arclock.rednet_id", tonumber(rednetID))
- settings.set("arclock.rednet_message", rednetMessage)
- end
- if rednetProtocol then
- settings.set("arclock.rednet_protocol", rednetProtocol)
- end
- settings.save(".settings")
- if not fs.exists("lock") then
- shell.run("pastebin get 5jQcugtT lock")
- rep = arcui.openDialog("confirm_dialog", "arcLock setup", "arcLock downloaded as lock.")
- arcui.redrawWindow("arcLock setup")
- end
- rep = arcui.openDialog("confirm_dialog", "arcLock setup", "Your computer will reboot...")
- os.reboot()
- end
- end
- end
- end
- end
- end
- parallel.waitForAll(main, arcui.eventHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement