Advertisement
burnin_aura

[CC] [ICBM] [SILOPC] V2

Jul 22nd, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. local masterID
  2. local armed = false
  3.  
  4. local function getMissileType()
  5.   peripheral.call("back", "getMissile")
  6. end
  7.  
  8. local function getArmStatus()
  9.   local armed
  10. end
  11.  
  12. local function setArmState(newState)
  13.   --# peripheral stuff
  14. end
  15.  
  16. local function fire()
  17.   id, msg, distance = rednet.receive(masterID)
  18.   if (msg == "ping") then
  19.     print("  master=", id)
  20.     masterID = id;
  21.     rednet.send(masterID, "pong")
  22.  
  23.   elseif type(msg) == "table" and id == masterID then
  24.     if type(msg.x) == "number" and type(msg.y) == "number" and type(msg.z) == "number" then
  25.       print("  launching to x=" .. msg.x .. ", y=" .. msg.y .. ", z=" .. msg.z)
  26.       icbm.setTarget(msg.x, msg.y, msg.z)
  27.       if (armed) then
  28.         peripheral.call("back","launch")
  29.       end
  30.     else
  31.       print("  invalid table command")
  32.     end
  33.   else
  34.     print("  invalid message", msg, " from ", id, ", distance=", distance)
  35.   end
  36. end
  37.  
  38. local function getSiloState()
  39.   return {os.getComputerID, peripheral.call("back", "getMissile")}
  40. end
  41.  
  42. rednet.send(masterID, getSiloState())
  43.  
  44. while true do
  45.   local message = {rednet.receive()}
  46.         if message[1] == masterID then
  47.           if message[2] == "arm" then setArmState(true)
  48.           elseif message[2] == "disarm" then setArmState(false)
  49.           elseif message[2] == "fire" then fire()
  50.           else --# bad message, ignore
  51.           end
  52.         end
  53.   end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement