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