burnin_aura

Test

Jul 22nd, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. --# slave/silo
  2.  
  3. --# User config section
  4. local hostName = "Andrew2060_Silo_System" --# must match master variable
  5. local protocolName = "Andrew2060_Silo" --# must match master variable
  6.  
  7.  
  8. local arm == "true"
  9.  
  10. --# End of user config section
  11.  
  12.  
  13.  
  14.  
  15.  
  16. local silo = peripheral.wrap("back")
  17. if not silo then error("can't find silo") end
  18.  
  19. --# peripheral dummy functions (because I don't have the mod)
  20.  
  21. local function silo.getMissileType()
  22.   peripheral.call("back", "getMissile")
  23. end
  24.  
  25. local function silo.getArmStatus()
  26.   local ArmStatus = arm
  27. end
  28.  
  29. local function silo.setArmState(newState)
  30.   local ArmStatus = newState
  31. end
  32.  
  33. local function silo.fire()
  34.   peripheral.call("back", "fire")
  35. end
  36.  
  37. --# end of peripheral dummy functions
  38.  
  39. local masterServer = rednet.lookup(protocolName, hostName)
  40.  
  41. if not masterServer then error("can't find master server") end
  42.  
  43. local function getSiloState()
  44.   return {os.getComputerID, silo.getMissileType(), tostring(silo.getMissileArmStatus())}
  45. end
  46.  
  47. rednet.send(masterServer, getSiloState(), protocolName) --# send first message so that the master server knows about this silo
  48.  
  49.  
  50.  
  51. while true do
  52.   local message = {rednet.recive()}
  53.   if message[3] == protocolName then
  54.         --# message is expected protocol, continue
  55.         if message[1] == masterServer then
  56.           --# the message if from our master server, continue
  57.           if message[2] == "arm" then silo.setArmState(true)
  58.           elseif message[2] == "disarm" then silo.setArmState(false)
  59.           elseif message[2] == "fire" then silo.fire()
  60.           else --# bad message, ignore
  61.           end
  62.         end
  63.   end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment