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 version, pastebinCode = "v1.0", "0YGWjwyc"
- --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
- -- SETUP --
- local tArgs = {...}
- local update = tostring(tArgs[1]) or nil
- 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}
- UPPER_THRESHOLD = ${upper_threshold}
- LOWER_THRESHOLD = ${lower_threshold}
- UPDATE_TIME = ${update_time}
- OUTPUT_SIDE = "${output_side}"
- INVERT_REDSTONE = "${invert_redstone}"
- ]]
- 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")
- settings = {
- label = COMPUTER_LABEL or os.getComputerLabel(),
- id = os.getComputerID(),
- upper_threshold = UPPER_THRESHOLD or 3.5,
- lower_threshold = LOWER_THRESHOLD or 3,
- update_time = UPDATE_TIME or 1,
- output_side = OUTPUT_SIDE or "bottom",
- invert_redstone = INVERT_REDSTONE or "false"
- }
- 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
- function find_peripheral(t, e)
- local e = e or nil
- local sides = {[1] = "front", [2] = "back", [3] = "left", [4] = "right", [5] = "top", [6] = "bottom"}
- local peripheral_found = false
- for num=1, 6 do
- local type = peripheral.getType(sides[num])
- if type == t then
- if e == "wireless" then
- if peripheral.call(sides[num], "isWireless") then
- return sides[num]
- end
- elseif e == "remote" then
- if not peripheral.call(sides[num], "isWireless") then
- return sides[num]
- end
- elseif e == nil then
- return sides[num]
- end
- end
- end
- if peripheral_found ~= true then
- error("No " .. t .. " attached to the computer", 0)
- end
- end
- pcm = peripheral.wrap(find_peripheral("pneumaticMachine"))
- local active = nil
- function run()
- if tonumber(pcm.getPressure()) > tonumber(CONFIG.UPPER_THRESHOLD) then active = false end
- if pcm.getPressure() < tonumber(CONFIG.LOWER_THRESHOLD) then active = true end
- if boolean_check(CONFIG.INVERT_REDSTONE) then active = not active end
- redstone.setOutput(tostring(CONFIG.OUTPUT_SIDE), boolean_check(active))
- end
- if update ~= "update" then
- while true do
- os.startTimer(tonumber(CONFIG.UPDATE_TIME))
- term.clear()
- term.setCursorPos(1,1)
- print("NAME: "..os.getComputerLabel())
- print("ID: "..os.getComputerID())
- print("ACTIVE: "..tostring(active))
- print("PRESSURE: "..pcm.getPressure())
- print("THRESHOLD UPPER: "..tostring(CONFIG.UPPER_THRESHOLD))
- print("THRESHOLD LOWER: "..tostring(CONFIG.LOWER_THRESHOLD))
- print("UPDATE TIMER: "..tostring(CONFIG.UPDATE_TIME))
- print("INVERT REDSTONE: "..tostring(CONFIG.INVERT_REDSTONE))
- os.pullEvent()
- run()
- end
- else
- print("UPDATING")
- shell.run("pastebin get "..pastebinCode.." update")
- if fs.exists("update") then
- fs.delete(shell.getRunningProgram())
- fs.copy("update", shell.getRunningProgram())
- fs.delete("update")
- print("UPDATE SUCCESS")
- else
- print("UPDATE FAILED")
- end
- sleep(2)
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment