Advertisement
nicx321

OC_MainControl

Nov 18th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.81 KB | None | 0 0
  1. --<>{}[]
  2.  
  3. --Globals
  4. local component = require("component")
  5. local sides = require("sides")
  6. local term = require("term")
  7. local event = require("event")
  8. local clock = 0.25
  9. local net = require("internet")
  10. local Chtene_Itemy = {"Diamond", "Cobblestone", "Yellorium Ingot", "Iron Ingot", "Osmium Ingot", "Ender Pearl", "Redstone", "Oak Wood"}
  11.  
  12. --Setting up switch boards:
  13. local iter = component.list("switch_board")
  14. local it1 = iter()
  15. local it2 = iter()
  16. local switch2 = 0
  17. local switch1 = 0
  18. if it1:sub(1,4) == "b95f" then
  19.   switch1 = component.proxy(it1)
  20.   switch2 = component.proxy(it2)
  21. else
  22.   switch1 = component.proxy(it2)
  23.   switch2 = component.proxy(it1)
  24. end
  25.  
  26. --Setting up light boards:
  27. local iterl = component.list("light_board")
  28. local it1l = iterl()
  29. local it2l = iterl()
  30. local light1 = 0
  31. local light2 = 0
  32. if it1l:sub(1,4) == "837d" then
  33.   light1 = component.proxy(it1l)
  34.   light2 = component.proxy(it2l)
  35. else
  36.   light1 = component.proxy(it2l)
  37.   light2 = component.proxy(it1l)
  38. end
  39.  
  40. --Default Switch
  41. local MP1 = switch2.isActive(4)
  42. local MP2 = switch2.isActive(3)
  43. for i=1, 4 do
  44.   switch1.setActive(i, false)
  45.   switch2.setActive(i, false)
  46. end
  47. switch2.setActive(4, MP1)
  48. switch2.setActive(3, MP2)
  49.  
  50. --Default Switch
  51. for i=1, 4 do
  52.   light1.setActive(i, false)
  53.   light2.setActive(i, false)
  54. end
  55. light1.setColor(1, 0x00FF00)
  56. light1.setActive(1, true)
  57. local BlinkState = false
  58. light1.setColor(2, 0x0000FF)
  59.  
  60. --Debug Card
  61. local debug = component.debug
  62.  
  63. --Reactor
  64. local reactor = component.br_reactor
  65. local function RCK()
  66.   return reactor.getEnergyStored()/100000
  67. end
  68.  
  69. --Redstone
  70. local RS = component.redstone
  71.  
  72. --Glasses
  73. local Glasses = component.openperipheral_bridge
  74.  
  75. --ME-Energie
  76. local ECube = component.tile_thermalexpansion_cell_hardened_name
  77. local function EMK()
  78.   return ECube.getEnergyStored()/ECube.getMaxEnergyStored()*100
  79. end
  80.  
  81. --Alarm
  82. local Alarm = component.os_alarm
  83. Alarm.setRange(150)
  84.  
  85. local function round(num, DecPlac)
  86.   local mult = math.pow(10, DecPlac or 0)
  87.   return math.floor(nummult+0.5)/mult
  88. end
  89.  
  90. --Main
  91. while true do
  92.   local NewLine = ""
  93.   light1.setActive(2, BlinkState)
  94.   BlinkState = not BlinkState
  95.   local CurrentReactor = RCK()
  96.   local CurrentME = EMK()
  97.   local Reactor_State=reactor.getActive()
  98.   print("Reactor: " .. CurrentReactor)
  99.   print("MECube:  " .. CurrentME)
  100.   print("")
  101.   NewLine = NewLine .. "Reactor: " .. CurrentReactor .. "\r\n"
  102.  
  103.   --Domecek lockdown
  104.   if switch2.isActive(4) then
  105.     RS.setOutput(sides.top, 15)
  106.   else
  107.     RS.setOutput(sides.top, 0)
  108.   end
  109.  
  110.   --DownDoor
  111.   if not switch2.isActive(3) then
  112.     RS.setOutput(sides.forward, 15)
  113.   else
  114.     RS.setOutput(sides.forward, 0)
  115.   end
  116.  
  117.   --Player info
  118.   local oldLen = 65
  119.   local Players = debug.getPlayers()
  120.   local Gy=10
  121.   for k,P_Name in pairs(Players) do
  122.     if type(P_Name) == "string" then
  123.       player = debug.getPlayer(P_Name)
  124.       P_World = player.getWorld()
  125.       local info = " "
  126.       if player == nil then
  127.       else
  128.         info = P_Name .. " " .. math.floor(player.getHealth()) .. " " .. P_World.getDimensionName()
  129.       end
  130.       local len = string.len(info)*6
  131.       if oldLen < len then
  132.         oldLen = len
  133.       end
  134.       Gy=Gy+10
  135.     end
  136.   end
  137.   Glasses.addBox(1,1,oldLen,Gy,0xFFFFFF,0.2)
  138.   Gy=10
  139.   for k,P_Name in pairs(Players) do
  140.     if type(P_Name) == "string" then
  141.       player = debug.getPlayer(P_Name)
  142.       P_World = player.getWorld()
  143.       local info = " "
  144.       if player == nil then
  145.       else
  146.         local HP =player.getHealth()
  147.         if HP == nil then
  148.           HP = 0
  149.         end
  150.         info = P_Name .. " " .. math.floor(HP) .. " " .. P_World.getDimensionName()
  151.       end
  152.       NewLine = NewLine .. info.."\r\n"
  153.       print(info)
  154.       Glasses.addText(1,Gy,info,0)
  155.       Gy=Gy+10
  156.     end
  157.   end
  158.  
  159.  
  160.   --Glasses
  161.  
  162.   Glasses.addText(1,1,"R: "..CurrentReactor, 0)
  163.   Glasses.sync()
  164.  
  165.  
  166.   --Reactor Alarm check
  167.   if ((CurrentReactor < 10) and not Reactor_State) or CurrentME < 95 then
  168.     Alarm.activate()
  169.   else
  170.     Alarm.deactivate()
  171.   end
  172.  
  173.   if not Reactor_State then
  174.     reactor.setActive(true)
  175.   end
  176.  
  177.   --End
  178.   if switch1.isActive(1) then
  179.     switch1.setActive(1, false)
  180.     light1.setColor(1, 0xFF0000)
  181.     break
  182.   end
  183.  
  184.   --ME info
  185.   ME = component.me_controller
  186.   NewLine = NewLine ..  "Items: \r\n\r\n"
  187.   for k, v in pairs(ME.getItemsInNetwork()) do
  188.     if type(v) == "table" then
  189.       for _, item in pairs(Chtene_Itemy) do
  190.         if item == v.label then
  191.           NewLine = NewLine ..  v.label .. "\t" .. v.size .. "\r\n"
  192.         end
  193.       end
  194.     end
  195.   end
  196.  
  197.   -- TCP send
  198.  
  199.   local con = net.open("XXXX", 00000)
  200.  
  201.   if con then
  202.     print(NewLine)
  203.     con:write(NewLine)
  204.     con:flush()
  205.   else
  206.     print("No Con")
  207.   end
  208.   os.sleep(clock)
  209.   term.clear()
  210.   Glasses.clear()
  211. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement