burnin_aura

ABM Server WIP v3

Mar 21st, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. -[[Settings]]--
  2. local waitDelay = 2
  3. local countersPerMissile = 1
  4. local missileDelay = 3
  5.  
  6. --[[Initialization]]--
  7. local silos, curSilo = {}, 1
  8. local siloData = {}
  9. peripheral.find("modem", rednet.open)
  10. term.setBackgroundColor(colors.blue)
  11.  
  12. local function red()
  13. term.setBackgroundColor(colors.red)
  14. print(" ")
  15. term.setBackgroundColor(colors.blue)
  16. end
  17.  
  18. rednet.broadcast("ABM1")
  19. repeat
  20. local id, msg, status = rednet.receive(waitDelay)
  21. if msg == "ABM" then
  22. table.insert(silos, id)
  23. table.insert(siloData, missile)
  24.  
  25. 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(" SKYNET 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.  
  44. red()
  45.  
  46. repeat os.pullEvent("redstone") until redstone.getInput("back")
  47. end
  48.  
  49. term.clear()
  50. term.setCursorPos(1, 1)
  51. term.setTextColor(colors.red)
  52.  
  53. print("Incoming Missiles:")
  54. print("Firing CounterMeasures\n")
  55.  
  56. maptab = peripheral.call("back","getEntities")
  57. maptxt = textutils.serialize(maptab)
  58. if maptxt ~= "{}" then
  59. allDat = 0
  60. for num in pairs(maptab) do
  61. allDat = allDat+1
  62. end
  63. targets = allDat/3
  64. for i=0,targets-1 do
  65. local msg = {["x"] = math.floor(maptab["x_"..i]), ["y"] = math.floor(maptab["y_"..i]), ["z"] = math.floor(maptab["z_"..i])}
  66.  
  67. print("Incoming Missile Threat #" .. i .. " at X:" .. msg.x .. " Y:" .. msg.y .. " Z:" .. msg.z)
  68. print("Launching " .. countersPerMissile .. " of ABM Missile CounterMeasures...\n")
  69.  
  70. for i = 1, countersPerMissile do
  71. rednet.send(silos[curSilo], msg)
  72. curSilo = (curSilo == #silos) and 1 or (curSilo + 1)
  73. sleep(missileDelay)
  74. end
  75. sleep(0)
  76. end
  77. sleep(0)
  78. end
  79. sleep(2)
  80. end
  81. sleep(1)
Add Comment
Please, Sign In to add comment