Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- A program to control multiple mining turtles.
- -- For UnbrokenMotion and Friends.
- -- Version 0.1.
- -- This code is probably a [redacted for discord] mess
- local termWidth, termHeight = term.getSize()
- local termHalfWidth = math.floor(termWidth / 2)
- local termHalfHeight = math.floor(termHeight / 2)
- -- Character table.
- -- If you have a better way of doing this, lemme know.
- local keyboard = {
- [30] = 'a',
- [48] = 'b',
- [46] = 'c',
- [32] = 'd',
- [18] = 'e',
- [33] = 'f',
- [34] = 'g',
- [35] = 'h',
- [23] = 'i',
- [36] = 'j',
- [37] = 'k',
- [38] = 'l',
- [50] = 'm',
- [49] = 'n',
- [24] = 'o',
- [25] = 'p',
- [16] = 'q',
- [19] = 'r',
- [31] = 's',
- [20] = 't',
- [22] = 'u',
- [47] = 'v',
- [17] = 'w',
- [45] = 'x',
- [21] = 'y',
- [44] = 'z',
- [2] = '1',
- [3] = '2',
- [4] = '3',
- [5] = '4',
- [6] = '5',
- [7] = '6',
- [8] = '7',
- [9] = '8',
- [10] = '9',
- [11] = '0',
- [57] = ' '
- }
- -- dependencies table, used to download additional scripts from pastebin or redwyn.moe during installation.
- local deps = {
- serverMain = "abcdefgh",
- turtleMain = "ijklmnop"
- }
- -- Self explanatory, this function prints text centered on the screen.
- -- Or at least, it tries to.
- function centeredText(y, text)
- local textLength = string.len(text)
- local cursorXPos = termHalfWidth - math.floor(textLength / 2)
- term.setCursorPos(cursorXPos, y)
- term.write(text)
- end
- -- A standard dialog screen.
- function dialog(text, bgColor, fgColor, btColor)
- -- Set background color.
- paintutils.drawFilledBox(1, 2, termWidth, termHeight, bgColor)
- term.setBackgroundColor(bgColor)
- term.setTextColor(fgColor)
- centeredText(termHalfHeight, text)
- --draw buttons.
- local buttonEnd = (termHalfWidth + 3)
- local buttonStart = (termHalfWidth - 2)
- local yPos = (termHalfHeight + 2)
- paintutils.drawLine(buttonStart, yPos, buttonEnd, yPos, btColor)
- term.setCursorPos(buttonStart+1, yPos)
- term.write("Okay")
- --wait for input.
- while true do
- -- sets multiple variables using os.pullEvent, if the mouse if clicked.
- local event, button, x, y = os.pullEvent("mouse_click")
- -- Basic logic to check which button has been pressed.
- if y == yPos then
- if x >= buttonStart and x <= buttonEnd then
- break
- end
- end
- end
- end
- -- A y/n dialog screen.
- function truthDialog(text, bgColor, fgColor, btColor)
- -- Set background color.
- paintutils.drawFilledBox(1, 2, termWidth, termHeight, bgColor)
- term.setBackgroundColor(bgColor)
- term.setTextColor(fgColor)
- centeredText(termHalfHeight, text)
- --draw buttons.
- local yesEnd = (termHalfWidth - 1)
- local yesStart = (yesEnd - 4)
- local noStart = (termHalfWidth + 1)
- local noEnd = (noStart + 3)
- local yPos = (termHalfHeight + 2)
- paintutils.drawLine(yesStart, yPos, yesEnd, yPos, btColor)
- paintutils.drawLine(noStart, yPos, noEnd, yPos, btColor)
- term.setCursorPos(yesStart+1, yPos)
- term.write("yes")
- term.setCursorPos(noStart+1, yPos)
- term.write("no")
- --wait for input.
- while true do
- -- sets multiple variables using os.pullEvent, if the mouse is clicked.
- local event, button, x, y = os.pullEvent("mouse_click")
- -- Basic logic to check which button has been pressed.
- if y == yPos then
- if x >= yesStart and x <= yesEnd then
- return true
- elseif x >= noStart and x <= noEnd then
- return false
- end
- end
- end
- end
- -- A textfield dialog screen.
- function textDialog(text, bgColor, fgColor, btColor)
- -- Set background color.
- paintutils.drawFilledBox(1, 2, termWidth, termHeight, bgColor)
- term.setBackgroundColor(bgColor)
- term.setTextColor(fgColor)
- centeredText(termHalfHeight, text)
- --draw buttons.
- local buttonEnd = (termHalfWidth + 3)
- local buttonStart = (termHalfWidth - 2)
- local yPos = (termHalfHeight + 5)
- paintutils.drawLine(1, yPos - 2, termWidth, yPos - 2, btColor)
- paintutils.drawLine(buttonStart, yPos, buttonEnd, yPos, btColor)
- term.setCursorPos(buttonStart+1, yPos)
- term.write("Okay")
- --wait for input.
- local content = ""
- while true do
- -- sets multiple variables using os.pullEvent, if key is pressed.
- local event, key, mouseX, mouseY = os.pullEvent()
- -- return stored value when enter key pressed
- if event == "key" then
- if key == keys.enter then
- return content
- -- Otherwise, concatenate to the value.
- elseif keyboard[key] ~= nil and string.len(content) < termWidth - 2 then
- content = content .. keyboard[key]
- -- display output.
- term.setCursorPos(2, yPos - 2)
- term.write(content)
- end
- end
- -- check if button clicked
- -- Basic logic to check which button has been pressed.
- if event == "mouse_click" then
- if mouseY == yPos then
- if mouseX >= buttonStart and mouseX <= buttonEnd then
- return content
- end
- end
- end
- end
- end
- -- Setup start.
- dialog("Welcome to mineX!", colors.blue, colors.white, colors.lightBlue)
- dialog("Please follow the prompts.", colors.blue, colors.white, colors.lightBlue)
- term.setCursorPos(1, termHeight)
- if turtle then
- term.write("Searching for host...")
- sleep(1)
- local modem = peripheral.wrap("right")
- modem.transmit(3, 1, "Turtle ping")
- else
- dialog("Press okay to begin server setup.", colors.blue, colors.white, colors.lightBlue)
- -- Begin configuration.
- -- Assign a server label.
- local newServerLabel = ""
- local serverLabelConfirm = false
- while serverLabelConfirm ~= true do
- newServerLabel = textDialog("Please enter this server's label.", colors.blue, colors.white, colors.lightBlue)
- serverLabelConfirm = truthDialog("Are you sure you'd like to use '" .. newServerLabel .. "'?", colors.blue, colors.white, colors.lightBlue)
- end
- os.setComputerLabel(newServerLabel)
- -- Set server port
- local serverPort = 0
- local serverPortConfirm = false
- while serverPortConfirm ~= true do
- serverPort = tonumber(textDialog("Please enter a server SEND port (1 - 65535)", colors.blue, colors.white, colors.lightBlue))
- -- Ensure the provided value is valid.
- if serverPort > 0 and serverPort <= 65535 then
- serverPortConfirm = truthDialog("Are you sure you want to use port " .. serverPort .. "?", colors.blue, colors.white, colors.lightBlue)
- else
- dialog("The port you have entered is invalid.", colors.blue, colors.white, colors.lightBlue)
- end
- end
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, termHeight)
- print("Minex setup complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement