Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- settings.load()
- local outside_door_side = settings.get("gate.outside_door")
- local inside_door_side = settings.get("gate.inside_door")
- local sirene_side = settings.get("gate.sirene")
- local outside_monitor_name = settings.get("gate.outside_monitor")
- local inside_monitor_name = settings.get("gate.inside_monitor")
- local gate_monitor_name = settings.get("gate.gate_monitor")
- local player_detector_name = settings.get("gate.player_detector")
- local outside_scan_coordinates = settings.get("gate.outside_scan_coordinates")
- local inside_scan_coordinates = settings.get("gate.inside_scan_coordinates")
- local gate_scan_coordinates = settings.get("gate.gate_scan_coordinates")
- local gate_switch_coordinates = settings.get("gate.gate_switch_coordinates")
- local authorized_players = settings.get("gate.authorized_players")
- local outside_monitor = peripheral.wrap(outside_monitor_name)
- local inside_monitor = peripheral.wrap(inside_monitor_name)
- local gate_monitor = peripheral.wrap(gate_monitor_name)
- local player_detector = peripheral.wrap(player_detector_name)
- -- states: empty, unauth_outside, unauth_gate, multiple_gate, enter_outside_open, enter_inside_open, leave_inside_open, leave_outside_open
- local state = "empty"
- local function players_authorized(players, authorized_players)
- for _, k in pairs(players) do
- for _, v in pairs(authorized_players) do
- if k == v then
- return true
- end
- end
- end
- return false
- end
- -- region state switch
- local function toState_empty()
- inside_monitor.clear()
- inside_monitor.setCursorPos(2, 3)
- inside_monitor.write(" Schleuse ")
- inside_monitor.setCursorPos(2, 4)
- inside_monitor.write(" bereit ")
- outside_monitor.clear()
- outside_monitor.setCursorPos(2, 3)
- outside_monitor.write(" Schleuse ")
- outside_monitor.setCursorPos(2, 4)
- outside_monitor.write(" bereit ")
- gate_monitor.clear()
- rs.setOutput(sirene_side, false)
- rs.setOutput(outside_door_side, false)
- rs.setOutput(inside_door_side, false)
- state = "empty"
- end
- local function toState_unauthOutside()
- outside_monitor.clear()
- outside_monitor.setCursorPos(1, 2)
- outside_monitor.write("Zutritt verweigert")
- outside_monitor.setCursorPos(1, 4)
- outside_monitor.write("Nicht authorisiert")
- state = "unauth_outside"
- end
- local function toState_unauthGate()
- outside_monitor.clear()
- outside_monitor.setCursorPos(2, 3)
- outside_monitor.write("x Schleuse x")
- outside_monitor.setCursorPos(2, 4)
- outside_monitor.write("x verlassen x")
- gate_monitor.clear()
- gate_monitor.setCursorPos(1, 2)
- gate_monitor.write("Zutritt verweigert")
- gate_monitor.setCursorPos(1, 4)
- gate_monitor.write("Schleuse verlassen")
- rs.setOutput(sirene_side, true)
- rs.setOutput(outside_door_side, true)
- state = "unauth_gate"
- end
- local function toState_multipleGate()
- outside_monitor.clear()
- outside_monitor.setCursorPos(2, 3)
- outside_monitor.write("x Schleuse x")
- outside_monitor.setCursorPos(2, 4)
- outside_monitor.write("x verlassen x")
- gate_monitor.clear()
- gate_monitor.setCursorPos(1, 2)
- gate_monitor.write("Nur eine Person")
- gate_monitor.setCursorPos(1, 3)
- gate_monitor.write("in der Schleuse")
- gate_monitor.setCursorPos(1, 4)
- gate_monitor.write("erlaubt")
- rs.setOutput(sirene_side, true)
- rs.setOutput(outside_door_side, true)
- state = "multiple_gate"
- end
- local function toState_enterOutsideOpen()
- outside_monitor.clear()
- outside_monitor.setCursorPos(2, 2)
- outside_monitor.write("^ ^")
- outside_monitor.setCursorPos(2, 3)
- outside_monitor.write("| Bitte |")
- outside_monitor.setCursorPos(2, 4)
- outside_monitor.write("| eintreten |")
- inside_monitor.clear()
- inside_monitor.setCursorPos(2, 3)
- inside_monitor.write("x Schleuse x")
- inside_monitor.setCursorPos(2, 4)
- inside_monitor.write("x belegt x")
- gate_monitor.clear()
- gate_monitor.setCursorPos(1, 2)
- gate_monitor.write("Auf markierten")
- gate_monitor.setCursorPos(1, 3)
- gate_monitor.write("Bereich stellen")
- rs.setOutput(outside_door_side, true)
- rs.setOutput(inside_door_side, false)
- rs.setOutput(sirene_side, false)
- state = "enter_outside_open"
- end
- local function toState_leaveInsideOpen()
- inside_monitor.clear()
- inside_monitor.setCursorPos(2, 2)
- inside_monitor.write("^ ^")
- inside_monitor.setCursorPos(2, 3)
- inside_monitor.write("| Bitte |")
- inside_monitor.setCursorPos(2, 4)
- inside_monitor.write("| eintreten |")
- outside_monitor.clear()
- outside_monitor.setCursorPos(2, 3)
- outside_monitor.write("x Schleuse x")
- outside_monitor.setCursorPos(2, 4)
- outside_monitor.write("x belegt x")
- gate_monitor.clear()
- gate_monitor.setCursorPos(1, 2)
- gate_monitor.write("Auf markierten")
- gate_monitor.setCursorPos(1, 3)
- gate_monitor.write("Bereich stellen")
- rs.setOutput(inside_door_side, true)
- rs.setOutput(outside_door_side, false)
- state = "leave_inside_open"
- end
- local function toState_enterInsideOpen()
- outside_monitor.clear()
- outside_monitor.setCursorPos(2, 3)
- outside_monitor.write("x Schleuse x")
- outside_monitor.setCursorPos(2, 4)
- outside_monitor.write("x belegt x")
- sleep(1)
- gate_monitor.clear()
- gate_monitor.setCursorPos(1, 3)
- gate_monitor.write("Schleuse verlassen")
- rs.setOutput(inside_door_side, true)
- state = "enter_inside_open"
- end
- local function toState_leaveOutsideOpen()
- inside_monitor.clear()
- inside_monitor.setCursorPos(2, 3)
- inside_monitor.write("x Schleuse x")
- inside_monitor.setCursorPos(2, 4)
- inside_monitor.write("x belegt x")
- sleep(1)
- gate_monitor.clear()
- gate_monitor.setCursorPos(1, 3)
- gate_monitor.write("Schleuse verlassen")
- rs.setOutput(outside_door_side, true)
- state = "leave_outside_open"
- end
- -- endregion
- -- region states
- local function emptyState()
- if player_detector.isPlayersInCoords(outside_scan_coordinates.posOne, outside_scan_coordinates.posTwo) then
- local players = player_detector.getPlayersInCoords(outside_scan_coordinates.posOne, outside_scan_coordinates.posTwo)
- if not players_authorized(players, authorized_players) then
- toState_unauthOutside()
- else
- toState_enterOutsideOpen()
- end
- elseif player_detector.isPlayersInCoords(inside_scan_coordinates.posOne, inside_scan_coordinates.posTwo) then
- toState_leaveInsideOpen()
- end
- end
- local function unauthOutsideState()
- if player_detector.isPlayersInCoords(inside_scan_coordinates.posOne, inside_scan_coordinates.posTwo) then
- toState_leaveInsideOpen()
- elseif player_detector.isPlayersInCoords(outside_scan_coordinates.posOne, outside_scan_coordinates.posTwo) then
- local players = player_detector.getPlayersInCoords(outside_scan_coordinates.posOne, outside_scan_coordinates.posTwo)
- if players_authorized(players, authorized_players) then
- toState_enterOutsideOpen()
- end
- else
- toState_empty()
- end
- end
- local function unauthGateState()
- if not player_detector.isPlayersInCoords(gate_scan_coordinates.posOne, gate_scan_coordinates.posTwo) then
- toState_empty()
- end
- end
- local function multipleGateState()
- if not player_detector.isPlayersInCoords(gate_scan_coordinates.posOne, gate_scan_coordinates.posTwo) then
- toState_enterOutsideOpen()
- end
- end
- local function enterOutsideOpenState()
- if player_detector.isPlayersInCoords(gate_switch_coordinates.posOne, gate_switch_coordinates.posTwo) then
- rs.setOutput(outside_door_side, false)
- local players = player_detector.getPlayersInCoords(gate_scan_coordinates.posOne, gate_scan_coordinates.posTwo)
- if #players > 1 then
- toState_multipleGate()
- elseif not players_authorized(players, authorized_players) then
- toState_unauthGate()
- else
- toState_enterInsideOpen()
- end
- elseif not (player_detector.isPlayersInCoords(outside_scan_coordinates.posOne, outside_scan_coordinates.posTwo) or player_detector.isPlayersInCoords(gate_scan_coordinates.posOne, gate_scan_coordinates.posTwo)) then
- toState_empty()
- end
- end
- local function enterInsideOpenState()
- if not player_detector.isPlayersInCoords(gate_scan_coordinates.posOne, gate_scan_coordinates.posTwo) then
- toState_leaveInsideOpen()
- end
- end
- local function leaveInsideOpenState()
- if player_detector.isPlayersInCoords(gate_switch_coordinates.posOne, gate_switch_coordinates.posTwo) then
- rs.setOutput(inside_door_side, false)
- toState_leaveOutsideOpen()
- elseif not (player_detector.isPlayersInCoords(inside_scan_coordinates.posOne, inside_scan_coordinates.posTwo) or player_detector.isPlayersInCoords(gate_scan_coordinates.posOne, gate_scan_coordinates.posTwo)) then
- toState_empty()
- end
- end
- local function leaveOutsideOpenState()
- if not player_detector.isPlayersInCoords(gate_scan_coordinates.posOne, gate_scan_coordinates.posTwo) then
- toState_enterOutsideOpen()
- end
- end
- -- endregion
- local function init()
- outside_monitor.clear()
- outside_monitor.setCursorPos(2, 3)
- outside_monitor.write("x Schleuse x")
- outside_monitor.setCursorPos(2, 4)
- outside_monitor.write("x nicht bereit x")
- toState_leaveOutsideOpen()
- end
- init()
- while true do
- if state == "empty" then
- emptyState()
- elseif state == "unauth_outside" then
- unauthOutsideState()
- elseif state == "unauth_gate" then
- unauthGateState()
- elseif state == "multiple_gate" then
- multipleGateState()
- elseif state == "enter_outside_open" then
- enterOutsideOpenState()
- elseif state == "leave_inside_open" then
- leaveInsideOpenState()
- elseif state == "enter_inside_open" then
- enterInsideOpenState()
- elseif state == "leave_outside_open" then
- leaveOutsideOpenState()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement