Advertisement
GauHelldragon

BWRail v0.1

Apr 16th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. local ArchiCode, GauCode, ShackCode = 3, 2, 4
  2. local ArchiColor, GauColor, ShackColor = colors.red, colors.lightBlue, colors.purple
  3. local ArchiButton, GauButton, ShackButton = colors.orange, colors.yellow, colors.white
  4.  
  5. function getCode()
  6.   rednet.broadcast("ping")
  7.   repeat
  8.      event, ID,message, distance = os.pullEvent("rednet_message")
  9.   until string.sub(message,1,4) == "rail"
  10.   return tonumber(string.sub(message,5))
  11. end
  12.  
  13. function setLight(color)
  14.   rs.setBundledOutput("left",color)
  15. end
  16.  
  17. function setLights(code)
  18.   if ( bit.band(code, 2) ~= 0 ) then
  19.      if ( bit.band(code,1) == 0 ) then
  20.        setLight(GauColor)
  21.      else    
  22.        setLight(ArchiColor)
  23.      end
  24.      return
  25.   end
  26.   if ( bit.band(code, 4) ~= 0 ) then setLight(ShackColor) return end
  27.   setLight(0)
  28. end
  29.  
  30. function sendCode(code)
  31.   rednet.broadcast("rail" .. tostring(code))
  32.   setLights(code)
  33. end
  34.  
  35. rednet.open("top")
  36. local code = getCode()
  37. setLights(code)
  38.  
  39. while true do
  40.   event, id, message, distance = os.pullEvent()
  41.   if ( event == "rednet_message" ) then
  42.     if ( string.sub(message,1,4) == "rail" ) then
  43.       local code = tonumber(string.sub(message,5))
  44.       setLights(code)
  45.     end
  46.   end
  47.   if ( event == "redstone" ) then
  48.     local myColors = rs.getBundledInput("left")
  49.     if ( colors.test(myColors,ArchiButton) ) then sendCode(ArchiCode) end
  50.     if ( colors.test(myColors,GauButton) ) then sendCode(GauCode) end
  51.     if ( colors.test(myColors,ShackButton) ) then sendCode(ShackCode) end
  52.    
  53.   end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement