View difference between Paste ID: WPUqMgQB and gW66gzt0
SHOW: | | - or go back to the newest paste.
1
local function bastion()
2
	local modem = peripheral.find("modem") or error("No modem attached", 0)
3
    modem.open(15) -- Open 43 so we can receive replies
4
5
    -- And wait for a reply
6
    local event, side, channel, replyChannel, message, distance
7
    repeat
8
      event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
9
    until channel == 15
10
11
    -- Process the received message based on its content
12
    if message == "Bridge" then
13-
        print("Toggling Bridge Gate")
13+
        os.sleep(1)
14-
        redstone.setOutput("left", true)  -- Emit a redstone signal to the right
14+
        if redstone.getInput("left") then
15-
        os.sleep(1)  -- Keep the signal for 1 seconds
15+
	        modem.transmit(43, 15, "Closing Bridge Gate")
16-
        redstone.setOutput("left", false)  -- Turn off the redstone signal
16+
        else
17
	        modem.transmit(43, 15, "Opening Bridge Gate")
18
        end
19-
        print("Toggling Courtyard Gate")
19+
20-
        redstone.setOutput("right", true)  -- Emit a redstone signal to the right
20+
21-
        os.sleep(1)  -- Keep the signal for 1 seconds
21+
        os.sleep(1)
22-
        redstone.setOutput("right", false)  -- Turn off the redstone signal
22+
        if redstone.getInput("right") then
23
	        modem.transmit(43, 15, "Closing Courtyard Gate")
24-
    elseif message == "Remote Connected" then
24+
        else
25-
        modem.transmit(43, 15, "Connected to Bastion Network")
25+
	        modem.transmit(43, 15, "Opening Courtyard Gate")
26-
        print("Remote Connected")
26+
        end
27
28
    elseif message == "status" then
29-
        print("Toggling Lockdown")
29+
		courtyard = ""
30-
        redstone.setOutput("front", true)  -- Emit a redstone signal to the right
30+
		bridge = ""
31-
        os.sleep(1)  -- Keep the signal for 1 seconds
31+
		lockdown = ""
32-
        redstone.setOutput("front", false)  -- Turn off the redstone signal
32+
        if redstone.getInput("right") then
33
			courtyard = "Courtyard Gate Closed, "
34
        else
35
	        courtyard = "Courtyard Gate Open, "
36
        end
37
        if redstone.getInput("left") then
38
	        bridge = "Bridge Gate Closed, "
39-
print("Bastion Network Online!")
39+
        else
40
	        bridge = "Bridge Gate Open, "
41
        end
42
        if redstone.getInput("back") then
43
	        lockdown = "Lockdown Enabled"
44-
end
44+
        else
45
	        lockdown = "Lockdown Disabled"
46
        end
47
	    modem.transmit(43, 15, courtyard .. bridge .. lockdown)
48
49
50
    elseif message == "Lockdown" then
51
        os.sleep(1)
52
        if redstone.getInput("back") then
53
	        modem.transmit(43, 15, "Enabeling Lockdown")
54
        else
55
	        modem.transmit(43, 15, "Disabeling Lockdown")
56
        end
57
    end
58
end
59
60
term.clear()
61
term.setCursorPos(1, 1)
62
print("Bastion Online!")
63
64
-- Main loop
65
while true do
66
    bastion()
67
end
68