burnin_aura

[CC] [Launch Server] [V3]

Jul 22nd, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. --# server/master/controller
  2.  
  3. --[[Functions]]--
  4. local silo = {}
  5. local curSilo = 1
  6.  
  7. local function printSilos()
  8.   if silo[1] then
  9.         textutils.pagedTabulate({"ID", "Type", "Armed"}, unpack(silo))
  10.     else print("No connected slaves")
  11.   end
  12. end
  13.  
  14.     local function findSilos()
  15.     rednet.broadcast("ping silo")
  16.     local timerID = os.startTimer(waitDelay)
  17.     while true do
  18.     local message = {rednet.receive()}
  19.     if event == "rednet_message" and msg == "pong" then
  20.      silo[#silo+1] = message[2]
  21.       timerID = os.startTimer(waitDelay)
  22.     elseif event == "timer" and id == timerID then
  23.        return
  24.     end
  25.   end
  26. end
  27.  
  28.  
  29.  
  30.  
  31. local function setTargets()
  32. local count, x, y, z
  33.   while not (type(count) == "number" and type(x) == "number" and type(y) == "number" and type(z) == "number") do
  34. red()
  35. print("      [Target Selection]       ")
  36. red()
  37. term.setBackgroundColor(colors.blue)
  38.  write(" Missile Count: ")
  39.       count = tonumber(read())
  40.       print("Coordinates:")
  41.       write("X: ")
  42.       x = tonumber(read())
  43.       write("Y: ")
  44.       y = tonumber(read())
  45.       write("Z: ")
  46.       z = tonumber(read())
  47. sleep(1)
  48. end
  49. end
  50.  
  51. local function launch(count, x, y, z)
  52.   local msg = {x = x, y = y, z = z}
  53.     print("launching Missiles At " .. x .. ", " .. y .. ", " .. z)
  54.       for i = 1, count do
  55.         rednet.send(silo[curSilo], msg)
  56.           curSilo = (curSilo == #silo) and 1 or (curSilo + 1)
  57.             sleep(5)
  58.       end
  59. end
  60.  
  61. local function fire(ID)
  62.   if silo[ID][3] then
  63. print("Target Selection Complete:")
  64. term.setBackgroundColor(colors.blue)
  65.    print("Launching at: "..x..","..y..","..z)
  66.    print("Launching Missiles -T Minus 10 Seconds.")
  67.    sleep(1)
  68. sleep(1)
  69. write("  Abort [Yes/No]: ")
  70. local abort = read()
  71. if abort == "Yes" then
  72. disarm(#silo)
  73. write("Warheads Disarmed Successfully")
  74. sleep(1)
  75. write("Session Expired, renewing login:")
  76. sleep(2)
  77. os.reboot()
  78. elseif abort == "No" then
  79.     end
  80.     launch(count, x, y, z)
  81.     sleep(10)
  82.     os.reboot()
  83. end
  84.  rednet.send(silo[ID][1])
  85.        
  86.   else print("Silo not armed, can't fire while not armed") end
  87. end
  88.  
  89. local function arm(ID)
  90.   silo[ID][3] = "true"
  91.   rednet.send(silo[ID][1],"arm")
  92. end
  93. `
  94. local function disarm(ID)
  95.   silo[ID][3] = "false"
  96.   rednet.send(silo[ID][1],"disarm")
  97. end
  98.  
  99. findSilos()
  100. printSilos()
Add Comment
Please, Sign In to add comment