Advertisement
Aidan428

ABM Server 1

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