burnin_aura

ABM Advanced Client

Mar 22nd, 2017
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. --[[Initialization]]--
  2. shell.run("clear")
  3. shell.run("id")
  4. missilesilo = peripheral.wrap("back")
  5. rednet.open("top")
  6. local armed = true
  7. local masterID
  8. --local pack = textutils.serialise(siloData)
  9.  
  10. --[[Contingencies]]--
  11.  
  12. if peripheral.call("back", "getMissile") ~= "{}"
  13. then currentmissile = "No Missile"
  14.   elseif peripheral.call("back", "getMissile") = "anti-ballistic missile"
  15.   then
  16.    local  currentmissile = tostring(missilesilo.getMissile())
  17.     end
  18.  
  19. --//Basically provides a contingency that when no missile is detected, it returns "No Missile"
  20. --//Prevents crashing due to nil values returned by empty missile silo.
  21.  
  22.  
  23. --[[Data Storage + Table]]--
  24. local  target = tostring(missilesilo.getTarget())
  25.  
  26. local siloData = {
  27. ["Msg"] = "ABM",
  28. ["ID"] = os.getComputerID(),
  29. ["Missile"] = currentmissile,
  30. ["Target"] = target
  31. }
  32.  
  33. --[[Main Program + Rednet Setup]]--
  34. while true do
  35.  print("Waiting for Threat Message From Defense Server...")
  36.  local id, msg2 = rednet.receive(masterID)
  37.  
  38.   if (msg2 == "ABM1") then
  39.     print("  master=", id)
  40.     masterID = id;
  41.     print(siloData[1])
  42.     rednet.send(masterID, siloData)
  43.  
  44. --//Top: If a message "ABM1" is received then log the id of the sender and send that ID the data.
  45. --//Bottom: If the message is not "ABM1" and is a "table" from the id of the original sender then prepare for launch.
  46.  
  47.             elseif type(msg2) == "table" and id == masterID then
  48.               if type(msg2.x) == "number" and type(msg2.y) == "number" and type(msg2.z) == "number" then
  49.               print("  launching CounterMeasures At x=" .. msg2.x .. ", y=" .. msg2.y .. ", z=" .. msg2.z)
  50.               icbm.setTarget(msg2.x, msg2.y, msg2.z)
  51.  
  52.                 if (armed) then
  53.                 peripheral.call("back","launch")
  54.               end
  55.  
  56.           else
  57.       print("  Invalid Table Command")
  58.     end
  59.   else
  60.  print("  Invalid Message:",msg," from: ",id)
  61. end
  62. end
Add Comment
Please, Sign In to add comment