View difference between Paste ID: rST5Sygp and 41kbsdp5
SHOW: | | - or go back to the newest paste.
1
shell.run("rm startup")
2-
shell.run("pastebin get 41kbsdp5 startup")
2+
shell.run("pastebin get rST5Sygp startup")
3
4-
subCoordX = 4162
4+
subCoordX = 888
5-
subCoordY = 66
5+
subCoordY = 72
6-
subCoordZ = 3921
6+
subCoordZ = 112
7-
maxDist = 10000
7+
maxDist = 20000
8-
remMissile = 10
8+
remMissile = 1
9-
salvoNumber = 1
9+
10
function clear()
11
    term.clear()
12
    term.setCursorPos(1, 1)
13
    term.write("        Raketnym kompleksom \"D-1\"")
14-
    term.write("        Raketnym kompleksom \"Ametist\"")
14+
15
16
17-
function updateSalvo()
17+
18-
    salvoNumber = salvoNumber + 1
18+
19-
    if salvoNumber > 5 then
19+
20-
        salvoNumber = 1
20+
21
        term.setCursorPos(1, 6)
22
        term.write("X: ")
23
        term.setCursorPos(1, 8)
24
        term.write("Z: ")
25
        term.setCursorPos(1, 10)
26
        term.write("Radius: ")
27
        term.setCursorPos(4, 6)
28
        x = read()
29
        term.setCursorPos(4, 8)
30
        z = read()
31
        term.setCursorPos(9, 10)
32
        radius = read()
33
		radius = math.max(1, radius)
34
		radius = math.min(4, radius)
35
36
        term.setCursorPos(1, 12)
37
38
        if tonumber(x) ~= nil and tonumber(z) ~= nil and tonumber(radius) ~= nil then
39
            print("Sokhranennyye koordinaty.")
40
            break
41
        end
42
    end
43
44
    sleep(1)
45
    clear()
46
end
47
48
function drawRosace()
49
    term.setCursorPos(21, 6)
50
    term.write("    |    ")
51
    term.setCursorPos(21, 7)
52
    term.write("    |    ")
53
    term.setCursorPos(21, 8)
54
    term.write("   /|\\   ")
55
    term.setCursorPos(21, 9)
56
    term.write("  / | \\  ")
57
    term.setCursorPos(21, 10)
58
    term.write("----O----")
59
    term.setCursorPos(21, 11)
60
    term.write("  \\ | /  ")
61
    term.setCursorPos(21, 12)
62
    term.write("   \\|/   ")
63
    term.setCursorPos(21, 13)
64
    term.write("    |    ")
65
    term.setCursorPos(21, 14)
66
    term.write("    |    ")
67
end
68
69
function getRemainingMissile()
70
    term.setCursorPos(1, 19)
71
    term.write("Raketa:  "..remMissile,,"          ")
72
end
73
74
function launchMissile(coordx, coordz, radius)
75
	coordx=tonumber(coordx)
76
	coordz=tonumber(coordz)
77
    p = peripheral.wrap("bottom")
78-
    term.write("Raketa:  "..remMissile.. " - Raketnyy zalp:  " .. salvoNumber.."     ")
78+
79
    y = 128
80
    id = 0
81
    while id == 0 or id == 8 or id == 9 or id == 221 or id == 231 or id == 49 or id == 57 or id == 10 or id == 11 do
82
        id = w.getBlockID(coordx, y, coordz)
83
        y = y-1
84
        if y < 10 then
85
            clear()
86
            print("\n\nZapusk rakety ne udaslya!!!!")
87
            sleep(1)
88
            os.reboot()
89
        end
90
    end
91
    clear()
92
    w.playSound("AdvJetpacks_startup", coordx, y, coordz, 1, 0.2)
93
    print("\n\nZapusk krylatyye rakety!")
94
    rs.setOutput("back", true)
95
    sleep(0.5)
96
    rs.setOutput("back", false)
97
    sleep(1)
98
    w.explode(subCoordX, subCoordY, subCoordZ, 1, false, false)   
99
    sleep(2)
100
    
101
    spawnMissile(coordx, coordz, radius)
102
end
103
104
function spawnMissile(coordX, coordZ, size)
105
    p = peripheral.wrap("bottom")
106
    w = p.getWorld(0)
107
    abort = false
108
    xt = 0 -- current position; x
109
    zt = 0 -- / current position; y
110
    d = 0 --  current direction; 0=RIGHT, 1=DOWN, 2=LEFT, 3=UP
111
    s = 1 --  chain size
112
 
113
    k=1
114
    while k <= size-1 do
115
        k = k+1
116
    	m = 0
117
    	if k < size-1 then
118
        	m = 2
119
        else
120
        	m = 3
121
        end
122
        j = 0
123
        while j<m do
124
            j=j+1
125
            i=0
126
            while i<s do
127
                i=i+1
128
                --std::cout << matrix[x][y] << " ";
129
                --print("X: " .. coordX+xt .. " Z: " .. coordZ+zt)
130
                id = w.getBlockID(coordX+xt, y, coordZ+zt)
131
                if id == 8 or id == 9 then
132
                    abort = true
133
                    break
134
                end
135
                
136
                spawnGas(coordX+xt, coordZ+zt)
137
 
138
                if d == 0 then zt = zt + 2
139
                elseif d == 1 then xt = xt + 2
140
                elseif d == 2 then zt = zt - 2
141
                elseif d == 3 then xt = xt - 2
142
				end
143
            end
144
            if abort == true then
145
                break
146
            end
147
            d = (d+1)%4
148
        end
149
        if abort == true then
150
            break
151
        end
152
        s = s + 1
153
    end
154
    
155
    w.setBlock(coordX, y+1, coordZ, 76, 0)
156
end
157
158
function spawnGas(x, z)
159
	w.setBlock(x, y, z, 1, 0)
160
	w.setBlock(x, y+2, z, 929, 0)
161
	--w.setBlock(x, y+1, z, 76, 0)
162
end
163
164
function validateCodes()
165
    while true do
166
        error = 0
167
        clear()
168
        print("\n\nKod autentifikatsii:")
169
        term.setCursorPos(1, 6)
170
        term.write("CDR:")
171
        term.setCursorPos(1, 8)
172
        term.write("XO:")
173
        term.setCursorPos(6, 6)
174
        code1 = read()
175
        term.setCursorPos(6, 8)
176
        code2 = read()
177
        term.setCursorPos(1, 10)
178
179
        
180
        if tonumber(code1) ~= nil and tonumber(code2) ~= nil then
181
            rest = http.get("http://172.16.20.220/luanet/servlets/ssb/gorae.php?code1="..code1.."&code2="..code2)
182
            reply = rest.readAll()
183
            rest.close()
184
185
            if reply == "OK" then
186
                print("Zapusk razreshen.")
187
                launchMissile(x, z, radius)
188-
            rest = http.get("http://172.16.20.220/luanet/servlets/ssg/k222.php?code1="..code1.."&code2="..code2)
188+
189
            else 
190
                term.setCursorPos(1,15)
191
                term.write("Oshibka! Nevernyy kod!")
192
                error = error + 1
193
                if error > 3 then
194
                    os.reboot()
195
                end
196
                sleep(1)
197
                term.setCursorPos(1,15)
198
                term.write("                      ")
199
            end
200
        end
201
    end
202
203
    sleep(1)
204
    clear()
205
end
206
207
function shootMissile() 
208
    if remMissile > 0 then
209
        validateCodes()
210
        launchMissile(tonumber(x), tonumber(z), tonumber(radius))
211
        remMissile = remMissile - 1
212
        return true
213
    else
214
        return false
215
    end
216
end
217
218
219
function autoAcquire()
220
    p = peripheral.wrap("bottom")
221
    
222
    while true do
223
        clear()
224
        print("\n\nTsel:'")
225-
function shootMissileSalvo(nOfSalvo)
225+
226-
    if remMissile >= nOfSalvo then
226+
227
        term.setCursorPos(1, 9)
228-
        for i = nOfSalvo,0,-1 do
228+
229-
            launchMissile(tonumber(x), tonumber(z), tonumber(radius))
229+
230-
            sleep(5)
230+
231
        user = read()
232-
        remMissile = remMissile - nOfSalvo
232+
233
        radius = read()
234
		radius = math.max(1, radius)
235
		radius = math.min(8, radius)
236
		
237
        pl = p.getPlayerByName(user)
238
        term.setCursorPos(1, 12)
239
240
        if pl ~= nil and tonumber(radius) ~= nil then
241
            ent = pl.asEntity()
242
            x, ignoredY, z = ent.getPosition()
243
            print("Tsel' dostignuta.")
244
            break
245
        end
246
    end
247
248
    sleep(1)
249
    clear()
250
end
251
252
253
254
x = 291
255
z = 289
256
radius = 10
257
258
clear()
259
while true do
260
    clear()
261
    getRemainingMissile()
262
    drawRosace()
263
    term.setCursorPos(1, 3)
264
    term.write("         ")
265
    term.setCursorPos(1, 3)
266
    term.write("X: " .. x)
267
    term.setCursorPos(1, 4)
268
    term.write("          ")
269
    term.setCursorPos(1, 4)
270
    term.write("Z: " .. z)
271
    term.setCursorPos(1, 5)
272
273
    d = math.floor(math.sqrt(((x - subCoordX) ^ 2) + ((z - subCoordZ) ^ 2))) / 1000
274
275
    term.write("d: " .. d .. " km               ")
276
    local event, key = os.pullEvent("key")
277
    if key == 200 then
278
        z = z + 1
279
    elseif key == 208 then
280
        z = z - 1
281
    elseif key == 203 then
282
        x = x - 1
283
    elseif key == 205 then
284
        x = x + 1
285
    elseif key == 211 then
286
        if d < maxDist then
287
        	shootMissile()
288
        else
289
            clear()
290
            term.setCursorPos(1, 12)
291
            print("Tsel' slishkom daleko.")
292
            sleep(2)
293
            clear()
294
        end
295
    elseif key == 210 then
296
        insertCoords()
297
    elseif key == 199 then
298
        autoAcquire()
299
    end
300
end