Advertisement
GauHelldragon

RailControl3 v0.7

Apr 16th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rednet.open("right")
  2.  
  3. local Archi,BW,Gau = colors.purple, colors.orange, colors.yellow
  4. local ResetColor = colors.white
  5. local ID
  6. local ignoreReset = 0
  7.  
  8. function sendNewCode(myColors)
  9.     local value = 0
  10.     if colors.test(myColors,Archi) then value = value + 1 end
  11.     if colors.test(myColors,BW) then value = value + 2 end
  12.     if colors.test(myColors,Gau) then value = value + 4 end
  13.     if ( ID ~= nil ) then
  14.       rednet.send(ID,"rail" .. value)
  15.     else
  16.       rednet.broadcast("rail" .. value)
  17.     end  
  18. end
  19.  
  20. function resetNetwork()
  21.   ignoreReset = 1
  22.   rs.setBundledOutput("back",ResetColor)
  23.   os.sleep(0.5)
  24.   rs.setBundledOutput("back",0)
  25. end
  26.  
  27. while true do
  28.  
  29.   event, ID,message, distance = os.pullEvent()
  30.   if ( event == "rednet_message" ) then
  31.  
  32.       if ( string.sub(message,1,4) == "rail" ) then
  33.          local value = tonumber(string.sub(message,5))
  34.          local newColor = 0
  35.          if ( bit.band(value, 1) ~= 0 ) then newColor = colors.combine(newColor,Archi) end
  36.          if ( bit.band(value, 2) ~= 0 ) then newColor = colors.combine(newColor,BW) end
  37.          if ( bit.band(value, 4) ~= 0 ) then newColor = colors.combine(newColor,Gau) end
  38.          resetNetwork()
  39.          rs.setBundledOutput("back",newColor)
  40.       end
  41.       if ( message == "ping" ) then
  42.         os.sleep(1)
  43.         local myColors = rs.getBundledInput("front")
  44.         sendNewCode(myColors)
  45.       end
  46.   end
  47.   if ( event == "redstone" and  colors.test(rs.getBundledInput("front"),colors.white) ) then
  48.      if ( ignoreReset == 0 ) then
  49.        
  50.         rs.setBundledOutput("back",0)
  51.         os.sleep(5)
  52.         local myColors = rs.getBundledInput("front")
  53.         sendNewCode(myColors)
  54.      else
  55.         ignoreReset = 0
  56.      end
  57.   end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement