Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local teleports = {}
- local textScale = 0.9
- rednet.open("left")
- local function initTeleports()
- print("Start startOperations")
- teleports = {}
- local desTP = {}
- local computerID = os.getComputerID()
- rednet.send(126, "", "dns_list")
- local senderID, message, protocol = rednet.receive("dns_list_response", 5)
- if senderID then
- desTP = textutils.unserialize(message)
- local file = fs.open("dns_table.txt", 'w')
- if file then
- file.write(textutils.serialize(desTP))
- file.close()
- end
- else
- print("DNS server is not reachable.")
- local file = fs.open("dns_table.txt", 'r')
- if file then
- desTP = textutils.unserialize(file.readAll())
- file.close()
- end
- end
- local index = 1
- for id, name in pairs(desTP) do
- if not (computerID == id) then
- teleports[index] = {id = id, name = name}
- index = index + 1
- end
- end
- print("End startOperations")
- end
- local function initialDisplay()
- print("Start initialDisplay()")
- local monitor = peripheral.wrap("top")
- monitor.setTextScale(textScale)
- monitor.setBackgroundColour(colors.blue)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- local function dispNewLine()
- local x, y = monitor.getCursorPos()
- monitor.setCursorPos(1, y + 1)
- end
- local function displayLine()
- local width = monitor.getSize()
- for i = 1, width do
- monitor.write("-")
- end
- dispNewLine()
- end
- for k, v in ipairs(teleports) do
- displayLine()
- monitor.write(k .. " " .. v.name)
- dispNewLine()
- displayLine()
- end
- print("End initialDisplay()")
- end
- local function clickPocketDimension()
- print("Start clickPocketDimension()")
- redstone.setOutput("bottom", true)
- os.sleep(1)
- redstone.setOutput("bottom", false)
- os.sleep(1)
- print("End clickPocketDimension()")
- end
- local function dcPD()
- print("Start dcPD()")
- clickPocketDimension()
- clickPocketDimension()
- print("End dcPD()")
- end
- local function sendLog(destination)
- print("Start sendLog")
- rednet.send(126, destination, "log")
- local senderID, message, protocol = rednet.receive("dns_list_response", 5)
- if senderID then
- print(message)
- end
- print("End sendLog")
- end
- local function clickDisplay()
- while true do
- print("Start clickDisplay()")
- ::continue::
- local event, side, x, y = os.pullEvent("monitor_touch")
- local btnClicked = math.ceil(y / 3)
- if btnClicked > #teleports and btnClicked > 0 then
- initialDisplay()
- goto continue
- end
- dcPD()
- sendLog(teleports[btnClicked])
- rednet.send(teleports[btnClicked].id, "Sended", "message")
- initialDisplay()
- print("End clickDisplay()")
- end
- end
- local function runRednet()
- while true do
- print("Start runRednet()")
- initialDisplay()
- local senderID, message, protocol = rednet.receive()
- if protocol == "message" then
- sleep(5)
- dcPD()
- end
- print("End runRednet()")
- end
- end
- local function main()
- print("Start main()")
- sleep(2)
- initTeleports()
- initialDisplay()
- parallel.waitForAll(clickDisplay, runRednet)
- print("End main()")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment