Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- UU Monitor by JJJan
- ____________________________________________________________________________
- * Monitor, Sensor Peripheral and Applied Energetics Sensor Card required
- * The Script automatically detects the monitor and sensor
- * You may switch the displayed time intervall by typing
- sec, min, hour, day in the console
- ____________________________________________________________________________
- Git: https://git.bitrain.co/computercraft/computer
- Bugs: https://git.bitrain.co/computercraft/computer/issues
- ]]--
- os.loadAPI("ocs/apis/sensor")
- sleep(2) -- Prevents crashing due to slow chunk loading
- local sensorcard = nil
- local monitor = nil
- local position = nil
- local item = "Iron%20Ingot"
- local wait = 5
- local multiplier = 1
- local scale = "SEC"
- local data = {}
- local body = nil
- local stored = 0
- local elapsed = 0
- local time = 0
- local tps = 0
- local function initialize()
- -- Autodetect Function by JJJan
- for i, side in pairs(redstone.getSides()) do
- if peripheral.isPresent(side) then
- type = peripheral.getType(side)
- if type == "monitor" then
- monitor = peripheral.wrap(side)
- monitor.setTextScale(0.5)
- end
- if type == "sensor" then
- if position then
- error()
- end
- sensorcard = sensor.wrap(side)
- targets = sensorcard.getTargets()
- for key, value in pairs(targets) do
- if value.RawName == "tile.appeng.mb.mewirelessaccesspoint" then
- position = key
- end
- end
- end
- end
- end
- end
- local function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- local function format(n)
- -- Format Function by JJJan
- if n >= 1000000 then
- return round(n/1000000, 2) .. " M"
- elseif n >= 1000 then
- return round(n/1000, 2) .. " K"
- else
- return round(n, 2)
- end
- end
- local function getInput()
- while true do
- input = read()
- if input then
- if input == "sec" then
- multiplier = 1
- scale = string.upper(input)
- elseif input == "min" then
- multiplier = 60
- scale = string.upper(input)
- elseif input == "hour" then
- multiplier = 3600
- scale = string.upper(input)
- elseif input == "day" then
- multiplier = 86400
- scale = string.upper(input)
- end
- end
- sleep(0.6)
- end
- end
- local function tick()
- while true do
- if not monitor then
- print("No Monitor found!")
- initialize()
- break
- end
- if not position then
- if not sensorcard then
- print("No Sensor found!")
- initialize()
- else
- print("No Target found!")
- end
- break
- end
- w, h = monitor.getSize()
- data = sensorcard.getTargetDetails(position)
- for key, value in ipairs(data["Items"]) do
- if(value.Name == item) then
- request = http.get("http://cc.nghty.co/seconds")
- body = request.readAll()
- request.close()
- count = value.Size - stored
- elapsed = body - time
- tps = (wait * 20)/elapsed
- stored = value.Size
- time = body
- monitor.clear()
- monitor.setTextColor(256)
- monitor.setCursorPos(w/6 - string.len("Iron/" .. scale)/2, h/2 - 1)
- monitor.write("Iron/" .. scale)
- monitor.setTextColor(1)
- monitor.setCursorPos(w/6 - string.len(tostring(format((count/elapsed) * multiplier)))/2, h/2 + 2)
- monitor.write(format((count/elapsed) * multiplier))
- monitor.setTextColor(256)
- monitor.setCursorPos(w/2 - string.len("TPS")/2, h/2 - 1)
- monitor.write("TPS")
- if tps > 18 then
- monitor.setTextColor(32)
- elseif tps <= 18 and tps >= 15 then
- monitor.setTextColor(2)
- else
- monitor.setTextColor(16384)
- end
- monitor.setCursorPos(w/2 - string.len(tostring(round(tps, 2)))/2, h/2 + 2)
- monitor.write(round(tps, 2))
- monitor.setTextColor(256)
- monitor.setCursorPos(5*w/6 - string.len("STORED")/2, h/2 - 1)
- monitor.write("STORED")
- monitor.setTextColor(1)
- monitor.setCursorPos(5*w/6 - string.len(tostring(format(stored)))/2, h/2 + 2)
- monitor.write(format(stored))
- end
- end
- sleep(wait)
- end
- end
- initialize()
- while true do
- parallel.waitForAny(tick, getInput)
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement