View difference between Paste ID: fwTJ4Zgc and EAH3S6CR
SHOW: | | - or go back to the newest paste.
1
local args = {...}
2
local channelList = args 
3
local event, modemSide, senderChannel, replyChannel, message, senderDistance
4
5-
local mon0 = peripheral.wrap("monitor_0")
5+
local mon0 = peripheral.wrap("monitor_2")
6
local modem = peripheral.wrap("left")
7
8-
for k,num in pairs(channelList) do modem.open(tonumber(num)) end
8+
for _,num in pairs(channelList) do modem.open(tonumber(num)) end
9
10
local amount = 0
11
local cap = -1
12
13-
--  print(senderDistance)
13+
local prodTank = 0
14-
  local amount = 0
14+
local tank_ratio = {0, 0, 0, 0}
15-
  local cap = -1
15+
local delta = {0, 0, 0, 0, 0, 0}
16-
  if message.amount then amount = message.amount end
16+
local energy = {0, 0, 0, 0, 0, 0}
17-
  if message.capacity then cap = message.capacity end
17+
--local delay = {1, 1, 1, 1, 1, 1}
18-
  mon0.clear()
18+
19-
  mon0.setCursorPos(1,1)
19+
mon0.clear()
20-
  mon0.write("Fractionator 01: ".. (amount/cap*100) .."%")
20+
mon0.setTextScale(1.5)
21
mon0.setCursorPos(1,1)
22
mon0.write("Gas Turbines 01 - 03")
23
--mon0.setTextScale(1)
24
--mon0.setCursorPos(1,3)
25
--mon0.write("Jet Fuel Production:")
26
mon0.setCursorPos(1,3)
27
mon0.write("Fractionator: ")
28
mon0.setCursorPos(1,4)
29
mon0.write("Tanks  01-04: ")
30
mon0.setCursorPos(1,5)
31
mon0.write("Cells  01-06:")
32
33
local index = 1
34
35
while true do
36
  
37
  event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
38
39
  amount = (type(message) == "table") and (message.amount and message.amount or 0) or 0
40
  cap = (type(message) == "table") and (message.capacity and message.capacity or -1) or -1
41
42
  if senderChannel == tonumber(channelList[1]) then    
43
    mon0.setCursorPos(1,3)
44
    mon0.clearLine()
45
    prodTank = math.floor(amount/cap*10000)/100
46
    mon0.write("Fractionator: ")
47
    if prodTank > 95 then mon0.setTextColor(colors.green)
48
    elseif prodTank > 90 then mon0.setTextColor(colors.orange)
49
    else mon0.setTextColor(colors.red)
50
    end
51
    mon0.write(prodTank.."%")
52
    mon0.setTextColor(colors.white)
53
  else
54
55
    if #channelList > 4 then
56
      index = -1
57
      for i = 2,5 do if senderChannel == tonumber(channelList[i]) then index = i-1; break; end; end
58
      if index > 0 and index < 5 then
59
        mon0.setCursorPos(1,4)
60
        mon0.clearLine()
61
        tank_ratio[index] = math.floor(amount/cap*100)/100
62
        --mon0.write(string.format("Tanks  01-04: %.2f %.2f %.2f %.2f", tank_ratio[1], tank_ratio[2], tank_ratio[3], tank_ratio[4]))
63
        mon0.write("Tanks  01-04: ")
64
        for i = 1,4 do
65
          if tank_ratio[i] < 0.9 then mon0.setTextColor(colors.red)
66
          elseif tank_ratio[i] < 0.98 then mon0.setTextColor(colors.orange)
67
          else mon0.setTextColor(colors.green)
68
          end
69
          mon0.write(string.format("%.2f ", tank_ratio[i]))
70
        end
71
        mon0.setTextColor(colors.white)
72
      end
73
    end
74
75
    if #channelList > 10 then
76
      index = -1
77
      for i = 6,11 do if senderChannel == tonumber(channelList[i]) then index = i-5; break; end; end
78
      if index > 0 and index < 7 then
79
        energy[index] = message.energy
80
        delta[index] = math.floor(message.delta/20/message.delay*100)/100
81
        mon0.setCursorPos(1,6)
82
        mon0.clearLine()
83
        for i = 1,6 do
84
          if energy[i] < 500000 then mon0.setTextColor(colors.orange)
85
          else mon0.setTextColor(colors.green)
86
          end
87
-- get max energy!
88
          mon0.write(string.format("%.2f ", math.floor(energy[i]/500000)/100))
89
        end
90
        mon0.setCursorPos(1,7)
91
        mon0.clearLine()
92
        for i = 1,6 do
93
          if delta[i] < -100 then mon0.setTextColor(colors.red)
94
	  elseif delta[i] < 0 then mon0.setTextColor(colors.orange)
95
          else mon0.setTextColor(colors.green)
96
          end
97
          mon0.write(string.format("%.2f ", delta[i]))
98
        end
99
        mon0.setTextColor(colors.white)
100
      end
101
    end
102
103
  end
104
    
105
end