Anonomit

broadcast

Aug 11th, 2012
800
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     --Created by Anonomit
  2.  
  3. rednet.open( "right" )
  4. rednet.open( "left" )
  5. rednet.open( "back" )
  6. rednet.open( "top" )
  7. rednet.open( "bottom" )
  8.  
  9. if fs.exists( "broadcastSettings" ) then
  10.     file = io.open( "broadcastSettings", "r" )
  11.     line = tonumber( file:read() )
  12.     file:close()
  13. else --fs.fileExists( "broadcastSettings" )
  14.     shell.run( "clear" )
  15.     print( "BROADCAST CONSOLE" )
  16.     print( "" )
  17.     write( "Amount of loggers: " )
  18.     line = tonumber( read() )
  19.     while true do
  20.         if line == nil or line < 0 then
  21.             print( "Invalid number" )
  22.             sleep( 0.5 )
  23.             shell.run( "clear" )
  24.             print( "BROADCAST CONSOLE" )
  25.             print( "" )
  26.             write( "Amount of loggers: " )
  27.             line = tonumber( read() )
  28.         else --line == nil or line < 0
  29.             break --while true
  30.         end --if line == nil or line <= 0
  31.     end --while true
  32.    
  33.     file = io.open( "broadcastSettings", "w" )
  34.     file:write( line )
  35.     file:close()
  36.    
  37. end --if fs.exists( "broadcastSettings" )
  38.  
  39.  
  40. shell.run( "clear" )
  41. print( "BROADCAST CONSOLE" )
  42.  
  43. activeLoggers = line
  44. done = 1000
  45. los = 0
  46. oos = 0
  47.  
  48. local function rednetBC( message )
  49.     rednet.broadcast( message )
  50.     print( "broadcasted '", message, "'" )
  51. end --local function rednetBC( message )
  52.  
  53. while true do
  54.    
  55.     event, param1, param2, param3 = os.pullEvent()
  56.     if event == "rednet_message" and param2 == "log" then
  57.         print( "received '", param2, "'" )
  58.         if done >= activeLoggers then
  59.             done = 0
  60.             los = 0
  61.             oos = 0
  62.             rednetBC( "startLogging" )
  63.         else --done >= activeLoggers
  64.             rednetBC( "wait" )
  65.             done = tostring( done )
  66.             rednetBC( done )
  67.             done = tonumber( done )
  68.             los = tostring( los )
  69.             rednetBC( los )
  70.             los = tonumber( los )
  71.             oos = tostring( oos )
  72.             rednetBC ( oos )
  73.             oos = tonumber( oos )
  74.         end --if done >= activeLoggers
  75.     elseif event == "rednet_message" and param2 == "startLogging" then
  76.         print( "received '", param2, "'" )
  77.         done = 0
  78.         los = 0
  79.         oos = 0
  80.     elseif event == "rednet_message" and param2 == "doneLogging" then
  81.         print( "received '", param2, "'" )
  82.         done = done + 1
  83.     elseif event == "rednet_message" and param2 == "helpLogging" then
  84.         print( "received '", param2, "'" )
  85.         los = los + 1
  86.     elseif event == "rednet_message" and param2 == "noLogging" then
  87.         print( "received '", param2, "'" )
  88.         los = los - 1
  89.         oos = oos + 1
  90.     elseif event == "rednet_message" then
  91.         print( "Ignoring '", param2, "' from '", param1, "' from a distance of ", param3, " away" )
  92.     end --if event == "rednet_message" and param2 == "log"
  93. end --while true
RAW Paste Data