Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findItemIndexInTable(table, item)
- for index, value in pairs(table) do
- if value == item then
- return index
- end
- end
- return nil
- end
- function drawBargraph(fillPercent, mon, fillColor)
- local orgTerm = term.current()
- local graphCoords = {}
- local width, height = mon.getSize()
- graphCoords["X1"] = width - (width/3)
- graphCoords["Y1"] = height - (height/100) * fillPercent
- graphCoords["X2"] = width - (width/20)
- graphCoords["Y2"] = height
- term.redirect(mon)
- mon.clear()
- term.clear()
- paintutils.drawFilledBox(graphCoords["X1"], graphCoords["Y1"], graphCoords["X2"], graphCoords["Y2"], fillColor)
- term.redirect(orgTerm)
- end
- function findAndWrap(devType)
- local devices = peripheral.getNames()
- for id, devName in pairs(devices) do
- if peripheral.getType(devName) == devType then
- return peripheral.wrap(devName)
- end
- end
- end
- function findAndWrapAll(devType, useStartsWith)
- useStartsWith = useStartsWith or false
- local deviceWrappers = {}
- local devices = peripheral.getNames()
- for id, devName in pairs(devices) do
- if (useStartsWith == true and devName:sub(1, #devType) == devType) or peripheral.getType(devName) == devType then
- deviceWrappers[(devName .. "_" .. devType)] = peripheral.wrap(devName)
- end
- end
- return deviceWrappers
- end
- function orderTable(t, f)
- local a = {}
- for n in pairs(t) do
- table.insert(a, n)
- end
- table.sort(a, f)
- local i = 0
- local iter = function ()
- i = i + 1
- if a[i] == nil then
- return nil
- else
- return a[i], t[a[i]]
- end
- end
- return iter
- end
- function printTable(tableData)
- for key, value in pairs(tableData) do
- print(key .. ":" .. value)
- end
- end
- function formatInt(num, separator)
- if tonumber(num) == nil then
- return -1
- else
- separator = string.sub((separator or ","), 1, 1)
- return tostring(math.floor(num)):reverse():gsub("(%d%d%d)", "%1"..separator):gsub(separator.."(%-?)$", "%1"):reverse()
- end
- end
- function round(num, places)
- local mult = 10^(places or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function rednetLookupWithRetry(protocol, host)
- local hostId = nil
- local MAX_ATTEMPTS = 20
- local attempts = 0
- while hostId == nil and attempts < MAX_ATTEMPTS do
- attempts = attempts + 1
- hostId = rednet.lookup(protocol, host)
- sleep(1)
- end
- return hostId
- end
- --Convert ME Display Bytes to smaller units
- function convertMEBytes(bytes)
- local byteLength = string.len(bytes)
- local postfix = "B"
- if byteLength > 3 and byteLength <= 6 then
- postfix = "KB"
- bytes = bytes / 1000
- elseif byteLength > 6 and byteLength <= 9 then
- postfix = "MB"
- bytes = bytes / 1000000
- elseif byteLength > 9 and byteLength <= 12 then
- postfix = "GB"
- bytes = bytes / 1000000000
- end
- return round(bytes, 1) .. postfix
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement