Savage_Me55iah

Basic monitor client

Oct 18th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Savage_Me55iah--
  2. --http://pastebin.com/ZVduDAB1--
  3.  
  4. tArgs = { ... }
  5. first_run = tArgs[1] or false
  6.  
  7. local variables = {
  8.   ["status"] = true,
  9.   ["timer"] = 2,
  10.   ["save"] = "variables",
  11.   ["side"] = "left",
  12.   ["rednet"] = "y",
  13.   ["rednet_color"] = colors.white,
  14.   ["wireless"] = "right",
  15.   ["reversal"] = "N"
  16. }
  17.  
  18. id2 = os.getComputerID()
  19. label = os.getComputerLabel()
  20.  
  21. rednet.open(variables["wireless"])
  22.  
  23.  
  24. function load()
  25.   print("loading")
  26.  
  27.   fileHandle = fs.open (variables["save"], 'r')
  28.   variables = textutils.unserialize (fileHandle.readAll())
  29.   fileHandle.close()
  30.  
  31.   print("loaded")
  32. end
  33.  
  34. function save()
  35.   print("saving")
  36.  
  37.   fileHandle = fs.open (variables["save"], 'w')
  38.   fileHandle.write (textutils.serialize (variables))
  39.   fileHandle.close()
  40.  
  41.   print("saved")
  42. end
  43.  
  44. function switch()
  45.   if variables["status"] then
  46.     if variables["rednet"] == "y" then
  47. --      c = colors.combine(c, variables["rednet_color"])
  48.       rs.setBundledOutput(variables["side"], variables["rednet_color"])
  49.     else
  50.       redstone.setOutput(variables["side"], true)
  51.     end
  52.   else
  53.     if variables["rednet"] == "y" then
  54. --      c = colors.subtract(c, variables["rednet_color"])
  55.       rs.setBundledOutput(variables["side"], 0)
  56.     else
  57.       redstone.setOutput(variables["side"], false)
  58.     end
  59.   end
  60. end
  61.  
  62. if first_run == false then
  63.   load()
  64. else
  65.   save()
  66. end
  67.  
  68. switch()
  69.  
  70. while true do
  71.   print(label .. " " .. id2)
  72.   event, id, text = os.pullEvent()
  73.   if event == "rednet_message" then
  74.     if variables["reversal"] == "N" then
  75.       if text == "activate" then
  76.         variables["status"] = true
  77.       else
  78.         variables["status"] = false
  79.       end
  80.     else
  81.       if text == "activate" then
  82.         variables["status"] = false
  83.       else
  84.         variables["status"] = true
  85.       end  
  86.     end
  87.   end
  88.   print(variables["status"])
  89.   save()
  90.   switch()
  91.   event = "turd"
  92. end
Advertisement
Add Comment
Please, Sign In to add comment