SHOW:
|
|
- or go back to the newest paste.
1 | -- Print a line of dashes for aesthetics | |
2 | - | term.clear() |
2 | + | local function lineBreak() |
3 | - | term.setCursorPos(1, 1) |
3 | + | local width, height = term.getSize() |
4 | for i = 1, width do | |
5 | io.write("-") | |
6 | - | local modem = peripheral.find("modem") or error("No modem attached", 0) |
6 | + | end |
7 | - | modem.open(43) -- Open channel 43 to receive messages |
7 | + | io.write("\n") |
8 | end | |
9 | -- Function to clear the screen | |
10 | local function clearScreen() | |
11 | - | modem.transmit(15, 43, "Remote Connected") |
11 | + | term.clear() |
12 | term.setCursorPos(1, 1) | |
13 | - | local event, side, channel, replyChannel, message, distance |
13 | + | |
14 | - | repeat |
14 | + | |
15 | - | event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message") |
15 | + | |
16 | - | until channel == 43 |
16 | + | -- Print the welcome message |
17 | print("Artillary Controller") | |
18 | - | print(tostring(message)) |
18 | + | lineBreak() |
19 | print("Select a weapon!") | |
20 | - | -- Define the allowed options |
20 | + | print("1. TNT") |
21 | - | local allowedOptions = {"Bridge", "Courtyard", "Archive", "Stables", "Filters", "status"} |
21 | + | print("2. Napalm") |
22 | print("3. Nuke") | |
23 | - | -- Prompt the user to choose from the options |
23 | + | lineBreak() |
24 | - | print("Choose one of the following options:") |
24 | + | |
25 | - | for i, option in ipairs(allowedOptions) do |
25 | + | local choice = read() |
26 | - | print(i .. ". " .. option) |
26 | + | |
27 | if choice == "1" then | |
28 | projectileType = "TNT" | |
29 | - | -- Validate user input |
29 | + | elseif choice == "2" then |
30 | - | local userInput |
30 | + | projectileType = "Napalm" |
31 | - | repeat |
31 | + | elseif choice == "3" then |
32 | - | print("Enter the number corresponding to your choice:") |
32 | + | projectileType = "Nuke" |
33 | - | userInput = tonumber(read()) |
33 | + | |
34 | - | until userInput and allowedOptions[userInput] |
34 | + | |
35 | clearScreen() | |
36 | - | -- Send the chosen option |
36 | + | print("Artillary Controller") |
37 | - | local chosenOption = allowedOptions[userInput] |
37 | + | lineBreak() |
38 | - | modem.transmit(15, 43, chosenOption) |
38 | + | print("Weapon:"..projectileType) |
39 | lineBreak() | |
40 | print("Select a targeting method") | |
41 | print("1. Current Position") | |
42 | - | -- Wait for a reply |
42 | + | print("2. Custom Position") |
43 | - | repeat |
43 | + | lineBreak() |
44 | - | event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message") |
44 | + | |
45 | - | until channel == 43 |
45 | + | local choice = read() |
46 | ||
47 | - | print(tostring(message)) |
47 | + | if choice == "1" then |
48 | - | |
48 | + | targetX, targetY, targetZ = gps.locate() |
49 | elseif choice == "2" then | |
50 | print("X: ") | |
51 | targetX = read() | |
52 | print("Y: ") | |
53 | targetY = read() | |
54 | print("Z: ") | |
55 | targetZ = read() | |
56 | end | |
57 | ||
58 | clearScreen() | |
59 | print("Artillary Controller") | |
60 | lineBreak() | |
61 | print("Weapon:"..projectileType) | |
62 | print("X:"..targetX) | |
63 | print("Y:"..targetY) | |
64 | print("Z:"..targetZ) | |
65 | lineBreak() | |
66 | print("Please Confirm") | |
67 | print("1. Confirm Input") | |
68 | print("2. Cancel") | |
69 | lineBreak() | |
70 | ||
71 | ||
72 | local choice = read() | |
73 | ||
74 | if choice == "1" then | |
75 | print("Confrimed Fiering!") | |
76 | ||
77 | local modem = peripheral.find("modem") or error("No modem attached", 0) | |
78 | modem.open(43) -- Open 43 so we can receive replies | |
79 | ||
80 | modem.transmit(15, 43, projectileType) | |
81 | os.sleep(1) | |
82 | modem.transmit(15, 43, targetX) | |
83 | os.sleep(1) | |
84 | modem.transmit(15, 43, targetY) | |
85 | os.sleep(1) | |
86 | modem.transmit(15, 43, targetZ) | |
87 | ||
88 | local event, side, channel, replyChannel, message, distance | |
89 | repeat | |
90 | event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message") | |
91 | until channel == 43 | |
92 | ||
93 | clearScreen() | |
94 | ||
95 | print(tostring(message)) | |
96 | elseif choice == "2" then | |
97 | print("Cancelled") | |
98 | end |