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