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 43 so we can receive replies |
| 7 | + | io.write("\n")
|
| 8 | - | |
| 8 | + | |
| 9 | - | modem.transmit(15, 43, "Remote Connected") |
| 9 | + | -- Function to clear the screen |
| 10 | - | |
| 10 | + | |
| 11 | - | local event, side, channel, replyChannel, message, distance |
| 11 | + | term.clear() |
| 12 | - | repeat |
| 12 | + | term.setCursorPos(1, 1) |
| 13 | - | event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
| 13 | + | |
| 14 | - | until channel == 43 |
| 14 | + | |
| 15 | - | |
| 15 | + | |
| 16 | -- Print the welcome message | |
| 17 | - | |
| 17 | + | print("Artillery Controller")
|
| 18 | - | print(tostring(message)) |
| 18 | + | lineBreak() |
| 19 | print("Select a weapon:")
| |
| 20 | print("1. TNT")
| |
| 21 | print("2. Nuke")
| |
| 22 | print("3. Arrows")
| |
| 23 | lineBreak() | |
| 24 | - | -- Define the allowed options |
| 24 | + | |
| 25 | - | local allowedOptions = {"Fortress"}
|
| 25 | + | local choice = read() |
| 26 | ||
| 27 | - | -- Prompt the user to choose from the options |
| 27 | + | if choice == "1" then |
| 28 | - | print("Choose one of the following options:")
|
| 28 | + | projectileType = "TNT" |
| 29 | - | for i, option in ipairs(allowedOptions) do |
| 29 | + | elseif choice == "2" then |
| 30 | - | print(i .. ". " .. option) |
| 30 | + | print("Authorization Code:")
|
| 31 | local auth = read() | |
| 32 | if auth == "1234" then | |
| 33 | - | -- Validate user input |
| 33 | + | print("Codes Accepted")
|
| 34 | - | local userInput |
| 34 | + | projectileType = "Nuke" |
| 35 | - | repeat |
| 35 | + | end |
| 36 | - | print("Enter the number corresponding to your choice:")
|
| 36 | + | elseif choice == "3" then |
| 37 | - | userInput = tonumber(read()) |
| 37 | + | projectileType = "Arrows" |
| 38 | - | until userInput and allowedOptions[userInput] |
| 38 | + | |
| 39 | ||
| 40 | - | -- Send the chosen option |
| 40 | + | if projectileType == "Arrows" then |
| 41 | - | local chosenOption = allowedOptions[userInput] |
| 41 | + | clearScreen() |
| 42 | - | modem.transmit(15, 43, chosenOption) |
| 42 | + | print("Artillery Controller")
|
| 43 | lineBreak() | |
| 44 | print("Select Arrow Mode:")
| |
| 45 | print("1. Spray")
| |
| 46 | - | -- Wait for a reply |
| 46 | + | print("2. Scatter")
|
| 47 | - | repeat |
| 47 | + | lineBreak() |
| 48 | - | event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
| 48 | + | local modeChoice = read() |
| 49 | - | until channel == 43 |
| 49 | + | if modeChoice == "2" then |
| 50 | - | |
| 50 | + | arrowMode = "Scatter" |
| 51 | else | |
| 52 | - | |
| 52 | + | arrowMode = "Spray" |
| 53 | - | print(tostring(message)) |
| 53 | + | end |
| 54 | end | |
| 55 | ||
| 56 | - | shell.run("Greeting") |
| 56 | + | |
| 57 | ||
| 58 | -- Ask for shot size | |
| 59 | print("Artillery Controller")
| |
| 60 | lineBreak() | |
| 61 | print("Weapon:"..projectileType)
| |
| 62 | lineBreak() | |
| 63 | print("Size of Shot:")
| |
| 64 | print("1. 1x1")
| |
| 65 | print("2. 2x2")
| |
| 66 | if projectileType == "TNT" then | |
| 67 | print("3. 3x3")
| |
| 68 | print("4. 4x4")
| |
| 69 | print("5. 5x5")
| |
| 70 | print("6. Stab Charge")
| |
| 71 | ||
| 72 | local choice = read() | |
| 73 | if choice == "2" then | |
| 74 | projectilePattern = "2x2" | |
| 75 | elseif choice == "3" then | |
| 76 | projectilePattern = "3x3" | |
| 77 | elseif choice == "4" then | |
| 78 | projectilePattern = "4x4" | |
| 79 | elseif choice == "5" then | |
| 80 | projectilePattern = "5x5" | |
| 81 | elseif choice == "6" then | |
| 82 | projectilePattern = "StabCharge" | |
| 83 | else | |
| 84 | projectilePattern = "Single" | |
| 85 | end | |
| 86 | ||
| 87 | elseif projectileType == "Nuke" then | |
| 88 | local choice = read() | |
| 89 | if choice == "2" then | |
| 90 | projectilePattern = "2x2" | |
| 91 | else | |
| 92 | projectilePattern = "Single" | |
| 93 | end | |
| 94 | ||
| 95 | elseif projectileType == "Arrows" then | |
| 96 | if arrowMode == "Scatter" then | |
| 97 | projectilePattern = "Scatter" | |
| 98 | else | |
| 99 | projectilePattern = "Spray" | |
| 100 | end | |
| 101 | end | |
| 102 | ||
| 103 | clearScreen() | |
| 104 | ||
| 105 | print("Artillery Controller")
| |
| 106 | lineBreak() | |
| 107 | print("Weapon:"..projectileType)
| |
| 108 | print("Pattern:"..projectilePattern)
| |
| 109 | lineBreak() | |
| 110 | print("Number of Itterations")
| |
| 111 | lineBreak() | |
| 112 | local iterations = tonumber(read()) | |
| 113 | clearScreen() | |
| 114 | ||
| 115 | print("Artillery Controller")
| |
| 116 | lineBreak() | |
| 117 | print("Weapon:"..projectileType)
| |
| 118 | print("Pattern:"..projectilePattern)
| |
| 119 | lineBreak() | |
| 120 | print("Select a targeting method")
| |
| 121 | print("1. Current Position")
| |
| 122 | print("2. Custom Current")
| |
| 123 | print("3. Offset Position")
| |
| 124 | lineBreak() | |
| 125 | ||
| 126 | local choice = read() | |
| 127 | ||
| 128 | if choice == "2" then | |
| 129 | print("X: ")
| |
| 130 | targetX = read() | |
| 131 | print("Y: ")
| |
| 132 | targetY = read() | |
| 133 | print("Z: ")
| |
| 134 | targetZ = read() | |
| 135 | elseif choice == "3" then | |
| 136 | X, Y, Z = gps.locate() | |
| 137 | print("X: ")
| |
| 138 | targetX = X + read() | |
| 139 | print("Y: ")
| |
| 140 | targetY = Y + read() | |
| 141 | print("Z: ")
| |
| 142 | targetZ = Z + read() | |
| 143 | else | |
| 144 | targetX, targetY, targetZ = gps.locate() | |
| 145 | end | |
| 146 | ||
| 147 | clearScreen() | |
| 148 | print("Artillery Controller")
| |
| 149 | lineBreak() | |
| 150 | print("Weapon:"..projectileType)
| |
| 151 | print("Pattern:"..projectilePattern)
| |
| 152 | print("X:"..targetX)
| |
| 153 | print("Y:"..targetY)
| |
| 154 | print("Z:"..targetZ)
| |
| 155 | lineBreak() | |
| 156 | print("Please Confirm")
| |
| 157 | print("1. Confirm Input")
| |
| 158 | print("2. Cancel")
| |
| 159 | lineBreak() | |
| 160 | ||
| 161 | local choice = read() | |
| 162 | ||
| 163 | if choice == "1" then | |
| 164 | local modem = peripheral.find("modem") or error("No modem attached", 0)
| |
| 165 | modem.open(43) -- Open 43 so we can receive replies | |
| 166 | ||
| 167 | clearScreen() | |
| 168 | print("Artillery Controller")
| |
| 169 | lineBreak() | |
| 170 | modem.transmit(15, 43, "Artillery") | |
| 171 | os.sleep(0.1) | |
| 172 | print("Artillery Connected")
| |
| 173 | print("Starting Programing")
| |
| 174 | lineBreak() | |
| 175 | ||
| 176 | modem.transmit(15, 43, projectileType) | |
| 177 | print("Weapon:"..projectileType)
| |
| 178 | os.sleep(0.1) | |
| 179 | modem.transmit(15, 43, projectilePattern) | |
| 180 | print("Pattern:"..projectilePattern)
| |
| 181 | os.sleep(0.1) | |
| 182 | modem.transmit(15, 43, iterations) | |
| 183 | print("Iterations:"..iterations)
| |
| 184 | os.sleep(0.1) | |
| 185 | modem.transmit(15, 43, targetX) | |
| 186 | print("X:"..targetX)
| |
| 187 | os.sleep(0.1) | |
| 188 | modem.transmit(15, 43, targetY) | |
| 189 | print("Y:"..targetY)
| |
| 190 | os.sleep(0.1) | |
| 191 | modem.transmit(15, 43, targetZ) | |
| 192 | print("Z:"..targetZ)
| |
| 193 | ||
| 194 | os.sleep(0.5) | |
| 195 | clearScreen() | |
| 196 | print("Artillery Controller")
| |
| 197 | lineBreak() | |
| 198 | print("Programing Complete")
| |
| 199 | lineBreak() | |
| 200 | print("Firing Now")
| |
| 201 | ||
| 202 | clearScreen() | |
| 203 | print("Artillery Controller")
| |
| 204 | lineBreak() | |
| 205 | print("Programing Complete")
| |
| 206 | for i = 1, iterations+2 do | |
| 207 | local event, side, channel, replyChannel, message, distance | |
| 208 | repeat | |
| 209 | event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
| |
| 210 | until channel == 43 | |
| 211 | print(tostring(message)) | |
| 212 | end | |
| 213 | else | |
| 214 | print("Cancelled")
| |
| 215 | end | |
| 216 | ||
| 217 | os.sleep(1) | |
| 218 | shell.run("Greeting")
| |
| 219 |