Guest User

x

a guest
Jul 22nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. --Silo Launch PC, [working] [By Andrew2060]
  2.  
  3. --[[Settings]]--
  4. local icbmSide = "back"
  5. local armed = true
  6. local data = {os.getComputerID(), peripheral.call("back", "getMissile"), armed}
  7. local status = textutils.serialise(data)
  8. --set armed to false to disarm silo.
  9.  
  10. --[[Init]]--
  11. local icbm = peripheral.wrap(icbmSide)
  12. local masterID
  13.  
  14. --[[Functions]]--
  15. local function clear()
  16.  term.clear()
  17.   term.setCursorPos(1, 1)
  18.    end
  19.  
  20. rednet.open("top")
  21. --[[Main program]]--
  22. clear()
  23. while true do
  24.   print("Waiting for Launch Confirmation Message")
  25.   id, msg, distance = rednet.receive(masterID)
  26.  
  27.   if (msg == "ping silo") then
  28.     print("  master=", id)
  29.     masterID = id;
  30.     rednet.send(masterID, "pong")
  31.     rednet.send(masterID, data)
  32.   elseif type(msg) == "table" and id == masterID then
  33.     if type(msg.x) == "number" and type(msg.y) == "number" and type(msg.z) == "number" then
  34.       print("  launch to x=" .. msg.x .. ", y=" .. msg.y .. ", z=" .. msg.z)
  35.       icbm.setTarget(msg.x, msg.y, msg.z)
  36.       if (armed) then
  37.         peripheral.call("back","launch")
  38.       end
  39.     else
  40.       print("  invalid table command")
  41.     end
  42.   else
  43.     print("  invalid msg '", msg, "' from '", id, "', distance=", distance)
  44.   end
  45. end
Add Comment
Please, Sign In to add comment