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