Savage_Me55iah

Savage Client v1.4

Dec 2nd, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.38 KB | None | 0 0
  1. --Script by Savage_Me55iah of CraftAu.com.au--
  2. --Version 1.4--
  3. --Needs corresponding "Savage Monitor v1.4" script--
  4.  
  5. tArgs = { ... }
  6. adjust = tArgs[1] or false
  7.  
  8. local variables = {
  9.   ["status"] = true,
  10.   ["timer"] = 2,
  11.   ["save"] = "variables",
  12.   ["side"] = "left",
  13.   ["rednet"] = true,
  14.   ["rednet_color"] = colors.white,
  15.   ["reversal"] = false
  16. }
  17.  
  18. local sides2 = {["front"] = true, ["back"] = true, ["left"] = true, ["right"] = true, ["top"] = true, ["bottom"] = true}
  19.  
  20. local colors2 = {["white"] = colors.white, ["orange"] = colors.orange, ["magenta"] = colors.magenta, ["lightblue"] = colors.lightBlue, ["yellow"] = colors.yellow, ["lime"] = colors.lime, ["pink"] = colors.pink, ["gray"] = colors.gray, ["lightgray"] = colors.lightGray, ["cyan"] = colors.cyan, ["purple"] = colors.purple, ["blue"] = colors.blue, ["brown"] = colors.brown, ["green"] = colors.green, ["red"] = colors.red, ["black"] = colors.black}
  21.  
  22.  
  23. function find_peripheral(t, e)
  24.   e = e or nil
  25.   sides = {[1] = "front", [2] = "back", [3] = "left", [4] = "right", [5] = "top", [6] = "bottom"}
  26.   peripheral_found = false
  27.   for num=1, 6 do
  28.     type = peripheral.getType(sides[num])
  29.     if type == t then
  30.       if e == "wireless" then
  31.         if peripheral.call(sides[num], "isWireless") then
  32.           peripheral_side = sides[num]
  33.           peripheral_found = true
  34.         end
  35.       elseif e == "remote" then
  36.         if not peripheral.call(sides[num], "isWireless") then
  37.           peripheral_side = sides[num]
  38.           peripheral_found = true
  39.         end
  40.       elseif e == nil then
  41.         peripheral_side = sides[num]
  42.         peripheral_found = true
  43.       end
  44.     end
  45.   end
  46.   if peripheral_found ~= true then
  47.     error("No " .. t .. " attached to the computer", 0)
  48.   end
  49. end
  50.  
  51. id2 = os.getComputerID()
  52. label = os.getComputerLabel() or false
  53. if label == false then
  54.   print("Please Type label here: ")
  55.   label = read()
  56.   label = tostring(label)
  57.   os.setComputerLabel(label)
  58. end
  59.  
  60. find_peripheral("modem", "wireless")
  61. rednet.open(peripheral_side)
  62.  
  63.  
  64.  
  65. function load()
  66.   print("loading")
  67.  
  68.   fileHandle = fs.open (variables["save"], 'r')
  69.   variables = textutils.unserialize (fileHandle.readAll())
  70.   fileHandle.close()
  71.  
  72.   print("loaded")
  73. end
  74.  
  75. function save()
  76.   print("saving")
  77.  
  78.   fileHandle = fs.open (variables["save"], 'w')
  79.   fileHandle.write (textutils.serialize (variables))
  80.   fileHandle.close()
  81.  
  82.   print("saved")
  83. end
  84.  
  85. function switch()
  86.   if variables["status"] then
  87.     if variables["rednet"] then
  88.       rs.setBundledOutput(variables["side"], variables["rednet_color"])
  89.     else
  90.       redstone.setOutput(variables["side"], true)
  91.     end
  92.   else
  93.     if variables["rednet"] then
  94.       rs.setBundledOutput(variables["side"], 0)
  95.     else
  96.       redstone.setOutput(variables["side"], false)
  97.     end
  98.   end
  99. end
  100.  
  101. if adjust ~= false or not fs.exists(variables["save"]) then
  102.   print("SETTINGS: ")
  103.   repeat
  104.     print("Output Side?: front/back/left/right/top/bottom")
  105.     text = read()
  106.     text = tostring(text)
  107.     text = text:lower()
  108.   until sides2[text]
  109.   variables["side"] = text
  110.   repeat
  111.     print("Rednet/Bundled cables?: true/false: ")
  112.     text = read()
  113.     text2 = tostring(text)
  114.   until text2 == "true" or text2 == "false"
  115.   if text2 == "true" then
  116.     variables["rednet"] = true
  117.   else
  118.     variables["rednet"] = false
  119.   end
  120.   if variables["rednet"] then
  121.     repeat
  122.       print("Rednet Color?: ")
  123.       text = read()
  124.       text = tostring(text)
  125.       text = text:lower()
  126.     until colors2[text] ~= nil
  127.     variables["rednet_color"] = colors2[text]
  128.   end
  129.   repeat
  130.     print("Reversal (for machines that turn off with redstone signal): true/false: ")
  131.     text = read()
  132.     text2 = tostring(text)
  133.   until text2 == "true" or text2 == "false"
  134.   if text2 == "true" then
  135.     variables["reversal"] = true
  136.   else
  137.     variables["reversal"] = false
  138.   end
  139.   save()
  140. else
  141.   load()
  142. end
  143.  
  144. switch()
  145.  
  146. while true do
  147.   print(label .. ":" .. id2)
  148.   event, id, text = os.pullEvent()
  149.   if event == "rednet_message" then
  150.     if variables["reversal"] then
  151.       if text == "activate" then
  152.         variables["status"] = false
  153.       else
  154.         variables["status"] = true
  155.       end
  156.     else
  157.       if text == "activate" then
  158.         variables["status"] = true
  159.       else
  160.         variables["status"] = false
  161.       end  
  162.     end
  163.   end
  164.   print(variables["status"])
  165.   save()
  166.   switch()
  167. end
Advertisement
Add Comment
Please, Sign In to add comment