Advertisement
danya201272

[OpenComputers]LSC Controller and Auto-Nuke GTCE from redstone

Oct 29th, 2022 (edited)
1,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.26 KB | Source Code | 0 0
  1. -- Require:
  2. -- Monitor and GPU tear 3 and PC
  3. -- Adapter, Redstone controller or redstone card
  4. -- I update this script for auto-enable reactor from redstone signal on 50% lapatron storage
  5. -- Owner scripts: 4GNAME
  6.  
  7. unicode = require("unicode")
  8. comp = require("component")
  9. colors = require("colors")
  10. side = require("sides")
  11. screen = require("term")
  12. computer = require("computer")
  13. event = require("event")
  14. graphics = require("graphics")
  15. fs = require("filesystem")
  16. TC, RO, RN, RD, TPS = 2, 0, 0, 0
  17.  
  18. GPU1 = comp.gpu
  19. lsc = comp.impact_lsc
  20. rs = comp.redstone
  21. procent = 55 -- В процентах емкость лапатрона, когда начнется заряд реактора
  22. fuls = 100 -- В процентах емкость лапатрона, яр заряд остановка
  23.  
  24. screenWidth = 160
  25. screenHeight = 40
  26.  
  27. GPU1.setResolution(screenWidth, screenHeight)
  28.  
  29. function times()
  30.     f = io.open("/tmp/TF", "w")
  31.     f:write("test")
  32.     f:close()
  33.     return(fs.lastModified("/tmp/TF"))
  34. end
  35.  
  36. function spam()
  37.     RO = times()
  38.     os.sleep(TC)
  39.     RN = times()
  40.     RD = RN - RO
  41.     TPS = 20000 * TC / RD
  42.     TPS = string.sub(TPS, 1, 5)
  43.     nTPS = tonumber(TPS)
  44.     GPU1.set(154, 8, "     ")
  45.     if nTPS <= 10 then
  46.         GPU1.setForeground(0xcc4c4c)
  47.     elseif nTPS <= 15 then
  48.         GPU1.setForeground(0xf2b233)
  49.     elseif nTPS > 15 then
  50.         GPU1.setForeground(0x7fcc19)
  51.     end
  52.     GPU1.set(154, 8, TPS)
  53. end
  54.  
  55. function rectangleAround(GPU, x, y, w, h, b, color)
  56.     if y % 2 == 0 then
  57.         error("Pixel position must be odd on y axis")
  58.     end
  59.     graphics.rectangle(GPU, x, y, w - b, b, color)
  60.     graphics.rectangle(GPU, x + w - b, y, b, h - b + 1, color)
  61.     graphics.rectangle(GPU, x + b - 1, y + h - b, w - b + 1, b, color)
  62.     graphics.rectangle(GPU, x, y + b - 1, b, h - b + 1, color)
  63. end
  64.  
  65. function splitNumber(number)
  66.     number = math.floor(number)
  67.     local formattedNumber = {}
  68.     local string = tostring(math.abs(number))
  69.     local sign = number / math.abs(number)
  70.     for i = 1, #string do
  71.         n = string:sub(i, i)
  72.         formattedNumber[i] = n
  73.         if ((#string - i) % 3 == 0) and (#string - i > 0) then
  74.             formattedNumber[i] = formattedNumber[i] .. ","
  75.         end
  76.     end
  77.     if (sign < 0) then
  78.         table.insert(formattedNumber, 1, "-")
  79.     end
  80.     return table.concat(formattedNumber, "")
  81. end
  82.  
  83. function time(number)
  84.     local formattedTime = {}
  85.     formattedTime[1] = math.floor(number / 3600); formattedTime[2] = " H, "
  86.     formattedTime[3] = math.floor((number - formattedTime[1] * 3600) / 60); formattedTime[4] = " M, "
  87.     formattedTime[5] = number % 60; formattedTime[6] = " S"
  88.     return table.concat(formattedTime, "")
  89. end
  90.  
  91. function drawCharge()
  92.     local chargeFirst = lsc.getChargePercent()
  93.     local stored, capacity, input, output = lsc.getStoredLSC()
  94.     local pX = 20
  95.     local pY = 53
  96.     local pW = screenWidth - 2 * pX
  97.     local pH = 8
  98.     local charge = (pW - 2) * (lsc.getChargePercent() / 100)
  99.     local capacityEU = "CAPACITY: " .. splitNumber(capacity) .. " EU"
  100.     local storedEU = "STORED: " .. splitNumber(stored) .. " EU"
  101.     local inputEU = "IN: " .. splitNumber(input) .. " EU/T"
  102.     local outputEU = "OUT: " .. splitNumber(output) .. " EU/T "
  103.     local chargePercent = "       CHARGE: " .. math.floor(chargeFirst) .. " %"
  104.     local differenceIO = input - output
  105.  
  106.     rectangleAround(GPU1, pX, pY, pW, pH, 2, 0x131e27)
  107.  
  108.     graphics.rectangle(GPU1, pX + 2, pY + 2, charge - 2, 4, 0x7ec7ff)
  109.     if chargeFirst > 0 and chargeFirst < 100 then
  110.         graphics.rectangle(GPU1, pX + charge + 1, pY + 2, pW - 2 - charge, 4, 0x294052)
  111.     else
  112.         if chargeFirst <= 0 then
  113.             graphics.rectangle(GPU1, pX + 2, pY + 2, pW - 4, 4, 0x294052)
  114.         end
  115.     end
  116.     local diftext = "              " .. "COST: " .. splitNumber(math.abs(differenceIO)) .. " EU/T"
  117.     if differenceIO < 0 then
  118.         graphics.text(GPU1, pX + pW - #diftext, pY + pH, 0xff0000, diftext)
  119.     else
  120.         graphics.text(GPU1, pX + pW - #diftext, pY + pH, 0x33ff00, diftext)
  121.     end
  122.     graphics.text(GPU1, screenWidth-17, 3, 0x858585,"OFF - CTRL+C")
  123.     graphics.text(GPU1, screenWidth-10, 15, 0x00FF00,"TPS")
  124.     graphics.text(GPU1, pX + pW - #chargePercent, pY - 2, 0x7ec7ff, chargePercent)
  125.     graphics.text(GPU1, pX, pY - 2, 0x7ec7ff, capacityEU .. "              ")
  126.     graphics.text(GPU1, pX, pY + pH, 0x7ec7ff, storedEU .. "              ")
  127.     graphics.text(GPU1, pX, pY + pH + 4, 0x33ff00, inputEU .. "              ")
  128.     graphics.text(GPU1, pX, pY + pH + 6, 0xff0000, outputEU .. "              ")
  129.     if math.floor(chargeFirst) <= procent then
  130.     for b = 0, 5 do
  131.     rs.setOutput(b, 255)
  132.     end
  133.     computer.beep(1000, 0.1)
  134.     graphics.text(GPU1, screenWidth-12, 11, 0x00FF00,"REACTOR:ON_")
  135.     end
  136.  
  137.     if differenceIO > 0 then
  138.         fillTime = math.floor((capacity - stored) / (differenceIO * 20))
  139.         fillTimeString = "                        FULL: " .. time(math.abs(fillTime))
  140.         graphics.text(GPU1, pX + pW - #fillTimeString, pY + pH + 2, 0x7ec7ff, fillTimeString .. "              ")
  141.     else if differenceIO == 0 then
  142.         if stored >= (capacity * fuls / 100) then
  143.             fillTimeString = "                       CHARGE OK"
  144.             for i = 0, 5 do
  145.             rs.setOutput(i, 0)
  146.             end
  147.             graphics.text(GPU1, screenWidth-12, 11, 0xFF0000,"REACTOR:OFF")
  148.         else if stored <= (capacity * 20 / 100) then
  149.             fillTimeString = "                         NEED HELP"
  150.             computer.beep(1000, 1.0)
  151.         end
  152.             fillTimeString = "                        NO CHARGE"
  153.         end
  154.         graphics.text(GPU1, pX + pW - #fillTimeString, pY + pH + 2, 0x7ec7ff, fillTimeString)
  155.     else
  156.         fillTime = math.floor((stored) / (differenceIO * 20))
  157.         fillTimeString = "                        EMPTY: " .. time(math.abs(fillTime))
  158.         graphics.text(GPU1, pX + pW - #fillTimeString, pY + pH + 2, 0x7ec7ff, fillTimeString .. "              ")
  159.     end
  160.     end
  161. end
  162.  
  163. screen.clear()
  164.  
  165. while true do
  166.     drawCharge()
  167.     graphics.update()
  168.     spam()
  169.     os.sleep(.1)
  170.     if event.pull(.5, "interrupted") then
  171.         screen.clear()
  172.         print("soft interrupt, closing")
  173.         break
  174.     end
  175. end
Tags: GTCE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement