burnin_aura

[CC] [ABM] [Main] [Functional]

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