Advertisement
Andronio12

HH

Jun 3rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.03 KB | None | 0 0
  1. com = require("component")
  2. ev = require("event")
  3. sides = require("sides")
  4. str = require("string")
  5. e = {
  6.  com.proxy("c3b899b6-07a2-4a34-a820-88fd23aeefa4"), -- 1 right
  7.  com.proxy("104a0488-280e-40e4-b261-d7ae0197d926"), -- 2 front
  8.  com.proxy("88c30270-3298-4e0b-abd3-b6ce9d4691a1"), -- 3 back
  9.  com.proxy("f1808099-8678-4a2d-9f67-1c151a39f861") -- 4 left
  10. }
  11. e_sd = {sides.right,sides.front,sides.back,sides.left}
  12. bb = com.gt_machine --com.gt_batterybuffer
  13. op = com.openperipheral_bridge
  14. cb = com.chat_box
  15. red = com.redstone
  16. gpu = com.gpu
  17. state = "auto"
  18. hpe = {1,1,1,1}
  19. recst = {"","","",""}
  20. cb.setName("Горячий Мексиканец")
  21. works = false
  22.  
  23. function setEB(state)
  24.  for i=1,4,1 do
  25.   if hpe[i] < 80 then red.setOutput(e_sd[i],state) end
  26.  end
  27. end
  28.  
  29. function getEnrg()
  30.  now,total = 0,0
  31.  for i=1,16,1 do
  32.   if bb.getBatteryCharge(i) ~= nil then
  33.    now = now + bb.getBatteryCharge(i)
  34.    total = total + bb.getMaxBatteryCharge(i)
  35.   end
  36.  end
  37.  total = total + bb.getEUMaxStored()
  38.  now = now + bb.getStoredEU()
  39.  return now,total
  40. end
  41.  
  42. function glcc(_,_,nick,_,command)
  43.  print("Got command. Nick: "..nick.."; Command: $$"..command)
  44.  if nick == "Andronio" or nick == "Orlin" then
  45.   if command:sub(1,3) == "say" then cb.say("* "..command:sub(5)) -- Просто сказать
  46.   elseif command:sub(1,7) == "setmode" then                -- Управление режимами реакторного блока
  47.    if command:sub(9) == "auto" or command:sub(9) == "forceon" or command:sub(9) == "forceoff" then state = command:sub(9) cb.say("Mode has been set to '"..state.."'!")
  48.    else                                                                                                                   cb.say("Incorrect value: ".."'"..command:sub(9).."'!") end
  49.   elseif command == "help" then
  50.    cb.say("Help:\n$$setmode auto/forceon/forceoff - Sets reactor control mode.\n$$say *text* - Just says your text.\n$$stop - Closes this program(Reboots PC).\n$$status - Says everything about system.\n(C) Andronio")
  51.   elseif command == "stop" then cb.say("Bye-bye! <3") op.clear() op.sync() os.execute("reboot")
  52.   elseif command == "status" then
  53.    ct = "Status:\nEnergy Buffers:\n #1: "..enstr.."\n"
  54.    --for i=1,16 do if bb.getBatteryCharge(i) ~= nil then ct = ct.."  Crystal #"..i..": "..bb.getBatteryCharge(i).."/"..bb.getMaxBatteryCharge(i).." EU\n" end end
  55.    --ct = ct.."  Internal Buffer: "..bb.getStoredEU().."/"..bb.getEUMaxStored().." EU\n"
  56.    ct = ct.."Generators:\n Energy Block #1("..stt.."):\n"
  57.    for i=1,4 do
  58.     ct = ct.."  Reactor #"..i..": "..e[i].getReactorEUOutput().." EU/t   Heat: "..hpe[i].."%   Status: "
  59.     if e[i].isActive() then ct = ct.."On\n"
  60.     else                    ct = ct.."Off\n" end
  61.    end
  62.    ct = ct.."'SOSI PISOS' - Palindrom"
  63.    cb.say(ct)
  64.   else cb.say("Incorrect command!") end
  65.  else cb.say("You are not allowed to use that!") end
  66. end
  67.  
  68. setEB(0)
  69. cc_eve = ev.listen("glasses_chat_command",glcc)
  70.  
  71. while true do
  72.  cure,maxe = bb.getEUStored(),bb.getEUMaxStored()--getEnrg()
  73.  enstr = cure.."/"..maxe.." EU"
  74.  ain,aon = bb.getAverageElectricInput(),bb.getAverageElectricOutput()
  75.  if math.floor(cure/maxe*100) < 75 and state == "auto" and not works then
  76.   cb.say("Energy level is below 75%. Turning on reactors...")
  77.   setEB(255)
  78.   works = true
  79.  elseif math.floor(cure/maxe*100) > 95 and state == "auto" and works then
  80.   cb.say("Energy level is above 95%. Turning off reactors...")
  81.   setEB(0)
  82.   works = false
  83.  end
  84.  if state == "forceon"  then setEB(255) works = true end
  85.  if state == "forceoff" then setEB(0) works = false end
  86.  for i=1,4,1 do
  87.   hpe[i] = math.floor(e[i].getHeat()/e[i].getMaxHeat()*100)
  88.   if e[i].isActive() then recst[i] = "§2On"
  89.   else recst[i] = "§4Off" end
  90.   if hpe[i] >= 80 then
  91.    red.setOutput(e_sd[i],0) end
  92.  end
  93.  if state == "auto" then         stt = "§9Auto"
  94.  elseif state == "forceon" then  stt = "§2Force On"
  95.  elseif state == "forceoff" then stt = "§4Force Off" end
  96.  
  97.  op.clear()
  98.  op.addText(1,12,"Energy Buffers")
  99.  op.addIcon(1,22,"gregtech:gt.blockmachines",812) --op.addIcon(1,22,"gregtech:gt.blockmachines",165)
  100.  op.addText(3,27,math.floor(cure/maxe*100).." ",0x0000FF)
  101.  op.addText(19,23,enstr)--.."   §2In: "..ain.." EU/t   §cOut: "..aon.." EU/t")
  102.  op.addBox(19,33,100,3,0xFF0000)
  103.  op.addBox(19,33,math.floor(cure/maxe*100+0.5),3,0x00FF00)
  104.  op.addText(1,44,"Reactors")
  105.  for i=1,4,1 do
  106.   op.addIcon(1,55+17*(i-1),"IC2:blockReactorChamber")
  107.   if e[i].isActive() and e[i].getReactorEUOutput() == 0 then
  108.    op.addBox(4,55+17*(i-1),10,3,0x0000FF)
  109.   end
  110.   if hpe[i] >= 80 then
  111.    op.addBox(4,68+17*(i-1),10,3,0xFF0000)
  112.   end
  113.   op.addText(19,56+17*(i-1),"Output: "..math.floor(e[i].getReactorEUOutput()).." EU/t, Heat: "..hpe[i].."%  "..recst[i])
  114.   op.addBox(19,66+17*(i-1),100,3,0xFF0000)
  115.   op.addBox(19,66+17*(i-1),hpe[i],3,0x00FF00)
  116.  end
  117.  op.addText(1,124,"Total Output: "..math.floor(e[1].getReactorEUOutput()+e[2].getReactorEUOutput()+e[3].getReactorEUOutput()+e[4].getReactorEUOutput()).." EU/t")
  118.  op.addText(1,135,"Work Mode: "..stt)
  119.  op.sync()
  120.  os.sleep(0.01)
  121. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement