Savage_Me55iah

client v1.6 beta

May 12th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.79 KB | None | 0 0
  1. --Script by Savage_Me55iah of CraftAu.com.au--
  2. --Version 1.6--
  3. --Needs corresponding "Savage Monitor v1.6" 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.   ["nuke"] = false,
  17.   ["time_on"]  = 80,
  18.   ["time_off"] = 110
  19. }
  20.  
  21. local sides2 = {["front"] = true, ["back"] = true, ["left"] = true, ["right"] = true, ["top"] = true, ["bottom"] = true}
  22.  
  23. 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}
  24.  
  25. color_from_decimal = {[1] = "white", [2] = "orange", [4] = "magenta", [8] = "lightBlue", [16] = "yellow", [32] = "lime", [64] = "pink", [128] = "gray", [256] = "lightGray", [512] = "cyan", [1024] = "purple",[2048] = "blue", [4096] = "brown", [8192] = "green", [16384] = "red", [32768] = "black"}
  26.  
  27.  
  28. function find_peripheral(t, e)
  29.   e = e or nil
  30.   sides = {[1] = "front", [2] = "back", [3] = "left", [4] = "right", [5] = "top", [6] = "bottom"}
  31.   peripheral_found = false
  32.   for num=1, 6 do
  33.     type = peripheral.getType(sides[num])
  34.     if type == t then
  35.       if e == "wireless" then
  36.         if peripheral.call(sides[num], "isWireless") then
  37. return sides[num]
  38. end
  39.       elseif e == "remote" then
  40.         if not peripheral.call(sides[num], "isWireless") then return sides[num] end
  41.       elseif e == nil then
  42.         return sides[num]
  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.   os.setComputerLabel(tostring(read()))
  56. end
  57.  
  58. rednet.open(find_peripheral("modem", "wireless"))
  59.  
  60. function load()
  61.   fileHandle = fs.open (variables["save"], 'r')
  62.   variables = textutils.unserialize (fileHandle.readAll())
  63.   fileHandle.close()
  64. end
  65.  
  66. function save()
  67.   fileHandle = fs.open (variables["save"], 'w')
  68.   fileHandle.write (textutils.serialize (variables))
  69.   fileHandle.close()
  70. end
  71.  
  72. function switch(command)
  73.   if command then
  74.     if variables["rednet"] then
  75.       rs.setBundledOutput(variables["side"], variables["rednet_color"])
  76.     else
  77.       redstone.setOutput(variables["side"], true)
  78.     end
  79.   else
  80.     if variables["rednet"] then
  81.       rs.setBundledOutput(variables["side"], 0)
  82.     else
  83.       redstone.setOutput(variables["side"], false)
  84.     end
  85.   end
  86. end
  87.  
  88. function nuke(command)
  89.   switch(false)
  90.   term_draw(false)
  91.   if command then
  92.     os.startTimer(variables["time_off"])
  93.     while not event == "timer" or not event == "rednet_message" do os.pullEvent() end
  94.     if event == "rednet_message" then break end
  95.     switch(true)
  96.     os.startTimer(variables["time_on"])
  97.     term_draw(true)
  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 = tostring(read())
  106.     text = text:lower()
  107.   until sides2[text]
  108.   variables["side"] = text
  109.   repeat
  110.     print("Rednet/Bundled cables?: true/false: ")
  111.     text2 = tostring(read())
  112.     text2 = text2:lower()
  113.   until text2 == "true" or text2 == "false"
  114.   if text2 == "true" then
  115. variables["rednet"] = true else
  116. variables["rednet"] = false
  117. end
  118.   if variables["rednet"] then
  119.     repeat
  120.       print("Rednet Color?: ")
  121.       text = tostring(read())
  122.       text = text:lower()
  123.     until colors2[text] ~= nil
  124.     variables["rednet_color"] = colors2[text]
  125.   end
  126.   repeat
  127.     print("Reversal (for machines that turn off with redstone signal): true/false: ")
  128.     text2 = tostring(read())
  129.     text2 = text2:lower()
  130.   until text2 == "true" or text2 == "false"
  131.   if text2 == "true" then
  132. variables["reversal"] = true else
  133. variables["reversal"] = false end
  134.   repeat
  135.     print("Alternating redstone signal for IC2 reactors?: true/false: ")
  136.     text2 = tostring(read())
  137.     text2 = text2:lower()
  138.   until text2 == "true" or text2 == "false"
  139.   if text2 == "true" then
  140.     variables["nuke"] = true
  141.     repeat
  142.       print("How long turned on?: seconds: ")
  143.       time = read()
  144.     until type(time) == "number"
  145.     variables["time_on"] = time
  146.     repeat
  147.       print("How long turned off? (cooldown): seconds: ")
  148.       time = read()
  149.     until type(time) == "number"
  150.     variables["time_off"] = time
  151.   else
  152.     variables["nuke"] = false
  153.   end
  154.   save()
  155. else
  156.   load()
  157. end
  158.  
  159. function change_colors(command, color_1, color_2)
  160.   command.setTextColor(color_1 or colors.white)
  161.   command.setBackgroundColor(color_2 or colors.black)
  162. end
  163.  
  164. function term_write(text, command, xpos, ypos)
  165.   term.setCursorPos(xpos, ypos)
  166.   if term.iscolor() then
  167.     if command then change_colors(term, colors.black, colors.green) else change_colors(term, colors.black, colors.red) end
  168.   else
  169.     if command then change_colors(term, colors.black, colors.white) else change_colors(term) end
  170.   end
  171.   term.write(text)
  172.   change_colors(term)
  173. end
  174.  
  175. function term_draw(command)  
  176.   term.clear()
  177.   term_write(" " .. label .. ":" .. id2 .. " ", true, 2, 2)
  178.   term_write(" Status ", variables["status"], 2, 4)
  179.   term_write(" Nuclear Reactor ", variables["nuke"], 2, 6)
  180.   if not variables["nuke"] then
  181.     term_write(" Cooldown ", false, 2, 8)
  182.     term_write(" Reactor Active ", false, 2, 10)
  183.   else
  184.     if command then
  185.       term_write(" Cooldown: " .. variables['time_off"] .. " ", false, 2, 8)
  186.      term_write(" Reactor Active: " .. variables["time_on"] .. " ", true, 2, 10)
  187.    else
  188.      term_write(" Cooldown: " .. variables['time_off"] .. " ", true, 2, 8)
  189.      term_write(" Reactor Active: " .. variables["time_on"] .. " ", false, 2, 10)
  190.    end
  191.  end
  192.  term_write(" Rednet ", variables["rednet"], 2, 12)
  193.  term_write(" Reverse ", variables["reversal"], 2, 14)
  194. end
  195.  
  196. os.startTimer(0.1)
  197. term_draw(false)
  198.  
  199. while true do
  200.  
  201.  event, id, text = os.pullEvent()
  202.  if event == "rednet_message" then
  203.    if variables["reversal"] then
  204.      if text == "activate" then
  205.        variables["status"] = false
  206.      else
  207.        variables["status"] = true
  208.      end
  209.    else
  210.      if text == "activate" then
  211.        variables["status"] = true
  212.      else
  213.        variables["status"] = false
  214.      end  
  215.    end
  216.    event = nil
  217.  end
  218.  save()
  219.  if not variables["nuke"] then
  220.    switch(variables["status"])
  221.    term_draw()
  222.  else
  223.     nuke(variables["status"])
  224.  end
  225. end
Advertisement
Add Comment
Please, Sign In to add comment