burnin_aura

[CC] [ABM Server] [V2] [Working]

May 29th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[Skynet Nuclear ABM Defense Program BY: Andrew2060]]--
  2. --[[ABM Server, use with http://pastebin.com/aNsduCem]]--
  3.  
  4. --[[Settings]]--
  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.  
  26. rednet.broadcast("ABM1")
  27. rednet.broadcast("Retaliate")
  28.  
  29. repeat
  30.     local id, msg = rednet.receive(waitDelay)
  31.     if msg == "ABM" then table.insert(silos, id)
  32.     elseif msg == "RetaliationCheck" then table.insert(retalSilos, id) end
  33. until not id
  34.  
  35. --[[Main Programs]]--
  36. while true do
  37.     if not redstone.getInput("back") then
  38.         term.clear()
  39.         term.setCursorPos(1, 1)
  40.  
  41.         red()
  42.         print("        SKYNET DEFENSE SYSTEMS ACTIVATED           ")
  43.         red()
  44.         print("      ANTI-BALLISTIC MISSILE SHIELD ONLINE         ")
  45.         red()
  46.         red()
  47.         print("               [STANDBY ABM Silos]                 ")
  48.  
  49.         for k, v in ipairs(silos) do print("  silo #" .. k .. " id = "..v) end
  50.         red()
  51.        
  52.         repeat os.pullEvent("redstone") until redstone.getInput("back")
  53.     end
  54.    
  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.  allDat = 0
  66.  for num in pairs(maptab) do
  67.  allDat = allDat+1
  68.  end
  69.  targets = allDat/3
  70.  for i=0,targets-1 do
  71.         local msg = {["x"] = math.floor(maptab["x_"..i]), ["y"] = math.floor(maptab["y_"..i]), ["z"] = math.floor(maptab["z_"..i])}
  72.         local x2 = math.floor(tonumber(maptab["x_"..i])/1)
  73.         local y2 = math.floor(tonumber(maptab["y_"..i])/1)
  74.         local z2 = math.floor(tonumber(maptab["z_"..i])/1)
  75.         local msg2 = {x2, y2, z2}
  76.         local distance = math.sqrt((x2-homeX)^2 + (y2-homeY)^2 + (z2-homeZ)^2)
  77.         print("Incoming Missile")
  78.         print("  X:" .. msg.x .. " Y:" .. msg.y .. " Z:" .. msg.z..  " Distance: "..distance)
  79.         print("Launching " .. countersPerMissile .. " ABM Missile CounterMeasures...\n")
  80.         term.setBackgroundColor(colors.blue)
  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
Add Comment
Please, Sign In to add comment