Advertisement
GauHelldragon

RailGau v0.5

Apr 16th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. local ArchiCode, BWCode, ShackCode = 1, 0, 6
  2. local ArchiColor, BWColor, ShackColor = colors.orange, colors.cyan, colors.red
  3. local ArchiButton, BWButton, ShackButton = color.yellow, colors.lightBlue, colors.purple
  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, 1) ~= 0 ) then setLight(ArchiColor) return end
  19.   if ( bit.band(code, 2) == 0 ) then setLight(BWColor) return end
  20.   if ( bit.band(code, 4) ~= 0 ) then setLight(ShackColor) return end
  21.  
  22.   setLight(0)
  23.  
  24. end
  25.  
  26. function sendCode(code)
  27.   rednet.broadcast("rail" .. tostring(code))
  28.   setLights(code)
  29. end
  30.  
  31. rednet.open("top")
  32. local code = getCode()
  33. setLights(code)
  34.  
  35. while true do
  36.   event, id, message, distance = os.pullEvent()
  37.   if ( event == "rednet_message" ) then
  38.     if ( string.sub(message,1,4) == "rail" ) then
  39.       local code = tonumber(string.sub(message,5))
  40.       setLights(code)
  41.     end
  42.   end
  43.   if ( event == "redstone" ) then
  44.     local myColors = rs.getBundledInput("left")
  45.     if ( colors.test(myColors,ArchiButton) ) then sendCode(ArchiCode) end
  46.     if ( colors.test(myColors,BWButton) ) then sendCode(BWCode) end
  47.     if ( colors.test(myColors,ShackButton) ) then sendCode(ShackCode) end
  48.    
  49.   end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement