Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Script by Savage_Me55iah of CraftAU.com.au and Nuqube.co--
- local scriptName, version, pastebinCode = "REACTOR_LIST", "v1.0", "0Vp4jNhG"
- --Other Savage_Me55iah scripts @ http://pastebin.com/u/Savage_Me55iah
- --INSTRUCTIONS ON USE--
- --Instruction video on http://youtube.com/savagemessiah5
- --Contact Savage_Me55iah @ CraftAU.com.au or Nuqube.co or http://www.computercraft.info/forums2/ with suggestions/fixes/bugs
- -- CHANGELOG --
- --V1.0
- -- SETUP --
- local tArgs = {...}
- local update_request = tostring(tArgs[1]) or nil
- do
- update = function(script_name, pastebincode)
- print("UPDATING") shell.run("pastebin get "..pastebincode.." update")
- if fs.exists("update") then
- fs.delete(script_name) fs.copy("update", script_name) fs.delete("update") print("UPDATE SUCCESS")
- else
- print("UPDATE FAILED")
- end
- sleep(2) os.reboot()
- end
- end
- if tostring(update_request) == "update" then update(shell.getRunningProgram(), pastebinCode) end
- -- label_check(script) --
- label_check = function(param_scriptName)
- local param_labelA, param_text, param_labelB = os.getComputerLabel() or false, "Computer label, blank for random label:", nil
- while tostring(param_labelA) == "false" or tostring(param_labelA) == "nil" do
- term.clear() term.setCursorPos(1,1) print(param_text)
- param_labelB = tostring(read())
- if param_labelB == "nil" then param_labelB = tostring(param_scriptName.."-"..math.random(1000, 9999)) end
- os.setComputerLabel(param_labelB) param_labelA = os.getComputerLabel() or false
- if tostring(param_labelA) == "false" or tostring(param_labelA) == "nil" then param_text = "Computer label too long, try again:" end
- end
- end
- label_check(scriptName)
- id = os.getComputerID()
- label = os.getComputerLabel() or false
- if label == false then
- print("Please Type label here: ")
- os.setComputerLabel(tostring(read()))
- end
- function boolean_check(params)
- local answer = nil
- if tostring(params) == "true" then
- answer = true
- else
- answer = false
- end
- return answer
- end
- local settings_file = "config"
- local settings_template = [[-- adjust these configuration options as necessary.
- -- IMPORTANT!, API won't load if there are spaces in the values
- COMPUTER_LABEL = "${label}"
- COMPUTER_ID = ${id}
- TEXTSCALE = ${textscale}
- UPDATE_TIME = ${update_time}
- ]]
- local function interpolate(s, params)
- return s:gsub('($%b{})', function(w) return params[w:sub(3, -2)] or w end)
- end
- do
- save_settings = function()
- local filehandler = fs.open(tostring(settings_file), "w")
- if tostring(CONFIG) == "nil" then
- settings = {
- label = os.getComputerLabel(),
- id = os.getComputerID(),
- textscale = 1,
- update_time = 5
- }
- else
- settings = {
- label = CONFIG.COMPUTER_LABEL or os.getComputerLabel(),
- id = os.getComputerID(),
- textscale = CONFIG.TEXTSCALE or 1,
- update_time = CONFIG.UPDATE_TIME or 5
- }
- end
- filehandler.write(interpolate(settings_template, settings))
- filehandler.close()
- end
- end
- if fs.exists(settings_file) == false then
- save_settings()
- return
- else
- os.unloadAPI(settings_file)
- if os.loadAPI(settings_file) == false then print("ERROR: Could not load the settings file!") end
- CONFIG = nil
- for k, v in pairs(_G) do
- if k == settings_file then CONFIG = v break end
- end
- if CONFIG == nil then log_add("CONFIG came up nil", true) end
- end
- do
- -- modems = peripheral_find_type("modem", "wireless") .. returns a table of all peripherals of the same type --
- peripheral_find_type = function(peripheral_type, modem_type)
- local peripheralList, returnTable, modem_type = peripheral.getNames() or false, {}, modem_type or false
- if type(peripheralList) == "table" then
- for a,b in pairs(peripheralList) do
- local testType = peripheral.getType(b)
- if testType == tostring(peripheral_type) then
- if tostring(modem_type) == false then
- table.insert(returnTable, b)
- else
- local Peripheral = peripheral.wrap(b)
- -- local wireless = boolean_check(Peripheral.isWireless())
- if modem_type == "wireless" and wireless then table.insert(returnTable, b)
- elseif modem_type ~= "wireless" and not wireless then table.insert(returnTable, b) end
- end end end
- if tostring(returnTable[1]) == "nil" then returnTable = false end
- return returnTable
- end end
- end
- do
- percentage = function(params_varibleA, params_varibleB)
- local result = math.floor((tonumber(params_varibleA) or 0) / (tonumber(params_varibleB) or 0) * 10000)/100
- return result
- end
- getDetails = function()
- local results = {["EUTotal"] = 0}
- if tostring(reactorList) ~= "nil" then
- for a,b in pairs(reactorList) do
- local temp_wrap = peripheral.wrap(b)
- results[string.sub(tostring(b), 17, string.len(tostring(b)))] = {
- ["isActive"] = temp_wrap.isActive() or false,
- ["Heat"] = percentage((temp_wrap.getHeat() or 0), (temp_wrap.getMaxHeat() or 0)),
- ["EUOutput"] = (temp_wrap.getEUOutput() / 2) * 10
- }
- end
- for a,b in pairs(results) do
- if a ~= "EUTotal" then
- results["EUTotal"] = results["EUTotal"] + results[a]["EUOutput"]
- end
- end
- return results
- end
- end
- decimal = function(number)
- if type(number) == "number" then
- local text, num = ".", number
- if num >= 1000 then text = "K" end
- if num >= 1000000 then text = "M" end
- if num >= 1000000000 then text = "B" end
- if num >= 1000000000000 then text = "T" end
- while num >= 1000 do
- num = num / 1000
- end
- num = math.floor(num * 100) / 100
- if text ~= "." then
- text = tostring(num..text) or 0
- else
- text = tostring(num) or 0
- end
- return text
- else
- return number
- end
- end
- -- event = eventFilter("timer", "monitor_touch", "mouse_click", "key", "etc") .. returns a table only when the event matches the arg --
- eventFilter = function(...)
- local param, whitelist, event, fileHandler = {...}, {}, {}, fs.open("eventLog", 'a')
- for a,b in pairs(param) do whitelist[b] = true end
- while tostring(whitelist[event[1]]) ~= "true" do
- event = {os.pullEvent()}
- fileHandler.write(textutils.serialize(event))
- end
- fileHandler.close()
- return event
- end
- -- screenColor(colors.green, colors.blue)
- screenColor = function(param_commandb, param_colorBackground, param_colorText)
- local colorBackground, colorText, commandc = param_colorBackground or colors.black, param_colorText or colors.white, param_commandb
- if temp_wrap.isColor() == false then
- if param_colorBackground ~= colors.black then colorBackground, colorText = colors.white, colors.black
- else colorBackground, colorText = colors.black, colors.white end
- end
- temp_wrap.setBackgroundColor(colorBackground) temp_wrap.setTextColor(colorText)
- end
- -- screenWrite(mon[1], "hello world":upper(), 5, 3, colors.red, colors.black)
- screenWrite = function(param_command, param_text, param_x, param_y, param_colorBackground, param_colorText)
- local commandb = param_command
- param_command.setCursorPos(param_x, param_y)
- screenColor(commandb, param_colorBackground, param_colorText)
- param_command.write(param_text)
- screenColor()
- end
- monitor = function(command)
- local x, y, backg = 2, 2, " "
- command.clear() command.setCursorPos(x, y)
- screenWrite(command, " # HEAT OUTPUT ", x, y, colors.cyan, colors.white)
- y = y + 1
- for num=2,17 do backg = backg.." " end
- for a,b in pairs(reactorDetails) do
- local colorBackground = colors.red
- if a ~= "EUTotal" then
- if reactorDetails[a]["isActive"] and reactorDetails[a]["EUOutput"] ~= 0 then colorBackground = colors.green end
- screenWrite(command, backg, 2, y, colorBackground, colors.white)
- screenWrite(command, a, 3, y, colorBackground, colors.white)
- screenWrite(command, tostring(reactorDetails[a]["Heat"]).."%", 5, y, colorBackground, colors.white)
- screenWrite(command, decimal(reactorDetails[a]["EUOutput"]), 12, y, colorBackground, colors.white)
- y = y + 1
- end
- end
- screenWrite(command, backg, 2, y, colors.cyan, colors.white)
- screenWrite(command, " TOTAL EU: "..decimal(reactorDetails["EUTotal"]), x, y, colors.cyan, colors.white)
- end
- display = function()
- temp_wrap = term
- monitor(term)
- if tostring(peripheralList) ~= "nil" then
- for a,b in pairs(peripheralList) do
- local methodList = peripheral.getMethods(b)
- for c,d in pairs(methodList) do
- if tostring(d) == "setCursorPos" then
- temp_wrap = peripheral.wrap(b)
- temp_wrap.setTextScale(CONFIG.TEXTSCALE)
- monitor(temp_wrap)
- end end end end end
- end
- Event, reactorList, temp_wrap = {[1] = "timer"}, nil, nil, nil
- while true do
- if tostring(Event[1]) == "timer" then os.startTimer(tonumber(CONFIG.UPDATE_TIME)) end
- if tostring(Event[1]) == "peripheral" or tostring(Event[1]) == "peripheral_detach" or tostring(reactorList) == "nil" then reactorList = {} reactorList = peripheral_find_type("nuclear_reactor") peripheralList = peripheral.getNames() end
- reactorDetails = getDetails()
- display()
- Event = eventFilter("timer", "monitor_touch", "key", "peripheral_detach", "peripheral")
- end
Advertisement
Add Comment
Please, Sign In to add comment