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 = "TELEPOSER", "v1.0", "C2XQCaNr"
- --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
- --V1.1 -
- -- 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}
- TURTLEID = ${turtleid}
- TEXT_SCALE = ${text_scale}
- TELEPOSER_SIDE = "${teleposer_side}"
- OUTPUT_SIDE = "${output_side}"
- ]]
- 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(),
- turtleid = 1,
- text_scale = 1,
- teleposer_side = "down",
- output_side = "top"
- }
- else
- settings = {
- label = CONFIG.COMPUTER_LABEL or os.getComputerLabel(),
- id = os.getComputerID(),
- turtleid = CONFIG.TURTLEID or 1,
- text_scale = CONFIG.TEXT_SCALE or 1,
- teleposer_side = CONFIG.TELEPOSER_SIDE or "down",
- output_side = CONFIG.OUTPUT_SIDE or "top"
- }
- 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
- load_one = function(command)
- local answer = nil
- if fs.exists(tostring(command)) then
- local fileHandler = fs.open(command, 'r')
- answer = textutils.unserialize(fileHandler.readAll())
- fileHandler.close()
- end
- return answer
- end
- save_one = function(command1, command2)
- local fileHandler = fs.open(tostring(command1), 'w')
- fileHandler.write(textutils.serialize(command2))
- fileHandler.close()
- 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, peripheral.wrap(b))
- else
- local Peripheral = peripheral.wrap(b)
- -- local wireless = boolean_check(Peripheral.isWireless())
- if modem_type == "wireless" and wireless then table.insert(returnTable, peripheral.wrap(b))
- elseif modem_type ~= "wireless" and not wireless then table.insert(returnTable, peripheral.wrap(b)) end
- end end end
- if tostring(returnTable[1]) == "nil" then returnTable = false end
- return returnTable
- end end
- end
- local monitor = peripheral_find_type("monitor")
- local chests = peripheral_find_type("tile_extrautils_chestfull_name")
- local mon, chest = monitor[1], chests[1]
- local displayTable = {}
- local button_loc, current_page = {}, 1
- do
- item_list = function()
- chest.condenseItems()
- displayTable = {}
- for num=1,chest.getInventorySize() do
- local item = chest.getStackInSlot(num)
- if tostring(item) ~= "nil" then table.insert(displayTable, item["display_name"]) end
- end
- end
- button_length = function()
- local length = 1
- for k,v in ipairs(displayTable) do
- if tonumber(string.len(v) + 2) > length then length = string.len(v) + 2 end
- end
- return length
- end
- -- screenColor(colors.green, colors.blue)
- screenColor = function(param_commandb, param_colorBackground, param_colorText)
- local colorBackground, colorText = param_colorBackground or colors.black, param_colorText or colors.white
- if monitor[1].isColor() == false then
- if param_colorBackground ~= colors.black then colorBackground, colorText = colors.white, colors.black
- else colorBackground, colorText = colors.black, colors.white end
- end
- monitor[1].setTextColor(colorText)
- monitor[1].setBackgroundColor(colorBackground)
- 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)
- param_command.setCursorPos(param_x, param_y)
- screenColor(param_command, param_colorBackground, param_colorText)
- param_command.write(param_text)
- screenColor()
- end
- screen_drawbutton = function(command, text, num, x, y, num2)
- local params = {[1] = command, [2] = text or "FAIL", [3] = num, [4] = x, [5] = y}
- button_loc[num] = {}
- local text = " "..params[2].." "
- while string.len(tostring(text)) < tonumber(button_length()) and tostring(text) ~= " <<< SCROLL " and tostring(text) ~= " SCROLL >>> " do text = tostring(text).." " end
- button_loc[num]["x1"], button_loc[num]["y"] = x, y
- if num2 == num then color1 = colors.green else color1 = colors.red end
- screenWrite(params[1], text, params[4], params[5], color1, colors.white)
- button_loc[num]["x2"] = params[1].getCursorPos()
- end
- display = function(param)
- local start, x, y, selected = 1, 2, 4, param or "nil"
- button_loc = {}
- mon.setTextScale(tonumber(CONFIG.TEXT_SCALE))
- mon.clear()
- mon_x, mon_y = mon.getSize()
- mon_x, mon_y = mon_x - 2, mon_y - 4
- border_x1, border_y1, border_x2, border_y2 = 2, 4, mon_x + 1, mon_y + 2
- rows, mon_cols = math.floor(mon_y / 2), math.floor(mon_x / button_length())
- mon_total, page_length = rows * mon_cols, rows
- if current_page > 1 then start = (start + ((current_page - 1) * page_length)) end
- for a,b in pairs(displayTable) do
- y = 4
- for num2=1,rows do
- if x >= border_x1 and (x + button_length()) <= border_x2 and y <= border_y2 then
- if tostring(displayTable[start]) ~= "nil" then
- screen_drawbutton(mon, tostring(displayTable[start]), start, x, y, selected)
- end
- end
- start, y = start + 1, y + 2
- end
- x = x + button_length() + 1
- end
- screen_drawbutton(mon, "SCROLL >>>", "SCROLL >>>", (mon_x - 10), 2, selected)
- screen_drawbutton(mon, "<<< SCROLL", "<<< SCROLL", 2, 2, selected)
- end
- run = function(param_num)
- chest.pushItem(CONFIG.TELEPOSER_SIDE, param_num, 1, 1)
- redstone.setOutput(CONFIG.OUTPUT_SIDE, true)
- sleep(2)
- redstone.setOutput(CONFIG.OUTPUT_SIDE, false)
- chest.pullItem(CONFIG.TELEPOSER_SIDE, 1)
- end
- end
- while true do
- item_list()
- display()
- local Event = {os.pullEvent()}
- print(Event[1]..tostring(Event[2])..tostring(Event[3])..tostring(Event[4]))
- if Event[1] == "monitor_touch" then
- local button = nil
- for a,b in pairs(button_loc) do
- if Event[3] >= button_loc[a]["x1"] and Event[3] <= button_loc[a]["x2"] then
- if Event[4] == button_loc[a]["y"] or Event[4] == (button_loc[a]["y"] + 1) then
- button = a
- end end end
- if tostring(button) == "SCROLL >>>" then
- current_page = current_page + 1
- elseif tostring(button) == "<<< SCROLL" and current_page ~= 1 then
- current_page = current_page - 1
- end
- if tostring(button) ~= "nil" and tostring(button) ~= "<<< SCROLL" and tostring(button) ~= "SCROLL >>>" then display(button) run(button) end
- print(tostring(button))
- end
- print(Event[1])
- end
Advertisement
Add Comment
Please, Sign In to add comment