SHOW:
|
|
- or go back to the newest paste.
1 | - | local function bastion() |
1 | + | local modem = peripheral.find("modem") or error("No modem attached", 0) |
2 | - | local modem = peripheral.find("modem") or error("No modem attached", 0) |
2 | + | CHANNEL = 15 |
3 | - | modem.open(15) -- Open 43 so we can receive replies |
3 | + | modem.open(CHANNEL) |
4 | ||
5 | - | -- And wait for a reply |
5 | + | local function receiveMessage() |
6 | - | local event, side, channel, replyChannel, message, distance |
6 | + | local event, _, channel, _, message = os.pullEvent("modem_message") |
7 | - | repeat |
7 | + | if channel == CHANNEL then |
8 | - | event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message") |
8 | + | return message |
9 | - | until channel == 15 |
9 | + | else |
10 | return receiveMessage() | |
11 | - | -- Process the received message based on its content |
11 | + | |
12 | - | if message == "Bridge" then |
12 | + | |
13 | - | os.sleep(1) |
13 | + | |
14 | - | if redstone.getInput("left") then |
14 | + | |
15 | - | modem.transmit(43, 15, "Closing Bridge Gate") |
15 | + | |
16 | - | else |
16 | + | print("Bastion Network Online!") |
17 | - | modem.transmit(43, 15, "Opening Bridge Gate") |
17 | + | |
18 | - | end |
18 | + | local message = receiveMessage() |
19 | ||
20 | - | elseif message == "Courtyard" then |
20 | + | -- Function to summon particles at a given position |
21 | - | os.sleep(1) |
21 | + | local function summonParticles(x, y, z) |
22 | - | if redstone.getInput("right") then |
22 | + | for _ = 1, 10 do |
23 | - | modem.transmit(43, 15, "Closing Courtyard Gate") |
23 | + | commands.exec("particle minecraft:portal " .. x .. " " .. y .. " " .. z .. " 1 1 1 0.1 50") |
24 | - | else |
24 | + | sleep(0.1) -- Creates a brief delay between particle bursts |
25 | - | modem.transmit(43, 15, "Opening Courtyard Gate") |
25 | + | |
26 | - | end |
26 | + | |
27 | ||
28 | - | elseif message == "status" then |
28 | + | -- Process the received message based on its content |
29 | - | courtyard = "" |
29 | + | if message == "Recall" then |
30 | - | bridge = "" |
30 | + | print("Recalling Player...") |
31 | - | lockdown = "" |
31 | + | modem.transmit(43, CHANNEL, "Recalling Player...") |
32 | - | if redstone.getInput("right") then |
32 | + | |
33 | - | courtyard = "Courtyard Gate Closed, " |
33 | + | print("Starting Teleporter") |
34 | - | else |
34 | + | os.sleep(2) |
35 | - | courtyard = "Courtyard Gate Open, " |
35 | + | |
36 | - | end |
36 | + | for i = 1, 100 do |
37 | - | if redstone.getInput("left") then |
37 | + | local chargePercent = i |
38 | - | bridge = "Bridge Gate Closed, " |
38 | + | print("Charging " .. chargePercent .. "%") |
39 | - | else |
39 | + | modem.transmit(43, CHANNEL, "Charging " .. chargePercent .. "%") |
40 | - | bridge = "Bridge Gate Open, " |
40 | + | sleep(0.05) -- 100 updates over 5 seconds |
41 | - | end |
41 | + | |
42 | - | if redstone.getInput("back") then |
42 | + | |
43 | - | lockdown = "Lockdown Enabled" |
43 | + | -- Teleport the player |
44 | - | else |
44 | + | local targetX, targetY, targetZ = 293, 95, 750 |
45 | - | lockdown = "Lockdown Disabled" |
45 | + | commands.exec("tp Alexr036 " .. targetX .. " " .. targetY .. " " .. targetZ) |
46 | - | end |
46 | + | |
47 | - | modem.transmit(43, 15, courtyard .. bridge .. lockdown) |
47 | + | -- Summon teleport particles |
48 | summonParticles(targetX, targetY, targetZ) | |
49 | ||
50 | - | elseif message == "Lockdown" then |
50 | + | elseif message == "Teleport" then |
51 | - | os.sleep(1) |
51 | + | print("Programming Started") |
52 | - | if redstone.getInput("back") then |
52 | + | |
53 | - | modem.transmit(43, 15, "Enabeling Lockdown") |
53 | + | local positionX = receiveMessage() |
54 | - | else |
54 | + | print("Position X: " .. positionX) |
55 | - | modem.transmit(43, 15, "Disabeling Lockdown") |
55 | + | |
56 | - | end |
56 | + | local positionY = receiveMessage() |
57 | print("Position Y: " .. positionY) | |
58 | ||
59 | local positionZ = receiveMessage() | |
60 | print("Position Z: " .. positionZ) | |
61 | ||
62 | - | print("Bastion Online!") |
62 | + | print("Starting Teleporter") |
63 | os.sleep(2) | |
64 | - | -- Main loop |
64 | + | |
65 | - | while true do |
65 | + | for i = 1, 100 do |
66 | - | bastion() |
66 | + | local chargePercent = i |
67 | print("Charging " .. chargePercent .. "%") | |
68 | - | |
68 | + | modem.transmit(43, CHANNEL, "Charging " .. chargePercent .. "%") |
69 | sleep(0.05) -- 100 updates over 5 seconds | |
70 | end | |
71 | ||
72 | -- Teleport the player | |
73 | commands.exec("tp Alexr036 " .. positionX .. " " .. positionY .. " " .. positionZ) | |
74 | ||
75 | -- Summon teleport particles | |
76 | summonParticles(positionX, positionY, positionZ) | |
77 | ||
78 | elseif message == "Remote Connected" then | |
79 | print("Connected to System") | |
80 | modem.transmit(43, CHANNEL, "Connected to System") | |
81 | end | |
82 | ||
83 | os.reboot() |