Advertisement
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 = "CCECC", "v1.0", "Jb6qjsL4"
- --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 = {...}
- 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 tArgs[1] == "update" then update(scriptName, pastebinCode) end
- dir = "top"
- colorsRange = {}
- function addColor(paramName, paramColor, paramDec, paramHex, paramBin, paramPaint, paramDis)
- colorsRange[paramName] = {["color"] = paramColor,["decimal"] = paramDec,["hexadecimal"] = paramHex,["binary"] = paramBin,["paint"] = paramPaint,["display"] = paramDis}
- end
- addColor("white", colors.white, 1, "0x1", 0000000000000001, 0, "#F0F0F0")
- addColor("orange", colors.orange, 2, "0x2", 0000000000000010, 0, "#F2B233")
- addColor("magenta", colors.magenta, 4, "0x4", 0000000000000100, 0, "#E57FD8")
- addColor("lightBlue", colors.lightBlue, 8, "0x8", 0000000000001000, 0, "#99B2F2")
- addColor("yellow", colors.yellow, 16, "0x10", 0000000000010000, 0, "#DEDE6C")
- addColor("lime", colors.lime, 32, "0x20", 0000000000100000, 0, "#7FCC19")
- addColor("pink", colors.pink, 64, "0x40", 0000000001000000, 0, "#F2B2CC")
- addColor("gray", colors.gray, 128, "0x80", 0000000010000000, 0, "#4C4C4C")
- addColor("lightGray", colors.lightGray, 256, "0x100", 0000000100000000, 0, "#999999")
- addColor("cyan", colors.cyan, 512, "0x200", 0000001000000000, 0, "#4C99B2")
- addColor("purple", colors.purple, 1024, "0x400", 0000010000000000, 0, "#B266E5")
- addColor("blue", colors.blue, 2048, "0x800", 0000100000000000, 0, "#3366CC")
- addColor("brown", colors.brown, 4096, "0x1000", 0001000000000000, 0, "#7F664C")
- addColor("green", colors.green, 8192, "0x2000", 0010000000000000, 0, "#57A64E")
- addColor("red", colors.red, 16384, "0x4000", 0100000000000000, 0, "#CC4C4C")
- addColor("black", colors.black, 32768, "0x8000", 1000000000000000, 0, "#191919")
- if fs.exists("dataStore") then
- local fh = fs.open("dataStore", 'r')
- data = textutils.unserialize(fh:readAll())
- fh.close()
- end
- data = data or {}
- function wrapper(param)
- local result = false
- result = peripheral.wrap(param) or false
- if result == false then print("missing chest @ "..param) end
- return result
- end
- eChest = wrapper(dir)
- -- BACKSLASH WAS MESSING WITH MY SCRIPT EDITOR
- function BS() local result = "\\" return result end
- -- booleanCheck(functionNum, variable) -- [1] returns true if function ran correctly OR if false variable was nil [2] returns variable OR false if nil
- -- used for bypassing nil errors
- function booleanCheck(param_functionNum, param_value)
- local result, functionNum = {false, nil}, param_functionNum.."/001"
- if tostring(param_value) ~= "nil" then result = {true, param_value} else result = {false, false} end
- return result
- end
- -- quickChoice(functionNum, boolean, value, value) -- [1] returns function ran correctly [2] returns result
- -- removes alot of standard "if" blocks
- function quickChoice(param_functionNum, param_boolean, param_true, param_false)
- local result, functionNum = {false, false}, param_functionNum.."/002"
- if type(booleanCheck(functionNum, param_boolean)[2]) == "boolean" then
- if booleanCheck(functionNum, param_boolean)[2] == true then result = {true, param_true or false} else result = {true, param_false or true} end
- -- else
- -- logger.logger(functionNum, "Function Error, Expected: quickChoice(functionNum, boolean, value, value)", 2)
- end
- return result
- end
- -- massBooleanCheck(functionNum, "and", {boolean, boolean, etc}) -- [1] returns function ran correctly [2] returns result
- -- removes alot of "and/or"
- function massBooleanCheck(param_functionNum, param_function, param_booleans)
- local result, functionNum ={false, false}, param_functionNum.."/003"
- if (tostring(param_function) == "and" or tostring(param_function) == "or") and type(param_booleans) == "table" then
- if param_function == "and" then
- result = {false, true}
- for a,b in pairs(param_booleans) do result = {true, quickChoice(functionNum, b, result[2], false)[2]} end
- else
- for a,b in pairs(param_booleans) do result = {true, quickChoice(functionNum, b, true, result[2])[2]} end
- end
- -- else
- -- logger.logger(functionNum, "Function Error, Expected: massBooleanCheck(functionNum, (and/or), {boolean, boolean, etc})", 2)
- end
- return result
- end
- -- multiCompare(functionNum, "and", variable, {variable, variable, etc}) -- [1] returns function ran correctly [2] returns result
- -- compares multiple variables to 1 variable
- function multiCompare(param_functionNum, param_function, param_arg, param_variables)
- local result, functionNum = {false, false}, param_functionNum.."/004"
- if massBooleanCheck(functionNum, "and", {massBooleanCheck(functionNum, "or", {tostring(param_function) == "and", tostring(param_function) == "or"})[2], booleanCheck(functionNum, param_arg)[1], type(param_variables) == "table"})[2] then
- if param_function == "and" then
- result = {false, true}
- for a,b in pairs(param_variables) do result = {true, quickChoice(functionNum, (param_arg == booleanCheck(functionNum, b)[2]), result[2], false)[2]} end
- else
- for a,b in pairs(param_variables) do result = {true, quickChoice(functionNum, (param_arg == booleanCheck(functionNum, b)[2]), true, result[2])[2]} end
- end
- -- else
- -- logger.logger(functionNum, "Function Error, Expected: multiCompare(functionNum, (and/or), variable, {variable, variable, etc})", 2)
- end
- return result
- end
- -- tolerance(param_functionNum, "relative", 10, 5, 6, -1) -- [1] returns function ran correctly [2] returns result
- -- returns boolean if value is within tolerance
- function tolerance(param_functionNum, param_function, param_target, param_value, param_tolerancePositive, param_toleranceNegative)
- local result, functionNum = {false, false}, param_functionNum.."/005"
- local tolerancePositive, toleranceNegative = param_tolerancePositive or 0, param_toleranceNegative or 0
- if multiCompare(functionNum, "and", "number", {type(booleanCheck(functionNum, param_target)[2]), type(booleanCheck(functionNum, param_value)[2])})[2] and type(booleanCheck(functionNum, param_function)[2]) == "string" then
- if param_function == "relative" then
- tolerancePositive, toleranceNegative = param_target + tolerancePositive, param_target + toleranceNegative
- end
- result = {true, quickChoice(functionNum, massBooleanCheck(functionNum, "and", {(param_value <= tolerancePositive), (param_value >= toleranceNegative)})[2], true, false)[2]}
- -- else
- -- logger.logger(functionNum, "Function Error, Expected: tolerance(functionNum, relative, number, number, number, number)", 2)
- end
- return result
- end
- function changeAColor(...)
- local param = ...
- -- term.clearLine()
- -- screenWrite("changeAColor: "..param[1]..":"..param[2], colors.white, colors.black, 1,1)
- local currColors = {eChest.getColorNames()}
- currColors[param[1]] = param[2]
- eChest.setColorNames(currColors[1], currColors[2], currColors[3])
- end
- scroll = 1
- function presavedScroll(param)
- -- term.clearLine()
- -- screenWrite("scrolling: "..param, colors.white, colors.black, 1,1)
- local tempScroll = scroll
- if booleanCheck("001", data[tempScroll])[1] then
- if param == "<" then tempScroll = tempScroll - 1 else tempScroll = tempScroll + 1 end
- if (tempScroll) > table.maxn(data) then tempScroll = 1 elseif (tempScroll) < 1 then tempScroll = table.maxn(data) end
- if booleanCheck("001", data[tempScroll])[1] then
- eChest.setColorNames(data[tempScroll]["colors"][1], data[tempScroll]["colors"][2], data[tempScroll]["colors"][3])
- scroll = tempScroll
- end
- end
- end
- function changeFrequency(param)
- local currFrequency = nil
- if param == "<" then currFrequency = tonumber(math.floor(eChest.getFrequency())) - 1 else currFrequency = tonumber(math.floor(eChest.getFrequency())) + 1 end
- if currFrequency > 4095 then currFrequency = 0 elseif currFrequency < 0 then currFrequency = 4095 end
- eChest.setFrequency(currFrequency)
- -- term.clearLine()
- -- screenWrite("setting frequency to: "..currFrequency..param, colors.white, colors.black, 1,1)
- end
- function removeFrequency(param)
- if tostring(data[1]) ~= "nil" then
- for num=scroll,table.maxn(data) do
- data[num] = data[(num + 1)] or nil
- end
- local fh = fs.open("dataStore", 'w')
- fh.write(textutils.serialize(data))
- fh.close()
- scroll = 1
- term.setCursorPos(1,1) term.clearLine()
- print("Removed")
- end
- end
- function saveFrequency(param)
- local currColors, result, exists = {eChest.getColorNames()}, nil, false
- for a,b in pairs(data) do
- result = {}
- for num=1,3 do if data[a]["colors"][num] == currColors[num] then result[num] = true else result[num] = false end end
- exists = 0
- for a,b in pairs(result) do if b then exists = exists + 1 end end
- if exists == 3 then exists = true else exists = false end
- end
- if exists then
- term.setCursorPos(1,1) term.clearLine()
- print("Error already exists")
- else
- term.setCursorPos(1,2) term.clearLine()
- term.setCursorPos(1,1) term.clearLine()
- print("Type Name then hit Enter: ")
- local name = read()
- for a,b in pairs(data) do
- if tostring(data[a]["name"]) == name then exists = true end
- end
- if exists then
- term.setCursorPos(1,2) term.clearLine()
- term.setCursorPos(1,1) term.clearLine()
- print("Error already exists")
- else
- table.insert(data, {["name"] = name, ["colors"] = {eChest.getColorNames()}})
- local fh = fs.open("dataStore", 'w')
- fh.write(textutils.serialize(data))
- fh.close()
- term.setCursorPos(1,2) term.clearLine()
- term.setCursorPos(1,1) term.clearLine()
- print("Saved")
- end
- end
- end
- buttonList = {}
- function buttonListAdd(paramText, paramTColor, paramBColor, paramX, paramY, paramFunc, paramArg)
- table.insert(buttonList, {["text"] = paramText, ["textColor"] = paramTColor, ["BackGroundColor"] = paramBColor, ["x"] = paramX, ["y"] = paramY, ["func"] = paramFunc, ["arg"] = paramArg})
- end
- termX, termY = term.getSize()
- sections = {["mathY"] = math.floor((termY - 4) / 2) - 1}
- sections = {["mathY"] = sections["mathY"], [1] = math.floor((termX / 2) / 2) - 2, [2] = math.floor(termX / 2) - 2, [3] = math.floor(((termX / 2) / 2) * 3) - 2}
- for num=1,3 do
- x, y = sections[num], sections["mathY"]
- for a,b in pairs(colorsRange) do
- buttonListAdd(" ", colors.white, colorsRange[a]["color"], x, y, changeAColor, {num, a})
- if y == (sections["mathY"] + 3) then
- x, y = x + 1, sections["mathY"]
- else
- y = y + 1
- end
- end
- end
- buttonListAdd(" < ", colors.white, colors.red, sections[1], sections["mathY"] - 2, presavedScroll, "<")
- buttonListAdd(" > ", colors.white, colors.red, sections[3] + 1, sections["mathY"] - 2, presavedScroll, ">")
- buttonListAdd(" < ", colors.white, colors.red, sections[1], sections["mathY"] + 5, changeFrequency, "<")
- buttonListAdd(" > ", colors.white, colors.red, sections[3] + 1, sections["mathY"] + 5, changeFrequency, ">")
- buttonListAdd(" Save Frequency ", colors.white, colors.green, (termX / 2 - 8), sections["mathY"] - 4, saveFrequency, 1)
- buttonListAdd(" Remove Frequency ", colors.white, colors.green, (termX / 2 - 9), sections["mathY"] + 7, removeFrequency, 1)
- function scanButtons(param)
- local result = false
- -- print(param[3].." "..param[4])
- for a,b in pairs(buttonList) do
- if param[3] >= buttonList[a]["x"] and param[3] <= (buttonList[a]["x"] + (string.len(buttonList[a]["text"]) - 1)) and buttonList[a]["y"] == param[4] then
- buttonList[a]["func"](buttonList[a]["arg"])
- -- print(true)
- result = true
- end
- end
- return result
- end
- function screenWrite(paramText, paramTColor, paramBColor, paramX, paramY)
- term.setCursorPos(paramX, paramY)
- term.setTextColor(paramTColor)
- term.setBackgroundColor(paramBColor)
- term.write(paramText)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 1)
- end
- function drawScreen()
- clear, clearSpaces = sections[3] - 1 - sections[1] + 3, " "
- for num=2,clear do clearSpaces = clearSpaces.." " end
- screenWrite(clearSpaces, colors.white, colors.black, (sections[1] + 3), sections["mathY"] + 5)
- screenWrite(clearSpaces, colors.white, colors.black, (sections[1] + 3), sections["mathY"] - 2)
- for a,b in pairs(buttonList) do
- screenWrite(buttonList[a]["text"], buttonList[a]["textColor"], buttonList[a]["BackGroundColor"], buttonList[a]["x"], buttonList[a]["y"])
- end
- text = " "..eChest.getFrequency().." "
- screenWrite(text, colors.white, colors.blue, math.floor(termX / 2 - math.floor(string.len(text) / 2)), sections["mathY"] + 5)
- if booleanCheck("001", data[scroll])[1] then
- text = " "..data[scroll]["name"].." "
- screenWrite(text, colors.white, colors.blue, math.floor(termX / 2 - math.floor(string.len(text) / 2)), sections["mathY"] - 2)
- end
- text = " Current Setting "
- screenWrite(text, colors.white, colors.blue, math.floor(termX / 2 - math.floor(string.len(text) / 2)), sections["mathY"] + 9)
- local currColors = {eChest.getColors()}
- text = " "
- for num=(sections["mathY"] + 11),(termY - 1) do
- screenWrite(text, colors.white, currColors[1], (math.floor(termX / 2) - 10), num)
- screenWrite(text, colors.white, currColors[2], (math.floor(termX / 2) - 3), num)
- screenWrite(text, colors.white, currColors[3], (math.floor(termX / 2) + 4), num)
- end
- screenWrite("Savage's Ender Hacks: https://pastebin.com/Jb6qjsL4", colors.white, colors.cyan, 1, termY)
- end
- local updateScreen, event = true, {}
- term.clear()
- while true do
- if tostring(event[1]) == "mouse_click" then updateScreen = scanButtons(event) end
- if updateScreen then drawScreen() updateScreen = false end
- event = {}
- event = {os.pullEvent()}
- -- term.clearLine()
- -- screenWrite(tostring(event[1])..":"..tostring(event[3])..":"..tostring(event[4]).." ", colors.white, colors.black, 1,1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement