View difference between Paste ID: NEiXx33k and H4kALgKf
SHOW: | | - or go back to the newest paste.
1-
--[[Skynet Nuclear ABM Defense Program by Andrew2060]]--
1+
--[[Skynet Nuclear ABM Defense Program BY: Andrew2060]]--
2-
--[ABM Server, use with http://pastebin.com/aNsduCem]]--
2+
--[[ABM Server, use with http://pastebin.com/aNsduCem]]--
3-
--[System requires atleast 5 CC's with Modems and ABMs]]--
3+
4-
--[System has 5% chance of failure in killing missiles]]--
4+
5
local waitDelay = 2
6
local countersPerMissile = 1
7
local missileDelay = 3
8
9
--[[Initialization]]--
10
local silos, curSilo = {}, 1
11
local retalSilos = {}
12
peripheral.find("modem", rednet.open)
13
term.setBackgroundColor(colors.blue)
14
15
--Set your base coordinates here to determine distance
16
local homeX = 578 
17
local homeY = 56
18
local homeZ = -494
19
 
20
local function red()
21
term.setBackgroundColor(colors.red)
22
print("                                                   ")
23
term.setBackgroundColor(colors.blue)
24
end
25-
	local id, msg = rednet.receive(waitDelay)
25+
26-
	if msg == "ABM" then table.insert(silos, id) end
26+
27
rednet.broadcast("Retaliate")
28
 
29
repeat
30
    local id, msg = rednet.receive(waitDelay)
31-
	if not redstone.getInput("back") then
31+
    if msg == "ABM" then table.insert(silos, id)
32-
		term.clear()
32+
    elseif msg == "RetaliationCheck" then table.insert(retalSilos, id) end
33-
		term.setCursorPos(1, 1)
33+
34
 
35-
		red()
35+
36-
		print("        SKYNET DEFENSE SYSTEMS ACTIVATED           ")
36+
37-
		red()
37+
    if not redstone.getInput("back") then
38-
		print("      ANTI-BALLISTIC MISSILE SHIELD ONLINE         ")
38+
        term.clear()
39-
		red()
39+
        term.setCursorPos(1, 1)
40-
	    red()
40+
41-
		print("               [STANDBY ABM Silos]                 ")
41+
42
        print("        SKYNET DEFENSE SYSTEMS ACTIVATED           ")
43-
		for k, v in ipairs(silos) do print("  silo #" .. k .. " id = "..v) end
43+
44
        print("      ANTI-BALLISTIC MISSILE SHIELD ONLINE         ")
45-
		
45+
46-
		repeat os.pullEvent("redstone") until redstone.getInput("back")
46+
47-
	end
47+
        print("               [STANDBY ABM Silos]                 ")
48-
	
48+
49-
	term.clear()
49+
        for k, v in ipairs(silos) do print("  silo #" .. k .. " id = "..v) end
50-
	term.setCursorPos(1, 1)
50+
51-
	term.setTextColor(colors.red)
51+
       
52-
	
52+
        repeat os.pullEvent("redstone") until redstone.getInput("back")
53-
	print("Incoming Missiles:")
53+
    end
54-
	print("Firing CounterMeasures\n")
54+
   
55-
	
55+
    term.clear()
56
    term.setCursorPos(1, 1)
57
    term.setTextColor(colors.red)
58
   
59
    print("Incoming Missiles:")
60
    print("Firing CounterMeasures\n")
61
   
62
 maptab = peripheral.call("back","getEntities")
63
 maptxt = textutils.serialize(maptab)
64
 if maptxt ~= "{}" then
65-
		local msg = {["x"] = math.floor(maptab["x_"..i]), ["y"] = math.floor(maptab["y_"..i]), ["z"] = math.floor(maptab["z_"..i])}
65+
66
 for num in pairs(maptab) do
67-
		print("Incoming Missile Threat #" .. i .. " at X:" .. msg.x .. " Y:" .. msg.y .. " Z:" .. msg.z)
67+
68-
		print("Launching " .. countersPerMissile .. " of ABM Missile CounterMeasures...\n")
68+
69
 targets = allDat/3
70-
		for i = 1, countersPerMissile do
70+
71-
			rednet.send(silos[curSilo], msg)
71+
        local msg = {["x"] = math.floor(maptab["x_"..i]), ["y"] = math.floor(maptab["y_"..i]), ["z"] = math.floor(maptab["z_"..i])}
72-
			curSilo = (curSilo == #silos) and 1 or (curSilo + 1)
72+
        local x2 = math.floor(tonumber(maptab["x_"..i])/1)
73-
			sleep(missileDelay)
73+
        local y2 = math.floor(tonumber(maptab["y_"..i])/1)
74-
			end
74+
        local z2 = math.floor(tonumber(maptab["z_"..i])/1)
75-
	    sleep(0)
75+
        local msg2 = {x2, y2, z2}
76-
		end
76+
        local distance = math.sqrt((x2-homeX)^2 + (y2-homeY)^2 + (z2-homeZ)^2)
77
        print("Incoming Missile")
78-
	end
78+
        print("  X:" .. msg.x .. " Y:" .. msg.y .. " Z:" .. msg.z..  " Distance: "..distance)
79-
   sleep(2)
79+
        print("Launching " .. countersPerMissile .. " ABM Missile CounterMeasures...\n")
80
        term.setBackgroundColor(colors.blue)
81-
sleep(1)
81+
        if distance < 1000 then
82
        for i = 1, countersPerMissile do
83
            rednet.send(silos[curSilo], msg)
84
            rednet.send(retalSilos, msg2)
85
            
86
            curSilo = (curSilo == #silos) and 1 or (curSilo + 1)
87
            sleep(0)
88
            sleep(missileDelay)
89
            end
90
        sleep(0)
91
        end
92
     sleep(0)
93
    end
94
   sleep(1)
95
end
96
rednet.send(5, msg2)
97
sleep(1)
98
end