Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local header = "Dialer"
- local mon = peripheral.wrap("left")
- local controller = peripheral.wrap("right")
- local dialer = peripheral.wrap("ep_dialling_device_1")
- --[[Change nothing below unless you know what you are doing]]--
- --[[Unless you want to add more pages]]--
- local pages = 0
- local pageNum = 1
- local locNames = {}
- function APILoader(apiName, apiPastebin)
- os.unloadAPI(apiName)
- if fs.exists(apiName) then
- os.loadAPI(apiName)
- else
- shell.run("pastebin","get",apiPastebin,apiName)
- os.loadAPI(apiName)
- end
- end
- function heading()
- button.heading(header..":")
- end
- function setupNav()
- button.setTable("Prev", prevPage, "", "", false, 1, 6, 18, 20)
- button.setTable("Next", nextPage, "", "", false, 33, 39, 18, 20)
- button.setTable("Refresh", os.reboot, "", "", false, 15, 25, 18, 20)
- button.screen()
- end
- function setupPages()
- mon.clear()
- button.clearTable()
- heading()
- local totalRows = 0
- local rowCount = 0
- local currCount = 0
- local col = 2
- local row = 3
- local npp = 12 --names per page
- for i = 1, dialer.getStoredCount() do
- totalRows = totalRows + 1
- end
- for i = 0, dialer.getStoredCount()-1 do
- locNames[i+1] = dialer.getStoredName(i)
- end
- --[[To add more pages just take add 12 to your last number]]--
- if pageNum == 1 then
- j = 1
- end
- if pageNum == 2 then
- j = 13
- end
- if pageNum == 3 then
- j = 25
- end
- if pageNum == 4 then
- j = 37
- end
- if pageNum == 5 then
- j = 49
- end
- if pageNum == 6 then
- j = 61
- end
- if pageNum == 7 then
- j = 73
- end
- if pageNum == 8 then
- j = 85
- end
- if pageNum == 9 then
- j = 97
- end
- if pageNum == 10 then
- j = 109
- end
- for i = j, #locNames do
- button.setTable(locNames[i], travel, i-1, "", false, col, col+17, row, row)
- row = row + 2
- rowCount = rowCount + 1
- if rowCount == 6 then
- col = col + 19
- row = 3
- rowCount = 0
- end
- end
- pages = math.ceil(totalRows/npp)
- button.label(15, 16, "Page "..tostring(pageNum).." of "..tostring(pages))
- setupNav()
- button.screen()
- end
- function checkActive()
- if controller.isPortalActive() == true then
- mon.clear()
- button.clearTable()
- button.heading("Portal connection")
- button.label(6, 2, "Portal already connected,")
- button.label(6, 3, "would you like to close it?")
- button.setTable("Yes", confirm, "true", "", false, 6, 18, 4, 6)
- button.setTable("No", confirm, "false", ",, false, 20, 32, 4, 6)
- button.screen()
- else
- setupPages()
- end
- end
- function confirm(answer)
- if answer == "true" then
- dialer.terminate()
- setupPages()
- end
- if answer == "false" then
- mon.clear()
- button.clearTable()
- button.heading("Beginning restart...")
- sleep(3)
- mon.clear()
- os.reboot()
- end
- end
- function travel(location)
- dialer.dialStored(location)
- mon.clear()
- button.clearTable()
- button.heading("Travelling to "..tostring(locNames[location+1]))
- sleep(5)
- dialer.terminate()
- mon.clear()
- os.reboot()
- end
- function nextPage()
- if pageNum + 1 <= pages then
- pageNum = pageNum + 1
- end
- setupPages()
- button.flash("Next")
- end
- function prevPage()
- if pageNum - 1 >= 1 then
- pageNum = pageNum - 1
- end
- setupPages()
- button.flash("Prev")
- end
- function checkpress()
- event, side, x, y = os.pullEvent("monitor_touch")
- button.checkxy(x,y)
- end
- APILoader("button","S8x0K3ui")
- heading()
- checkActive()
- while true do
- checkpress()
- end
- mon.clear()
Advertisement
Add Comment
Please, Sign In to add comment