Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fuelAlert = {}
- local z = textutils.serialize
- local Reactors, Sides
- --local monitor = peripheral.wrap("left")
- --monitor.setTextScale(1)
- --[[mon = getPeripheral("monitor")
- --print(z(monitor))
- local term_back = term
- if mon then
- term = mon
- end]]
- local monx, mony = term.getSize()
- -- Helper API for MiscPeripherals integrated programs
- -- Gets all peripherals of the specified type
- function getPeripherals(typ, amount)
- peripherals = {}
- sides = {}
- if amount == nil then amount = 1000000 end
- count = 0
- for _, side in pairs(rs.getSides()) do
- peripheralType = peripheral.getType(side)
- if peripheralType == typ then
- -- Directly attached
- table.insert(peripherals, peripheral.wrap(side))
- table.insert(sides, side)
- count = count + 1
- if count >= amount then
- return peripherals, sides
- end
- elseif peripheralType == "modem" and not peripheral.call(side, "isWireless") then
- -- Look for remote peripherals
- modem = peripheral.wrap(side)
- for _, name in pairs(modem.getNamesRemote()) do
- if modem.getTypeRemote(name) == typ then
- -- Found one
- table.insert(peripherals, wrapRemote(modem, name))
- table.insert(sides, side..":"..name)
- count = count + 1
- if count >= amount then
- return peripherals, sides
- end
- end
- end
- end
- end
- return peripherals, sides
- end
- function getPeripheral(typ)
- resultPeripheral, resultSide = getPeripherals(typ, 1)
- return resultPeripheral[1], resultSide[1]
- end
- -- Modified version of peripheral.wrap for remote peripherals
- function wrapRemote(modem, name)
- result = {}
- methods = modem.getMethodsRemote(name)
- for _, method in pairs(methods) do
- result[method] = function(...)
- return modem.callRemote(name, method, ...)
- end
- end
- return result
- end
- --- MiscPeripherals apis I DONT OWN THOSE CODES
- -- Custom function to draw a status bar on the screen
- function drawStatusBar(title,x,y,cval,maxval,color1,color2,size,offset)
- if size==nil then
- size = 10
- end
- term.setCursorPos(x,y)
- term.setBackgroundColor(colors.black)
- -- print(cval)
- -- sleep(5)
- local s = 0
- if offset then
- s = offset - string.len(title)
- if s < 0 then s = 0 end
- end
- term.write(title)
- for i=1,s do term.write(" ") end
- local fill = math.floor(cval*size/maxval)
- term.setBackgroundColor(color1)
- for i=1,fill do
- term.write(" ")
- end
- term.setBackgroundColor(color2)
- for i=1,(size-fill) do
- term.write(" ")
- end
- term.setBackgroundColor(colors.black)
- -- Salto de Linea ##########
- end
- function printScr(n,reactor,side)
- fuel = 0
- items = reactor.getAllStacks()
- nItems = 0
- for islot,i in pairs(items) do
- nItems = nItems+1
- term.setCursorPos(1,mony-5)
- if string.find(i.name,"Fuel Rod") then
- fuel = fuel+ (10000-i.dmg)
- if i.dmg >= 9700 then
- table.insert(fuelAlert,{item=i,reactor=n,slot=islot})
- end
- end
- end
- fuel = fuel/nItems
- term.clear()
- term.setCursorPos(1,1)
- term.write("Reactor #"..n.." on "..side.." (items: "..nItems..")")
- drawStatusBar("Heat",2,3,reactor.getHeat(),reactor.getMaxHeat(),colors.red,colors.green,30,12)
- drawStatusBar("Fuel (avg)",2,5,fuel,10000,colors.green,colors.red,30,12)
- -- Salto de Linea ##########
- for N,i in pairs(fuelAlert) do
- term.setCursorPos(1,mony-1)
- term.setTextColor(colors.red)
- term.write(i.item.name.." [slot("..i.slot..")] on Reactor #"..i.reactor.." is low.")
- term.setTextColor(colors.yellow)
- fuelAlert = {}
- end
- end
- ---------------------------------
- ---------------------------------
- ---------------------------------
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.yellow)
- term.write("Starting...")
- --sleep(1)
- os.startTimer(0.1)
- local fuel = 0
- local counter = 1
- local static = false
- local Reactors,Sides
- --drawSquare(indicator((a.dmg-10000)*(-1)),"R")
- while true do
- event,key,a = os.pullEvent()
- if event == "timer" then
- Reactors, Sides = getPeripherals("nuclear_reactor")
- printScr(counter,Reactors[counter],Sides[counter])
- if not static then
- counter = counter+1
- end
- if counter > #Reactors then
- counter = 1
- end
- os.startTimer(1)
- --[[for n,reactor in pairs(Reactors) do
- printScr(n,reactor,Sides[n])
- end--]]
- --elseif event == "terminate" then
- --term = term_back
- elseif event == "mouse_click" then
- if not static then
- static = true
- if counter == 1 then
- counter = #Reactors
- elseif counter==#Reactors then
- counter = counter-1
- end
- else
- static = false
- end
- end
- --[[elseif event == "peripheral" then
- mon = getPeripheral("monitor")
- term.setCursorPos(1,1)
- term.write("redirecting to monitor")
- if mon then
- term = mon
- end
- end]]
- end
Advertisement
Add Comment
Please, Sign In to add comment