Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.unloadAPI("touchpoint")
- os.loadAPI("touchpoint")
- rednet.open("left") -- change to side wireless modem is on
- local mon = "top" -- side advanced monitor is on
- local spawnTurtleID = -1 -- do not change set in first line of spawnList
- local m = peripheral.wrap(mon)
- local pageOne = touchpoint.new(mon)
- local pageTwo = touchpoint.new(mon)
- local page = 1
- -- dont change anything here. just list up to 16 mobs in spawnList
- local pageOneSpawns = {}
- local pageTwoSpawns = {}
- local space = 2
- local width, height = m.getSize()
- m.setTextScale(1)
- term.clear()
- term.setCursorPos(1,1)
- m.clear()
- m.setCursorPos(1,1)
- function tableLength(T)
- local count = 0
- if T == nil then
- return 0
- else
- for _ in pairs(T) do
- count = count + 1
- end
- return count
- end
- end
- function loadList()
- if fs.exists("spawnList") then
- local spawns = 0
- local file = fs.open("spawnList", "r")
- spawnTurtleID = tonumber(file.readLine())
- print("Turtle ID: "..spawnTurtleID)
- while true do
- local line = file.readLine()
- spawns = spawns + 1
- if line == nil then break end
- if spawns < 9 then
- if spawns == 8 then
- table.insert(pageOneSpawns, line)
- table.insert(pageOneSpawns, "Next page")
- else
- table.insert(pageOneSpawns, line)
- end
- else
- table.insert(pageTwoSpawns, line)
- end
- end
- if spawns > 9 then
- table.insert(pageTwoSpawns, line)
- table.insert(pageTwoSpawns, "Previous page")
- end
- file:close()
- else
- error("Spawn list not found.")
- end
- end
- function autoButton(bText, bX, bY, pg)
- xMax = bX + string.len(bText) + 1
- yMax = bY
- if pg == 1 then
- if string.lower(bText) == "next page" then
- pageOne:add(bText, func, bX, bY, xMax, yMax, colors.purple, colors.lime)
- else
- pageOne:add(bText, func, bX, bY, xMax, yMax, colors.gray, colors.lightBlue)
- end
- end
- if pg == 2 then
- if string.lower(bText) == "previous page" then
- pageTwo:add(bText, func, bX, bY, xMax, yMax, colors.purple, colors.lime)
- else
- pageTwo:add(bText, func, bX, bY, xMax, yMax, colors.gray, colors.lightBlue)
- end
- end
- end
- function sendCommand(cmd)
- print("Sending command - ".. cmd)
- notSent = true
- while notSent do
- rednet.send(spawnTurtleID, cmd)
- os.sleep(.1)
- message = nil
- senderID, message, distance = rednet.receive(3)
- if message == "gotIt" then
- notSent = false
- end
- print("Re-sending command...")
- end
- print("Command Received.")
- end
- function drawPage()
- if page == 1 then
- pageOne:draw()
- end
- if page == 2 then
- pageTwo:draw()
- end
- end
- loadList()
- for i = 1, tableLength(pageOneSpawns) do
- autoButton(pageOneSpawns[i], math.ceil((width - string.len(pageOneSpawns[i]))/ 2), i * space, 1)
- end
- if tableLength(pageTwoSpawns) > 0 then
- for n = 1, tableLength(pageTwoSpawns) do
- autoButton(pageTwoSpawns[n], math.ceil((width - string.len(pageTwoSpawns[n]))/ 2), n * space, 2)
- end
- end
- drawPage()
- print("Waiting for input.")
- while true do
- event = nil
- p1 = nil
- if page == 1 then
- event, p1 = pageOne:handleEvents(os.pullEvent())
- end
- if page == 2 then
- event, p1 = pageTwo:handleEvents(os.pullEvent())
- end
- if page == 1 then
- for k = 1, tableLength(pageOneSpawns) do
- if p1 == pageOneSpawns[k] then
- if k == 9 then
- pageOne:flash(pageOneSpawns[k])
- page = 2
- drawPage()
- else
- pageOne:toggleButton(pageOneSpawns[k])
- sendCommand(k)
- end
- end
- end
- end
- if page == 2 then
- for k = 1, tableLength(pageTwoSpawns) do
- if p1 == pageTwoSpawns[k] then
- if string.lower(p1) == "previous page" then
- pageTwo:flash(pageTwoSpawns[k])
- page = 1
- drawPage()
- else
- pageTwo:toggleButton(pageTwoSpawns[k])
- sendCommand(k + 8)
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment