Advertisement
Aidan428

ICBM Launcher Client2

May 8th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.93 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.  
  9. --[[Contingencies]]--
  10.  
  11. if peripheral.call("back", "getMissile") ~= "nil"
  12. then currentmissile = tostring(missilesilo.getMissile())
  13.   else
  14.     currentmissile = "Empty"
  15.     end
  16.  
  17. --//Basically provides a contingency that when no missile is detected, it returns "No Missile"
  18. --//Prevents crashing due to nil values returned by empty missile silo.
  19.  
  20.  
  21. --[[Data Storage + Table]]--
  22. local target = tostring(missilesilo.getTarget())
  23. local xc, yc, zc = missilesilo.getTarget()
  24.  
  25. local siloData = {
  26. ["Msg"] = "pong",
  27. ["ID"] = os.getComputerID(),
  28. ["Missile"] = currentmissile,
  29. ["Armed"] = armed,
  30. ["TarX"] = xc,
  31. ["TarY"] = yc,
  32. ["TarZ"] = zc
  33. }
  34.  
  35. --[[Main Program + Rednet Setup]]--
  36. while true do
  37.  print("Waiting for Threat Message From Defense Server...")
  38.  local id, msg2 = rednet.receive(masterID)
  39.  
  40.   if (msg2 == "ping") then
  41.     print("  master=", id)
  42.     masterID = id;
  43.     print(siloData[1])
  44.     rednet.send(masterID, siloData)
  45.     print("Data has successfully been sent to: "..masterID)
  46.  
  47. --//Top: If a message "ping" is received then log the id of the sender and send that ID the data.
  48. --//Bottom: If the message is not "ping" and is a "table" from the id of the original sender then prepare for launch.
  49.  
  50.             elseif type(msg2) == "table" and id == masterID then
  51.               if type(msg2.x) == "number" and type(msg2.y) == "number" and type(msg2.z) == "number" then
  52.               print("  Launching missiles  At X:" .. msg2.x .. ", Y:" .. msg2.y .. ", Z:" .. msg2.z)
  53.               missilesilo.setTarget(msg2.x, msg2.y, msg2.z)
  54.  
  55.                 if (armed) then
  56.                 peripheral.call("back","launch")
  57.               end
  58.  
  59.           else
  60.       print("  Invalid Table Command")
  61.     end
  62.   else
  63.  print("  Invalid Message:",msg," from: ",id)
  64. end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement