Advertisement
loepie

Reactor send and receive

Mar 15th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.16 KB | None | 0 0
  1. local vRGarg = { ...}   -- input when starting program to determine server, 1,2,3,4,5,6
  2. os.loadAPI("/rom/apis/rednet")
  3. rednet.open("bottom")
  4. vServer = "rc"..tostring(vRGarg[1])
  5. rednet.host("rcnet",vServer)
  6. TOR = "TOR"..tostring(vRGarg[1])        --Turning On Reactor Number
  7. rchost = "rc"..tostring(vRGarg[1])      --This is ReactorControl number
  8. srg1 = "RG"..tostring(vRGarg[1]).."A"  
  9. srg2 = "RG"..tostring(vRGarg[1]).."B"
  10. messageL = nil      --Set Message to nil
  11. ms = 43             --Set ID MainServer listening
  12. vSideTra = "front"  --Set Transceiver side for turning on the reactor
  13. vSideRes = "back"   --Set Receiver side for confirmation reactor is running
  14. vRG1 = "left"       --Set Receiver side for Reactor Generator xA
  15. vRG2 = "right"      --Set Receiver side for Reactor Generator xB
  16. vRs = nil           --Reactor Status on off
  17. vRm = nil           --Reactor Manual on off
  18.  
  19. function listen()
  20.   local senderIdL, messageL, protocolL = rednet.receive()
  21.   print(senderIdL, messageL, protocolL)
  22.   if protocolL == "rctrl" then
  23.     if messageL == TOR then
  24.       print("toggleR")
  25.       toggleR()
  26.       messageL = nil
  27.     end
  28.   end
  29. end
  30.  
  31. function sendStatus()
  32.     while true do
  33.         if redstone.getInput(vSideRes) == true then
  34. --          print(vServer..": Reactor = on")
  35.             rednet.send(ms,"On",rchost)
  36.         elseif redstone.getInput(vSideRes) == false then
  37. --          print(vServer..": Reactor = Off")
  38.             rednet.send(ms,"Off",rchost)
  39.         end
  40.         sleep(1)
  41.     end
  42. end
  43.  
  44. function sendStatusRG()
  45.     while true do
  46.         if redstone.getInput(vRG1) == true then
  47.             print(vServer..": Reactor Generator :"..srg1.." = Off")
  48.             rednet.send(ms,"Off",srg1)
  49.         elseif redstone.getInput(vRG1) == false then
  50.             print(vServer..": Reactor Generator :"..srg1.." = On")
  51.             rednet.send(ms,"On",srg1)
  52.         end
  53.  
  54.         if redstone.getInput(vRG2) == true then
  55.             print(vServer..": Reactor Generator :"..srg2.." = Off")
  56.             rednet.send(ms,"Off",srg2)
  57.         elseif redstone.getInput(vRG2) == false then
  58.             print(vServer..": Reactor Generator :"..srg2.." = On")
  59.             rednet.send(ms,"On",srg2)
  60.         end
  61.         sleep(1)
  62.     end
  63. end
  64.  
  65. function sendStatusRCm()    -- Send Status Reactor Manual Yes or no
  66.     while true do
  67.         vRs = nil       -- reset var
  68.         vRm = nil       -- reset var
  69.    
  70.         vRs = redstone.getInput(vSideRes)
  71.         if vRs == true then
  72.             vRm = redstone.getOutput(vSideTra)
  73.             if vRm == true then
  74.                 rednet.send(ms,"mOn",rchost)
  75.                 print(vServer..": sending : mOn")
  76.             else
  77.                 rednet.send(ms,"On",rchost)
  78.                 print(vServer..": sending : On")
  79.             end
  80.         elseif vRs == false then
  81.             rednet.send(ms,"Off",rchost)
  82.             print(vServer..": sending : Off")
  83.         elseif vRs == nill then
  84.             rednet.send(ms,"NUL",rchost)
  85.             print(vServer..": sending : NULL")
  86.         end
  87.         sleep(1)
  88.     end
  89. end
  90.  
  91.  
  92. function pulse()
  93.   print(vServer..": pulse aan")
  94.   redstone.setOutput(vSideTra, true)
  95.   sleep(3,5)
  96.   redstone.setOutput(vSideTra, false)
  97.   print(vServer..": pulse uit")
  98. end
  99.  
  100. function toggleR()
  101.     if redstone.getOutput(vSideTra) == true then
  102.         print(vServer..": Reactor = on, turning off")
  103.         redstone.setOutput(vSideTra, false)
  104.     else
  105.         print(vServer..": Reactor = off, turning on")
  106.         redstone.setOutput(vSideTra, true)
  107.     end
  108. end
  109.  
  110. --x=0
  111.  
  112. while true do
  113.     parallel.waitForAny(listen, sendStatusRCm, sendStatusRG)
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement